Commit graph

406 commits

Author SHA1 Message Date
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
Folkert
fcb89cbcd8 Merge remote-tracking branch 'origin/trunk' into shrink-call-type 2021-11-13 19:31:30 +01:00
Folkert
f8b4ce0317 shrink tag id sizes in layouts 2021-11-13 19:31:20 +01:00
Folkert
e2f7606f25 shrink higher order with indirection 2021-11-13 15:42:47 +01:00
Folkert
144dbef434 Merge remote-tracking branch 'origin/trunk' into tag-union-imitate-rust 2021-11-10 17:19:30 +01:00
Michael Downey
7e074d300e cleaning up and adding comments 2021-11-09 14:37:31 -05:00
Michael Downey
1bc278d962 initial commit of Str.trimLeft 2021-11-09 14:25:24 -05:00
Folkert
5cd232816b waypoint 2021-11-05 21:30:20 +01:00
Richard Feldman
ff48abdd06 Refactor NonRecursive to use flat_map and match 2021-11-03 19:44:35 -04:00
Folkert
aa9bf6bdff fix alignment problem 2021-11-03 18:21:07 +01:00
Folkert
a40c4f4fd5 use Entry 2021-10-31 13:47:02 +01:00
Folkert
408aa899bf remove old code 2021-10-13 15:10:42 +02:00
Folkert
f43c10373f represent empty closure as unit (not void) 2021-09-24 15:41:00 +02:00
Brendan Hansknecht
0c6f8f308f Remove f16. It is not really supported by modern CPU hardware. 2021-09-21 16:51:47 -07:00
Folkert
77911cb68a store closure data for bool/byte again 2021-09-18 01:01:38 +02:00
Folkert
7416cc4e81 don't pass closure argument if not expected 2021-09-17 22:51:51 +02:00
Richard Feldman
f619932255
Merge pull request #1699 from rtfeldman/effect-after
Fix closures only monomorphizing once
2021-09-13 19:50:50 -04:00
Folkert
52d36cbe72 fix closure weirdness (skipping or infinite looping) 2021-09-13 22:50:48 +02:00
Folkert
350891468a add LambdaSet layout variant 2021-09-12 17:00:09 +02:00
Folkert
0b893eb972 remove alignment bump again 2021-09-12 14:01:41 +02:00
Folkert
9713645806 only round up to 2*usize on 32-bit platforms 2021-09-04 16:00:22 +02:00
Folkert
1d17a21d1f higher alignment requirement on rocstr/roclist 2021-09-04 15:18:37 +02:00
Folkert
97577c92cf layout add allocation_alignment_bytes 2021-09-04 00:03:10 +02:00
Folkert
c6163a73f6 use environment size of pointer 2021-08-27 12:25:21 +02:00
Folkert
a070a7fcc7 add ptr_bytes to layout env 2021-08-26 22:12:44 +02:00
Folkert
af1051ef89 add ptr_bytes to the layout cache 2021-08-26 22:06:47 +02:00
Folkert
ecba687243 Unify variables directly when possible
instead of going through a solved type
2021-08-22 16:30:06 +02:00