Commit graph

695 commits

Author SHA1 Message Date
Brian Carroll
0d08c97e44 wasm: enable a test that has a Stmt::RuntimeError 2022-02-09 17:23:36 +00:00
Brian Carroll
abfa4b1522 test_gen: allow non-llvm tests to expect errors 2022-02-09 17:23:36 +00:00
Brian Carroll
cff762afe5 Fix test_gen llvm 2022-02-08 11:03:48 +00:00
Brian Carroll
c21b2bd0da Formatting and Clippy 2022-02-08 11:03:48 +00:00
Brian Carroll
85b418ebdf wasm: get rid of Result from gen_wasm, rename a function, improve comments 2022-02-08 11:03:48 +00:00
Brian Carroll
2fd2a85887 wasm: delete redundant enum TestType 2022-02-08 11:03:48 +00:00
Brian Carroll
c5ccc99e20 repl: rename Wasm32TestResult -> Wasm32Result 2022-02-08 11:03:48 +00:00
Brian Carroll
1783fa8009 repl: rename FromWasm32Memory -> FromWasmerMemory 2022-02-08 11:03:48 +00:00
Brian Carroll
e9871947d3 repl: move wasm32_test_result to gen_wasm, and extract Wasm32Sized from FromWasm32Memory 2022-02-08 11:03:48 +00:00
Brian Carroll
aaa5fa04cd wasm: delete obsolete code 2022-02-08 11:03:48 +00:00
ayazhafiz
40196185a0 Specialize zero-argument thunks with the correct variable
Previously we would pass the annotation down as the
type-to-be-monomorphized for, but that would just mean the annotation
would unify with itself. We instead want to use the variable the thunk
is being used as to be the one unified with the thunk's annotation.

Closes #2445
Closes #2446
2022-02-06 20:58:13 -05:00
ayazhafiz
ff3596505e Fix gen tests 2022-02-06 15:04:12 -05:00
Richard Feldman
9b05d8dd50
Move expect zig code out of utils 2022-02-02 19:15:47 -05:00
Richard Feldman
f8eec65229
Drop an obsolete todo 2022-02-01 20:43:43 -05:00
Richard Feldman
65244d6383
Fix unclosed brace 2022-02-01 08:43:47 -05:00
Richard Feldman
a55ff62e6c
Merge remote-tracking branch 'origin/trunk' into expect-dont-panic 2022-01-30 20:22:26 -05:00
Chelsea Troy
4f8d0776b3 We got a test working for panicking with the appropriate number fo failures. Ultimatly we want:
+ An error maessage that says what the failures were
+ Not panicking (so these are effectively error productions)
2022-01-30 18:55:09 -06:00
ayazhafiz
47a59c560c Make test use an i64 2022-01-29 15:04:22 -05:00
ayazhafiz
5943873654 Inline polymorphic calls at usage sites
This is a bit.. ugly, or at least seems suboptimal, but I can't think of
a better way to do it currently aside from demanding a uniform
representation, which we probably don't want to do.

Another option is something like the defunctionalization we perform
today, except also capturing potential uses of nested functions in the
closure tag of an encompassing lambda. So for example,

```
f = \x -> \y -> 1
```

would now record a lambdaset with the data `[Test.f
[TypeOfInnerClos1]]`, where `TypeOfInnerClos1` is e.g.
`[Test.f.innerClos1 I8, Test.f.innerClos1 I16]`, symbolizing that the
inner closure may be specialized to take an I8 or I16. Then at the time
that we create the capture set for `f`, we create a tag noting what
specialization should be used for the inner closure, and apply the
current defunctionalization algorithm. So effectively, the type of the
inner closure becomes a capture.

I'm not sure if this is any better, or if it has more problems.
@folkertdev any thoughts?

Closes #2322
2022-01-28 23:49:19 -05:00
Folkert
b9c318e9fb update the tests 2022-01-26 15:59:21 +01:00
Folkert
74932a4cab phase 2 2022-01-26 14:30:37 +01:00
Folkert
9ee7198e45 and another 2022-01-25 15:23:53 +01:00
Folkert
3137e14a85 another test fix 2022-01-25 13:37:30 +01:00
Folkert
b72ad31a89 fix more tests 2022-01-25 12:05:13 +01:00
ayazhafiz
3692b38447 Disable wasm tests for now 2022-01-23 12:33:22 -05:00
ayazhafiz
b2f2fcd6a8 Collect tags from extension variables during monomorphization
Fixes #2365
2022-01-23 12:33:22 -05:00
Jan Van Bruggen
9a8a4c6ed7 Add Num.(min/max)(I/U)(8/16) builtins 2022-01-22 00:19:17 -07:00
Eric Newbury
7919cd9fee add test 2022-01-21 17:08:43 -05:00
Eric Newbury
05c01a81f5 adding List.sortAsc builtin 2022-01-21 15:34:24 -05:00
Folkert de Vries
c0ea664141
Merge pull request #2375 from rtfeldman/expression-monomorphization-inlined
Monomorphize polymorphic non-function values
2022-01-21 20:10:42 +01:00
ayazhafiz
25db1189af Monomorphize expressions in refcount test 2022-01-20 10:23:13 -05:00
ayazhafiz
8fd139ba67 Handle unspecialized symbols captured in closures 2022-01-20 00:34:11 -05:00
Richard Feldman
6d8277ad8d
Merge pull request #2367 from rtfeldman/remove_Num.minmaxInt
Remove `Num.(min/max)Int`
2022-01-20 00:19:44 -05:00
ayazhafiz
649695f6e3 Fix wasm refcount tests 2022-01-19 23:21:29 -05:00
ayazhafiz
a5de224626 Specialize polymorphic non-function expressions
This commit fixes a long-standing bug wherein bindings to polymorphic,
non-function expressions would be lowered at binding site, rather than
being specialized at the call site.

