Commit e05448b
authored
fix miscompilation with indirect tail calls (nim-works#1573)
## Summary
Fix a bug with the tail call elimination that caused target compiler
errors, or run-time errors, with the JS and C targets, in some edge
cases involving indirect tail calls.
## Details
In the MIR type IR, there are no `sink` types, meaning that
`proc(x: sink T)` and `proc(x: T)` map to the same type
representation -- the one first registered with the environment is
considered the canonical one.
The tail call elimination looked up the `PType` for the canonical type
of `.tailcall` procvals, yielding a `PType that's not the original for
the MIR type that's not the canonical one. Since the `sink` modifier is
significant for the parameter tuple type creation, this led to the
tuple having the wrong type for one of the indirect calls.
The lookup is changed to use the original instead of the canonical MIR
type, fixing the problem. A regression test reproducing the problem
is added.1 parent ec117c4 commit e05448b
File tree
2 files changed
+20
-1
lines changed- compiler/mir
- tests/lang_callable/proc
2 files changed
+20
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments