Commit graph

13739 commits

Author SHA1 Message Date
Anton-4
65a706939c debugging grammar 2022-01-22 18:58:28 +01:00
Jan Van Bruggen
14ef9be3d2 Sort Num.(min/max)* builtin symbol defs 2022-01-22 00:19:17 -07:00
Jan Van Bruggen
9a8a4c6ed7 Add Num.(min/max)(I/U)(8/16) builtins 2022-01-22 00:19:17 -07:00
Jan Van Bruggen
38f0a3717f Extract repeated min/max logic 2022-01-22 00:00:29 -07:00
Folkert de Vries
bec222b0c3
Merge pull request #2386 from rtfeldman/enewbury/list-sort-desc
add List.sortDesc builtin
2022-01-22 04:02:00 +01:00
Folkert
2c139100ca fix big error 2022-01-21 23:30:04 +01:00
Eric Newbury
7919cd9fee add test 2022-01-21 17:08:43 -05:00
Eric Newbury
a96d5e6abf Merge branch 'trunk' into enewbury/list-sort-desc 2022-01-21 17:06:52 -05:00
Eric Newbury
7e7104d9ba WIP 2022-01-21 16:46:47 -05:00
Folkert de Vries
e7aa65bff0
Merge pull request #2384 from rtfeldman/enewbury/list-sort-asc
Adds List.sortAsc builtin
2022-01-21 22:12:53 +01:00
Eric Newbury
05c01a81f5 adding List.sortAsc builtin 2022-01-21 15:34:24 -05:00
Folkert
1328e4515d use Task.loop in False 2022-01-21 20:57:03 +01:00
Anton-4
3047fc6845 grammar progress, made temp tokenizer 2022-01-21 20:32:28 +01: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
Folkert
06d506f63b use Task.loop in Deriv 2022-01-21 20:01:45 +01:00
Anton-4
495e6b58d4 rust-peg grammar progress 2022-01-21 09:46:45 +01:00
Brian Carroll
992105930b
Merge pull request #2363 from rtfeldman/wasm-refactor-lowlevels
Wasm: refactor low-level ops
2022-01-21 07:16:45 +00:00
Richard Feldman
83f12b6e53
Merge pull request #2361 from rtfeldman/cleanup_builtins_Num.minmaxI128
Remove leftover TODOs from #2354
2022-01-20 18:21:29 -05:00
Richard Feldman
eacbb956cf
Merge pull request #2360 from rtfeldman/builtins-using-builtins
using builtins from builtins
2022-01-20 18:20:50 -05:00
ayazhafiz
b281ea8c2c Make var_contains_content a loop 2022-01-20 18:09:04 -05:00
ayazhafiz
53be0e2674 Reduce visibility of partial exprs 2022-01-20 17:56:43 -05:00
ayazhafiz
25db1189af Monomorphize expressions in refcount test 2022-01-20 10:23:13 -05:00
Richard Feldman
ee4e4e976f
Merge pull request #2378 from rtfeldman/remove-deprecated-symbols
remove deprecated symbols and reorder remainder
2022-01-20 10:03:55 -05:00
Brian Hicks
f2ae02213a remove deprecated symbols and reorder remainder 2022-01-20 08:29:30 -06:00
Folkert de Vries
82c7e8c37e
Merge pull request #2372 from rtfeldman/effect-forever
Add `Effect.forever`
2022-01-20 09:16:32 +01:00
ayazhafiz
e7e2fa063f Specialize polymorphic values in record updates 2022-01-20 01:23:31 -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
Richard Feldman
74428e23eb
Merge pull request #2374 from rtfeldman/effect-loop
implement `Effect.loop`
2022-01-19 23:58:48 -05:00
ayazhafiz
649695f6e3 Fix wasm refcount tests 2022-01-19 23:21:29 -05:00
ayazhafiz
ae104c3791 Elide unnecessary lifetimes 2022-01-19 23:16:48 -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
ayazhafiz
3342090e7b Add var_contains_content conditional function to Subs
This function checks for the existence of a content of a certain shape
on a content, or any its deep children.
2022-01-19 22:51:15 -05:00
hafiz
8858c7a4bd
Merge pull request #2373 from rtfeldman/mono-test-lambda-set-debug
Mono test lambda set debug
2022-01-19 22:48:29 -05:00
Folkert
a2cb9035c4 formatting 2022-01-19 23:56:14 +01:00
Folkert
202a8438ce change UserApp -> Test in mono tests 2022-01-19 23:22:19 +01:00
Folkert
72e883a20b make symbol debug formatting consistent 2022-01-19 23:21:18 +01:00
Folkert
ee4c2177c0 add annotation for Effect.loop 2022-01-19 23:13:34 +01:00
Folkert
5230c6f6f3 implement Effect.loop 2022-01-19 23:06:32 +01:00
Folkert
2adcbecf8a update mono tests 2022-01-19 21:01: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
859bdf5212 Merge remote-tracking branch 'origin/trunk' into effect-forever 2022-01-19 20:14:24 +01:00
Folkert
4c445f9f24 recognize functions that become tail-recursive after closure conversion 2022-01-19 20:09:20 +01:00
Anton-4
dcbd1fb7f8 peg grammar progress 2022-01-19 19:52:01 +01:00
Folkert
aecafe5c80 add Task.forever to platforms 2022-01-19 19:32:18 +01:00
Folkert
389681ee90 return forall b. Effect b 2022-01-19 19:19:43 +01:00
Folkert
359956220e working definition of Effect.forever 2022-01-19 19:11:37 +01: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
Brian Carroll
27d921ff66
Merge pull request #2370 from rtfeldman/remove_trailing_spaces
Remove trailing spaces
2022-01-19 14:04:11 +00:00
Jan Van Bruggen
fb66467343 Remove trailing spaces from test snapshots 2022-01-18 22:33:24 -07:00