Commit graph

111 commits

Author SHA1 Message Date
Brian Carroll
e342b21d43 wasm: enable some List.map tests 2022-04-05 00:02:05 +01:00
Folkert
de77748dd5
add additonal tests 2022-03-30 19:08:23 +02:00
Folkert
98b2ed5d60
add test 2022-03-09 23:07:24 +01:00
Brendan Hansknecht
a5ce124bd3 Merge branch 'list-replace' into gen-dev/quicksort2 2022-02-27 20:42:45 -08:00
Brendan Hansknecht
457ba524aa fix tests and alias analysis 2022-02-27 15:20:54 -08:00
Brendan Hansknecht
d9e9c28889 add error test case 2022-02-27 00:45:51 -08:00
Brendan Hansknecht
7a608524ec Merge remote-tracking branch 'origin/trunk' into gen-dev/quicksort2 2022-02-27 00:26:04 -08:00
Brendan Hansknecht
7c6c9b52a9 Merge remote-tracking branch 'origin/trunk' into list-replace 2022-02-25 07:35:00 -08:00
Tom Dohrmann
954064fa1e make more types more explicit 2022-02-25 13:58:07 +01:00
Tom Dohrmann
868316abb8 make types more explicit 2022-02-25 13:02:11 +01:00
Brendan Hansknecht
116b585cdc add more tests 2022-02-24 22:59:47 -08:00
Brendan Hansknecht
889b189191 fix list passing 2022-02-24 22:46:50 -08:00
Brendan Hansknecht
dddf8ff785 switch from pair to record and change name to ListReplaceUnsafe 2022-02-24 20:41:26 -08:00
Brendan Hansknecht
ba2e8cd32b Add base piping for list.Replace 2022-02-24 17:58:56 -08:00
Tom Dohrmann
788c8a6af2 reimplement RocList and RocStr 2022-02-23 16:02:13 +01:00
Brendan Hansknecht
2154e910d8 expand test coverage 2022-02-19 19:39:44 -08:00
Jan Van Bruggen
f47dbb5171
Swap List.mapWithIndex arg1 args order to put the element first 2022-02-11 16:10:29 -07:00
Jan Van Bruggen
92e0f8714f
Swap List.repeat args order to put the list first 2022-02-11 16:10:29 -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
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
ayazhafiz
fefbb5312e Yet more quicksort bugs 2022-01-11 18:17:57 -05:00
ayazhafiz
fe114e5e09 Improve test names 2022-01-10 23:42:15 -05:00
ayazhafiz
fba1c64c4b Fix another quicksort bug 2022-01-10 23:41:08 -05:00
Folkert de Vries
db44d03e66
Merge pull request #2259 from rtfeldman/i/2227-record-layout-hang
Turn invalid record field types into runtime errors
2021-12-23 20:17:34 +01:00
ayazhafiz
ed64ff912a Implement List.dropIf
This was referenced in the `List` documentation and in the
[tutorial](./TUTORIAL.md), but wasn't actually implemented prior to this
commit!

Part of #2227
2021-12-22 12:34:48 -06:00
ayazhafiz
3c2822224a Update expected failure tests to use expect_runtime_error_panic 2021-12-22 09:23:50 -06:00
rvcas
14e66de0b7 tests(wasm): assert_concat_work needs a feature flag too 2021-12-17 12:52:55 -05:00
rvcas
a18c3e2c3a tests(wasm): fix tests 2021-12-17 12:44:11 -05:00
rvcas
edd3c8c4c1 tests(wasm): List.isEmpty already works now 2021-12-17 12:05:17 -05:00
rvcas
660c3dc111 tests(wasm): prep tests for CI 2021-12-17 11:47:58 -05:00
rvcas
40da207859 feat(wasm): LowLevel::ListLen 2021-12-16 21:50:12 -05:00
rvcas
6ada59d7a1 feat(wasm): the beginnings of a real array 2021-12-10 14:44:19 -05:00
rvcas
6305947b1a fix: exclude gen-dev from gen_list test compilation 2021-11-29 18:08:12 -05:00
rvcas
7657d5b192 test: enable wasm in gen_list 2021-11-29 15:06:45 -05:00
Folkert
79d5c82dfb cleanup 2021-11-27 16:36:43 +01:00
Michael Downey
d11bb93539
Merge branch 'trunk' into add_list_all 2021-11-18 16:09:24 -05:00
Michael Downey
9d587d37b4
Merge branch 'trunk' into add_list_all 2021-11-18 06:41:08 -05:00
satotake
ce8a88416d Merge branch 'trunk' into builtins-list-intersperse 2021-11-18 11:16:27 +00:00
Michael Downey
c5484a9ad3 fixing List.all on empty list to be true 2021-11-17 22:47:49 -05:00
satotake
16fb04b4fa Add builtin List.intersperse 2021-11-17 15:18:45 +00:00
Michael Downey
81f0f46132 fixing test 2021-11-16 18:25:16 -05:00
Michael Downey
d946b84e63 adding initial List.all 2021-11-16 16:34:36 -05:00
satotake
73dda714de Add builtin List.split 2021-11-15 13:50:11 +00:00
Folkert
5d7b4b7ad0 change roc call result; adding an extra field for the error message pointer
When the returned value was smaller than a pointer, there was no space for the error message pointer.
2021-11-10 22:14:54 +01:00
satotake
9f5d3f521b Implement List.sublist 2021-11-10 13:16:57 +00:00
Folkert
94efbd0e95 Merge remote-tracking branch 'origin/trunk' into builtins-list-take-last 2021-11-09 16:18:19 +01:00
satotake
dfc527ecff Merge branch 'trunk' into builtins-list-take-last 2021-11-09 12:34:58 +00:00