Commit graph

28 commits

Author SHA1 Message Date
Brian Carroll
ab3a75b754 wasm: fix WasmLayout for LambdaSet 2022-04-05 00:02:05 +01:00
Brian Carroll
5db3ae0227 wasm: code gen for higher order wrapper function 2022-04-05 00:02:05 +01:00
Brian Carroll
83cae16a60 wasm: Generate code for List.map call (incomplete) 2022-04-05 00:02:05 +01:00
Folkert
92f2927046
initial implementation 2022-03-08 19:09:42 +01: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
Folkert
c663a35e16 final phase 2022-01-26 15:44:24 +01:00
Brian Carroll
72fa6217fb Refactor wasm lowlevels to make it easier to add more 128-bit ops 2021-12-01 15:09:23 +00:00
Brian Carroll
079a8311ec Delete HeapMemory variant of WasmLayout, just treat pointers as Primitive
When I created this (at the very beginning of the Wasm backend),
I didn't really have a clear reason for it. I just thought it might end up
making sense treat heap pointers differently from numbers, somehow.

But the semantic differences between pointers and other numbers is not relevant
to WasmLayout. The semantics are clear from where the Symbol appears in the IR.

Also we were storing heap pointers in locals, for no real reason.
And the fact that it's *different* meant a lot of new cases in match expressions,
to do the exact same thing as Primitives but with a pointless difference.

Until now, we haven't really used this variant in any of our tests.
But the refcount pointer needed it... and everything broke!
2021-11-30 09:57:00 +00:00
Brian Carroll
88bf6bf1b7 Clean up Wasm calling convention code 2021-11-29 00:17:45 +00:00
Folkert
a1fd34feef remove empty layout types (list,str,dict,set) 2021-11-27 14:05:16 +01:00
Folkert
f96d60a13e Merge remote-tracking branch 'origin/trunk' into layout-builtin-numbers-refactor 2021-11-21 23:19:55 +01:00
Brian Carroll
2e31350010 Logic to load 128-bit numbers 2021-11-21 20:44:16 +00:00
Folkert
dc44eaac97 cleanup 2021-11-21 14:11:18 +01:00
Folkert
ce8615fbbc wasm working 2021-11-21 00:41:37 +01:00
Folkert
c4ec9aa898 working mono 2021-11-20 23:25:30 +01:00
Brian Carroll
7c95189e4a Get lots of Num lowlevel ops working 2021-11-10 14:21:32 +00:00
Brian Carroll
ad9b761fce Move wasm file format code into a submodule 2021-11-03 11:20:16 +00:00
Brian Carroll
59757d638a Migrate the last sections: Type and Function 2021-11-03 10:24:03 +00:00
Brian Carroll
973626fe2d Rename FunctionBuilder back to CodeBuilder 2021-10-23 13:48:20 +02:00
Brian Carroll
74e3239a1c Switch over to function_builder 2021-10-23 13:39:54 +02:00
Brian Carroll
3aaafdefe1 Get Join/Jump working with VM storage 2021-10-09 16:46:59 +01:00
Brian Carroll
7ea59ad9d4 PR tidy-ups 2021-09-29 06:15:58 +01:00
Brian Carroll
02bb9028ef Returning records on the stack from Wasm dev backend! 2021-09-28 08:06:59 +01:00
Brian Carroll
c3b5ac6c82 Allocate stack memory to local variables 2021-09-18 13:39:38 +01:00
Brian Carroll
52a56bfa27 Optimise away a memory copy for returned structs in simple cases 2021-09-17 21:50:00 +01:00
Brian Carroll
036503c750 copy returned structs to caller stack 2021-09-17 19:42:29 +01:00
Brian Carroll
2be2e09ffd Merge branch 'trunk' of github.com:rtfeldman/roc into wasm_stack_memory 2021-09-14 14:57:17 +02:00
Brian Carroll
866d9f47a0 Move WasmLayout to its own module 2021-09-14 08:31:32 +02:00