Commit graph

382 commits

Author SHA1 Message Date
Folkert
a3b00fbf55
Merge branch 'explicit-closed-tag-record' into delay-instantiating-aliases 2022-03-17 20:34:52 +01:00
Folkert
7d8409f6a6
write Aliases implementation 2022-03-15 22:02:04 +01:00
ayazhafiz
2d01c21b5c Codegen tags that are polymorphic because of rigids
Closes #2724
2022-03-14 15:25:25 -05:00
Folkert
a3d56bce3a
layout of Box a 2022-03-08 22:21:25 +01:00
Folkert
92f2927046
initial implementation 2022-03-08 19:09:42 +01:00
Folkert
a9c8e2dc3e
copy instead of clone Content 2022-03-06 19:07:18 +01:00
Brian Carroll
dcf3c052af
Merge pull request #2594 from rtfeldman/wasm-repl-fixes
Wasm REPL bug fixes
2022-02-27 18:40:47 +00:00
ayazhafiz
059c324268 Error reporting for type mismatches involving opaques 2022-02-27 00:10:12 -05:00
Brian Carroll
9544b3ba6c repl_wasm: update static assertions for struct sizes 2022-02-26 13:11:17 +00:00
ayazhafiz
395e0a33e0 Make sure unit structs are always units 2022-02-21 14:10:46 -05:00
ayazhafiz
e52d427ac8 Hash record field name order in generated layouts
Closes #2535

See the referenced issue for longer discussion - here's the synopsis.
Consider this program

```
app "test" provides [ nums ] to "./platform"

alpha = { a: 1, b: 2 }

nums : List U8
nums =
    [
        alpha.a,
        alpha.b,
    ]
```

Here's its IR:

```
procedure : `#UserApp.alpha` {I64, U8}
procedure = `#UserApp.alpha` ():
    let `#UserApp.5` : Builtin(Int(I64)) = 1i64;
    let `#UserApp.6` : Builtin(Int(U8)) = 2i64;
    let `#UserApp.4` : Struct([Builtin(Int(I64)), Builtin(Int(U8))]) = Struct {`#UserApp.5`, `#UserApp.6`};
    ret `#UserApp.4`;

procedure : `#UserApp.nums` List U8
procedure = `#UserApp.nums` ():
    let `#UserApp.7` : Struct([Builtin(Int(I64)), Builtin(Int(U8))]) = CallByName `#UserApp.alpha`;
    let `#UserApp.1` : Builtin(Int(U8)) = StructAtIndex 1 `#UserApp.7`;
    let `#UserApp.3` : Struct([Builtin(Int(I64)), Builtin(Int(U8))]) = CallByName `#UserApp.alpha`;
    let `#UserApp.2` : Builtin(Int(U8)) = StructAtIndex 1 `#UserApp.3`;
    let `#UserApp.0` : Builtin(List(Builtin(Int(U8)))) = Array [`#UserApp.1`, `#UserApp.2`];
    ret `#UserApp.0`;
```

What's happening is that we need to specialize `alpha` twice - once for the
type of a narrowed to a U8, another time for the type of b narrowed to a U8.

We do the specialization for alpha.b first - record fields are sorted by
layout, so we generate a record of type {i64, u8}. But then we go to
specialize alpha.a, but this has the same layout - {i64, u8} - so we reuse
the existing one! So (at least for records), we need to include record field
order associated with the sorted layout fields, so that we don't reuse
monomorphizations like this incorrectly!
2022-02-21 14:10:45 -05:00
Brian Carroll
8e370a32b6 repl: update some static_asserts for 32-bit compiler build 2022-02-09 16:34:11 +00:00
ayazhafiz
8dc92ccd97 Second pass 2022-02-06 15:04:12 -05:00
Brian Carroll
382ae948e1 Merge branch 'trunk' of github.com:rtfeldman/roc into repl_from_memory_trait 2022-01-28 12:49:33 +00:00
Brian Carroll
4a08fead1a repl: Change lots of pointers to addresses 2022-01-27 09:40:18 +00:00
Folkert
fbd26c598e provide target info to number alignment function 2022-01-26 17:19:53 +01:00
Folkert
0ed259a80d phase 3 2022-01-26 14:37:32 +01:00
Folkert
7e90812332 ptr_bytes -> target info, step 1 2022-01-26 14:28:26 +01:00
Folkert
97d14f421d Merge remote-tracking branch 'origin/trunk' into fix-lambda-set-debug-instance 2022-01-25 09:25:20 +01:00
ayazhafiz
e7b506646b Refinements from @folkertdev review 2022-01-23 19:00:32 -05:00
ayazhafiz
b2f2fcd6a8 Collect tags from extension variables during monomorphization
Fixes #2365
2022-01-23 12:33:22 -05:00
Folkert
fbf3ba77e9 fix debug impl 2022-01-23 15:44:42 +01:00
Folkert de Vries
82c7e8c37e
Merge pull request #2372 from rtfeldman/effect-forever
Add `Effect.forever`
2022-01-20 09:16:32 +01:00
Folkert
72e883a20b make symbol debug formatting consistent 2022-01-19 23:21:18 +01:00
Folkert
fbab19a937 custom debug instance for LambdaSet
so that symbols are printed as their numbers; makes mono tests reliable
2022-01-19 20:57:36 +01:00
Folkert
4c445f9f24 recognize functions that become tail-recursive after closure conversion 2022-01-19 20:09:20 +01:00
ayazhafiz
d966d8921f Support nullable wrapped tag union layouts in REPL 2021-12-29 17:55:21 -06:00
ayazhafiz
a03f7fa46c Update layout tests 2021-12-26 14:44:43 -06:00
ayazhafiz
c8ba554d8c Clippy warning 2021-12-26 11:58:50 -06:00
ayazhafiz
5e5eb6dca8 (llvm) Generate code for tag unions less than 64 bits in size correctly
Previously, we assumed that a union layout always lived on >= 1 64-bit
boundary when generating an LLVM type for it. For small tags unions,
like `[ Ok i8, Err ]` this need not be the case; indeed, a tag union
like that is actually only 2 bits - 1 bit for the "i8" data, and one bit
of the tag kind.

This led to a discrepancy between what the layout IR and generated LLVM
code would assume about the size of tag unions. In the case above, the
layout IR would assume the tag data is 2 bits wide, and the tag id is 1
bit into the data. But the LLVM code would generate a type that was 65
bits wide, the first 64 bits being for the "i8" data and the last 1 bit
being for the tag kind.

Usually, just running the LLVM-emitted code would not present a problem.
But it does present a problem when we use the layout IR to inspect the
result of LLVM-run code, in particular when we try to look up the tag
ID, as the repl does. This patch fixes that issue.

Note that this bug did not present itself in `test_gen` previously
because the data that most tests check against is stored in the front of
the representation.

Closes #2149
2021-12-26 11:45:02 -06:00
ayazhafiz
903fa7d363 Fix clippy warning: implement From over Into 2021-12-21 19:55:50 -06:00
ayazhafiz
e451c3a1f9 Small refactoring: coalesce record field collection loop 2021-12-21 19:23:07 -06:00
ayazhafiz
576f1293fd Turn invalid record field types into runtime errors
By emitting a runtime error rather than panicking when we can't layout
a record, we help programs like

```
main =
    get = \{a} -> a
    get {b: "hello world"}