Concretely, consider the program

```
main =
    n = 1

    idU8 : U8 -> U8
    idU8 = \m -> m

    idU8 n
```

Prior to this commit, we would lower `n = 1` as part of the IR, and the
`n` at the call site `idU8 n` would reference the lowered definition.
However, at the definition site, `1` has the polymorphic type `Num *` -
it is not until the the call site that we are able to refine the type
bound by `n`, but at that point it's too late. Since the default layout
for `Num *` is a signed 64-bit int, we would generate IR like

```
procedure main():
    let App.n : Builtin(Int(I64)) = 1i64;
    ...
    let App.5 : Builtin(Int(U8)) = CallByName Add.idU8 App.n;
    ret App.5;
```

But we know `idU8` expects a `u8`; giving it an `i64` is nonsense.
Indeed this would trigger LLVM miscompilations later on.

To remedy this, we now keep a sidecar table that maps symbols to the
polymorphic expression they reference, when they do so. We then
specialize references to symbols on the fly at usage sites, similar to
how we specialize function usages.

Looking at our example, the definition `n = 1` is now never lowered to
the IR directly. We only generate code for `1` at each place `n` is
referenced. As a larger example, you can imagine that

```
main =
    n = 1

    asU8 : U8 -> U8
    asU32 : U32 -> U8

    asU8 n + asU32 n
```

is lowered to the moral equivalent of

```
main =
    asU8 : U8 -> U8
    asU32 : U32 -> U8

    asU8 1 + asU32 1
```

Moreover, transient usages of polymorphic expressions are lowered
successfully with this approach. See for example the
`monomorphized_tag_with_polymorphic_arg_and_monomorphic_arg` test in
this commit, which checks that

```
main =
    mono : U8
    mono = 15
    poly = A
    wrap = Wrapped poly mono

    useWrap1 : [Wrapped [A] U8, Other] -> U8
    useWrap1 =
        \w -> when w is
            Wrapped A n -> n
            Other -> 0

    useWrap2 : [Wrapped [A, B] U8] -> U8
    useWrap2 =
        \w -> when w is
            Wrapped A n -> n
            Wrapped B _ -> 0

    useWrap1 wrap * useWrap2 wrap
```

has proper code generated for it, in the presence of the polymorphic
`wrap` which references the polymorphic `poly`.

https://github.com/rtfeldman/roc/pull/2347 had a different approach to
this - polymorphic expressions would be converted to (possibly capturing) thunks.
This has the benefit of reducing code size if there are many polymorphic
usages, but may make the generated code slower and makes integration
with the existing IR implementation harder. In practice I think the
average number of polymorphic usages of an expression will be very
small.

Closes https://github.com/rtfeldman/roc/issues/2336
Closes https://github.com/rtfeldman/roc/issues/2254
Closes https://github.com/rtfeldman/roc/issues/2344
2022-01-19 22:52:15 -05:00
Jan Van Bruggen
8e4b6f0cab Remove Num.(min/max)Int
Replace all uses with `Num.(min/max)I64`,
since all uses expect an `I64`.
2022-01-19 09:55:06 -07:00
Jan Van Bruggen
1e9d2d1239 Remove accidental trailing spaces 2022-01-18 22:25:46 -07:00
Jan Van Bruggen
591477e77b Add most remaining Num.min/max* builtins
This skips `min/maxU128`, as they require a subtle change
to the `I128`-centric implementation of `Int`s.
2022-01-17 15:26:23 -07:00
Chelsea Troy
085c02ffee Infrastructure to test and implement the replacement of an 'expect' failure with an error production
Last command run was 'cargo test expect_fail'
2022-01-16 22:01:22 -06:00
Richard Feldman
2ade76b373
Merge pull request #2354 from rtfeldman/add_builtin_Num.minI128
Add `Num.minI128` builtin
2022-01-16 22:38:27 -05:00
Jan Van Bruggen
d7e2be306f WIP: Add Num.minI128 builtin (TODOs remain) 2022-01-15 17:49:15 -07:00
Brian Carroll
f4650654ca Wasm: cosmetic changes to fake WASI functions 2022-01-15 15:35:42 +00:00
Brian Carroll
c7da7ca689 Wasm: Parse the Name section, export init_refcount_test, and don't DCE exports 2022-01-14 18:20:52 +00:00
Brian Carroll
3d00217b53 Wasm: rename build_module_help -> build_module_without_test_wrapper 2022-01-14 18:20:52 +00:00
Brian Carroll
ca2597973e Wasm: store function_count on the ImportSection 2022-01-14 18:20:52 +00:00
Brian Carroll
7f5b8c7296 Merge branch 'trunk' of github.com:rtfeldman/roc into wasm-pre-linking 2022-01-14 18:20:24 +00:00
Folkert de Vries
e1d990896a
Merge branch 'trunk' into mono-display 2022-01-14 13:55:52 +01:00
ayazhafiz
9f78eb2e01 Fix bug that caused extraneous assignment in IR generation
Previously we would expand optional record fields to assignments when
converting record patterns to "when" expressions. This resulted in
incorrect code being generated.
2022-01-13 18:34:25 -05:00
ayazhafiz
72ee2d6327 Mark pretty_print_ir_symbols public 2022-01-13 16:35:09 -05:00
hafiz
5f216122d6 Update dev.rs 2022-01-13 16:33:26 -05:00