hash-org / hash-org/hashc

tir+lower: emit function names for monomorphised functions

Open
#990 0 comments 0 reactions 0 assignees View on GitHub
lowering type-system
Dominant language
Rust
Stars
28
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Currently, the semantic pass doesn't generate names for monomorphised names, so for code like:
```rs
main := () => {
buf : [u8; 9] = [1u8; 9]
mut sum := 0u32
mut count := 0usize

while count < 9 {
sum += cast<_, u32>(buf[count])
count += 1usize
}

if sum == 9 {
println("sum is 9")
} else {
println("sum is not 9")
}
}
```
The `cast` function which is generic over `T` and `U` is generated as the following IR:
```rust
main := () -> () {
mut _0: ();
_1: [u8; 9]; // parameter `buf`
_2: u32; // parameter `sum`
_3: usize; // parameter `count`
mut _4: bool;
mut _5: u32;
_6: usize;
_7: (u32, bool);
_8: (usize, bool);
mut _9: bool;

bb0: {
_1 = [const 1_u8; 9];
_2 = const 0_u32;
_3 = const 0_u64;
goto -> bb1;
}

bb1: {
_4 = Lt(_3, const 9_u64);
switch(_4) [false -> bb2, otherwise -> bb3];
}

bb2: {
_9 = Eq(_2, const 9_u32);
switch(_9) [false -> bb7, otherwise -> bb8];
}

bb3: {
_6 = _3;
_5 = _(_1[_6]) -> bb4; // <-- the `cast` function is the `_`
}

...
}
```

In order to generate names, we would have to change the mono pass to create/inherit names from the original polymorphic function. It is still unclear whether the function naming scheme should be, some possible variants:
- `cast_u8_u32` - we should append the concrete type arguments after the initial function name.
- `cast` - we use a similar syntax to the type arguments as in the language. The symbol mangling in the code generation would need to be adjusted to support this (but it shouldn't be too much of a problem).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.