```

execute as

```
Mismatch in compiler/unify/src/unify.rs Line 1071 Column 13
Trying to unify two flat types that are incompatible: EmptyRecord ~ { 'a' : Demanded(122), }<130>

🔨 Rebuilding host...
── TYPE MISMATCH ───────────────────────────────────────────────────────────────

The 1st argument to get is not what I expect:

8│      get {b: "hello world"}
            ^^^^^^^^^^^^^^^^^^

This argument is a record of type:

    { b : Str }

But get needs the 1st argument to be:

    { a : a }b

Tip: Seems like a record field typo. Maybe a should be b?

Tip: Can more type annotations be added? Type annotations always help
me give more specific messages, and I think they could help a lot in
this case

────────────────────────────────────────────────────────────────────────────────

'+fast-variable-shuffle' is not a recognized feature for this target (ignoring feature)
'+fast-variable-shuffle' is not a recognized feature for this target (ignoring feature)
Done!
Application crashed with message

    Can't create record with improper layout

Shutting down
```

rather than the hanging

```
Mismatch in compiler/unify/src/unify.rs Line 1071 Column 13
Trying to unify two flat types that are incompatible: EmptyRecord ~ { 'a' : Demanded(122), }<130>

thread '<unnamed>' panicked at 'invalid layout from var: UnresolvedTypeVar(104)', compiler/mono/s
rc/layout.rs:1510:52
```

that was previously produced.

Part of #2227
2021-12-21 19:11:59 -06:00
Brian Carroll
c290bbe7a7 Move layout calculations to layout module 2021-12-12 12:22:10 +00:00
Brian Carroll
211a5d9bf3 Fix apparent bug in Layout::is_refcounted
It contradicts build_tag in compiler/gen_llvm/src/llvm/build.rs,
where we create a NonNullableUnwrapped by calling
reserve_with_refcount_union_as_block_of_memory
2021-12-11 20:33:11 +00:00
Brian Carroll
031dce61c9 Add a stack_size_and_alignment method to Layout 2021-12-11 20:33:11 +00:00
Brian Carroll
2f4225eec6 Add more doc comments to UnionLayout enum 2021-12-08 20:30:26 +00:00
Folkert de Vries
8eb74da0f3
Merge pull request #2083 from rtfeldman/layout-soa
Layout Struct of Arrays
2021-11-28 12:43:37 +01:00
Folkert
79d5c82dfb cleanup 2021-11-27 16:36:43 +01:00
Folkert
a1fd34feef remove empty layout types (list,str,dict,set) 2021-11-27 14:05:16 +01:00
Folkert
48368f4fba fix imports 2021-11-26 22:33:10 +01:00
Folkert
891c879439 most of the conversion 2021-11-25 23:27:59 +01:00
hafiz
b3ecc16b16
Merge pull request #2050 from rtfeldman/empty-tags-and-unions
Canonicalize to empty tags and unions
2021-11-22 08:00:07 -06:00
Folkert
5415f458b1 make a layout for the empty tag union 2021-11-21 22:24:35 +01:00
Folkert
7fc79c3d40 fix typo 2021-11-21 19:20:05 +01:00
Folkert
dc44eaac97 cleanup 2021-11-21 14:11:18 +01:00
Folkert
2033f1f430 remove usize in mono 2021-11-21 13:22:45 +01:00
Folkert
aafb98ffac remove dead code 2021-11-21 00:55:23 +01:00
Folkert
123c963ff1 llvm build working 2021-11-21 00:23:59 +01:00
Folkert
c4ec9aa898 working mono 2021-11-20 23:25:30 +01:00