Commit graph

16 commits

Author SHA1 Message Date
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
0ed259a80d phase 3 2022-01-26 14:37:32 +01:00
Brian Carroll
5560ecb63e Implement tail recursion for union refcounting procs 2022-01-06 22:43:02 +00:00
Brian Carroll
040b8ce430 Reduce code size for Union refcount procedures 2022-01-06 10:49:34 +00:00
Brian Carroll
d9cc3c5692 Modify refcount of contents *before* structure to prevent use-after-free 2022-01-06 10:49:34 +00:00
Brian Carroll
5e642c880c Mask out union tag ID from pointer when calculating refcount address 2022-01-06 10:49:34 +00:00
Brian Carroll
5d7b4018b7 Generate refcounting helper procedures for tag unions 2022-01-05 12:24:04 +00:00
Brian Carroll
1de26c084d Make Struct DecRef a no-op 2022-01-01 21:57:28 +00:00
Brian Carroll
98ab97083a For DecRef, remove assumption that the refcounted symbol is ARG_1 2022-01-01 21:57:28 +00:00
Brian Carroll
176bb6f6aa Use joinpoints for DecRef 2022-01-01 21:57:28 +00:00
Brian Carroll
e55806fe27 Update is_rc_implemented_yet 2022-01-01 12:33:36 +00:00
Brian Carroll
8078afc74f Delete a stray println from debug 2022-01-01 11:39:55 +00:00
Brian Carroll
310de090a3 Wasm: Refcounting for struct fields 2022-01-01 11:32:53 +00:00
Brian Carroll
12a330dd76 Refactor to move all refcount IR gen to the same file 2021-12-31 23:09:11 +00:00
Brian Carroll
c5663e3538 Generate IR helper proc for list refcounting 2021-12-30 17:15:31 +00:00
Brian Carroll
37de499248 Reorganise code gen helper in roc_mono 2021-12-28 11:03:33 +00:00