Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-4 authored Jun 26, 2023
2 parents 74ed31c + 74e28ef commit 347a66c
Show file tree
Hide file tree
Showing 81 changed files with 4,503 additions and 2,629 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Roc is not ready for a 0.1 release yet, but we do have:

- [**installation** guide](https://github.com/roc-lang/roc/tree/main/getting_started)
- [**tutorial**](https://roc-lang.org/tutorial)
- [**docs** for the standard library](https://www.roc-lang.org/builtins/Str)
- [**docs** for the standard library](https://www.roc-lang.org/builtins)
- [**examples**](https://github.com/roc-lang/examples/tree/main/examples)
- [frequently asked questions](https://github.com/roc-lang/roc/blob/main/FAQ.md)
- [Group chat](https://roc.zulipchat.com) for help, questions and discussions
Expand Down
38 changes: 15 additions & 23 deletions crates/cli_testing_examples/benchmarks/CFold.roc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ main =
|> Task.putLine

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
Task.putLine "Error: Failed to get Integer from stdin."

Expr : [
Add Expr Expr,
Expand Down Expand Up @@ -100,35 +100,27 @@ constFolding = \e ->
x1 = constFolding e1
x2 = constFolding e2

when Pair x1 x2 is
Pair (Val a) (Val b) ->
Val (a + b)
when x1 is
Val a ->
when x2 is
Val b -> Val (a + b)
Add (Val b) x | Add x (Val b) -> Add (Val (a + b)) x
_ -> Add x1 x2

Pair (Val a) (Add (Val b) x) ->
Add (Val (a + b)) x

Pair (Val a) (Add x (Val b)) ->
Add (Val (a + b)) x

Pair y1 y2 ->
Add y1 y2
_ -> Add x1 x2

Mul e1 e2 ->
x1 = constFolding e1
x2 = constFolding e2

when Pair x1 x2 is
Pair (Val a) (Val b) ->
Val (a * b)

Pair (Val a) (Mul (Val b) x) ->
Mul (Val (a * b)) x

Pair (Val a) (Mul x (Val b)) ->
Mul (Val (a * b)) x
when x1 is
Val a ->
when x2 is
Val b -> Val (a * b)
Mul (Val b) x | Mul x (Val b) -> Mul (Val (a * b)) x
_ -> Mul x1 x2

Pair y1 y2 ->
Add y1 y2
_ -> Mul x1 x2

_ ->
e
1 change: 0 additions & 1 deletion crates/cli_testing_examples/benchmarks/Deriv.roc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ main =

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."


nest : (I64, Expr -> IO Expr), I64, Expr -> IO Expr
nest = \f, n, e -> Task.loop { s: n, f, m: n, x: e } nestHelp
Expand Down
14 changes: 8 additions & 6 deletions crates/cli_testing_examples/benchmarks/NQueens.roc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ main =
when inputResult is
Ok n ->
queens n # original koka 13
|> Num.toStr
|> Task.putLine
|> Num.toStr
|> Task.putLine

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
Expand All @@ -21,7 +21,8 @@ ConsList a : [Nil, Cons a (ConsList a)]
queens = \n -> length (findSolutions n n)

findSolutions = \n, k ->
if k <= 0 then # should we use U64 as input type here instead?
if k <= 0 then
# should we use U64 as input type here instead?
Cons Nil Nil
else
extend n Nil (findSolutions n (k - 1))
Expand All @@ -40,14 +41,15 @@ appendSafe = \k, soln, solns ->
else
appendSafe (k - 1) soln solns


safe : I64, I64, ConsList I64 -> Bool
safe = \queen, diagonal, xs ->
when xs is
Nil -> Bool.true
Cons q t ->
queen != q && queen != q + diagonal && queen != q - diagonal && safe queen (diagonal + 1) t

if queen != q && queen != q + diagonal && queen != q - diagonal then
safe queen (diagonal + 1) t
else
Bool.false

length : ConsList a -> I64
length = \xs ->
Expand Down
1 change: 0 additions & 1 deletion crates/cli_testing_examples/benchmarks/QuicksortApp.roc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ main =

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."


sort : List I64 -> List I64
sort = \list ->
Expand Down
10 changes: 8 additions & 2 deletions crates/cli_testing_examples/benchmarks/RBTreeCk.roc
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ ins = \tree, kx, vx ->

Node Black a ky vy b ->
if lt kx ky then
(if isRed a then balance1 (Node Black Leaf ky vy b) (ins a kx vx) else Node Black (ins a kx vx) ky vy b)
if isRed a then
balance1 (Node Black Leaf ky vy b) (ins a kx vx)
else
Node Black (ins a kx vx) ky vy b
else if lt ky kx then
(if isRed b then balance2 (Node Black a ky vy Leaf) (ins b kx vx) else Node Black a ky vy (ins b kx vx))
if isRed b then
balance2 (Node Black a ky vy Leaf) (ins b kx vx)
else
Node Black a ky vy (ins b kx vx)
else
Node Black a kx vx b

Expand Down
1 change: 0 additions & 1 deletion crates/cli_testing_examples/benchmarks/RBTreeDel.roc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ main =

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."


boom : Str -> a
boom = \_ -> boom ""
Expand Down
35 changes: 34 additions & 1 deletion crates/compiler/alias_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,38 @@ fn expr_spec<'a>(
builder.add_get_tuple_field(block, variant_id, index)
}
},
UnionFieldPtrAtIndex {
index,
tag_id,
structure,
union_layout,
} => {
let index = (*index) as u32;
let tag_value_id = env.symbols[structure];

let type_name_bytes = recursive_tag_union_name_bytes(union_layout).as_bytes();
let type_name = TypeName(&type_name_bytes);

// unwrap the named wrapper
let union_id = builder.add_unwrap_named(block, MOD_APP, type_name, tag_value_id)?;

// now we have a tuple (cell, union { ... }); decompose
let heap_cell = builder.add_get_tuple_field(block, union_id, TAG_CELL_INDEX)?;
let union_data = builder.add_get_tuple_field(block, union_id, TAG_DATA_INDEX)?;

// we're reading from this value, so touch the heap cell
builder.add_touch(block, heap_cell)?;

// next, unwrap the union at the tag id that we've got
let variant_id = builder.add_unwrap_union(block, union_data, *tag_id as u32)?;

let value = builder.add_get_tuple_field(block, variant_id, index)?;

// construct the box. Here the heap_cell of the tag is re-used, I'm hoping that that
// conveys to morphic that we're borrowing into the existing tag?!
builder.add_make_tuple(block, &[heap_cell, value])
}

StructAtIndex {
index, structure, ..
} => {
Expand Down Expand Up @@ -1589,13 +1621,14 @@ fn layout_spec_help<'a>(
}
}

Boxed(inner_layout) => {
Ptr(inner_layout) | Boxed(inner_layout) => {
let inner_type =
layout_spec_help(env, builder, interner, interner.get_repr(inner_layout))?;
let cell_type = builder.add_heap_cell_type();

builder.add_tuple_type(&[cell_type, inner_type])
}

// TODO(recursive-layouts): update once we have recursive pointer loops
RecursivePointer(union_layout) => match interner.get_repr(union_layout) {
LayoutRepr::Union(union_layout) => {
Expand Down
4 changes: 3 additions & 1 deletion crates/compiler/can/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ macro_rules! map_symbol_to_lowlevel_and_arity {
// these are used internally and not tied to a symbol
LowLevel::Hash => unimplemented!(),
LowLevel::PtrCast => unimplemented!(),
LowLevel::PtrWrite => unimplemented!(),
LowLevel::PtrStore => unimplemented!(),
LowLevel::PtrLoad => unimplemented!(),
LowLevel::Alloca => unimplemented!(),
LowLevel::RefCountIncRcPtr => unimplemented!(),
LowLevel::RefCountDecRcPtr=> unimplemented!(),
LowLevel::RefCountIncDataPtr => unimplemented!(),
Expand Down
6 changes: 6 additions & 0 deletions crates/compiler/collections/src/vec_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ impl<T: PartialEq> VecSet<T> {
self.elements.is_empty()
}

pub fn singleton(value: T) -> Self {
Self {
elements: vec![value],
}
}

pub fn swap_remove(&mut self, index: usize) -> T {
self.elements.swap_remove(index)
}
Expand Down
4 changes: 4 additions & 0 deletions crates/compiler/debug_flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ flags! {
/// instructions.
ROC_PRINT_IR_AFTER_REFCOUNT

/// Writes a pretty-printed mono IR to stderr after the tail recursion (modulo cons)
/// has been applied.
ROC_PRINT_IR_AFTER_TRMC

/// Writes a pretty-printed mono IR to stderr after performing dropspecialization.
/// Which inlines drop functions to remove pairs of alloc/dealloc instructions of its children.
ROC_PRINT_IR_AFTER_DROP_SPECIALIZATION
Expand Down
Loading

0 comments on commit 347a66c

Please sign in to comment.