Repository navigation
Commit ee08124
`let S = "text" + 4;` at module level, read by a function, failed to compile in every model:
"ops with side effects not allowed in global initializers". GlobalOpLowering puts an initializer
that looks constant into the llvm.mlir.global's own region and anything that runs code into a
per-global constructor. Its list knew ts.StringConcat, but at that point the concatenation is
still a ts.ArithmeticBinary with a string result, and the number's conversion (`ts.Cast` si32 ->
string, a sprintf into a new block) was not on the list either, so both landed in the region,
where allocating is not allowed. With a variable or a call among the operands it was already a
constructor, and a global nothing reads was dropped before it mattered.
Now a string-typed ts.ArithmeticBinary, and a cast to string from anything that is not already a
string, make the global a constructor. A plain string constant stays in place.
Test: 00global_constant_concat (compile and JIT, and in the rc/none corpus): `"text" + 4`,
`"text" + "four"`, a `string | null` and `"" + 6.5` globals read in main, a plain string constant,
and a reassignment. It failed to compile before the change.
Fixes #469.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 239c004 commit ee08124
3 files changed
Lines changed: 43 additions & 0 deletions
File tree
- tslang
- lib/TypeScript
- test/tester
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4418 | 4418 | | |
4419 | 4419 | | |
4420 | 4420 | | |
| 4421 | + | |
| 4422 | + | |
| 4423 | + | |
| 4424 | + | |
| 4425 | + | |
| 4426 | + | |
| 4427 | + | |
4421 | 4428 | | |
4422 | 4429 | | |
4423 | 4430 | | |
| 4431 | + | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
4424 | 4437 | | |
4425 | 4438 | | |
4426 | 4439 | | |
4427 | 4440 | | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
4428 | 4446 | | |
4429 | 4447 | | |
4430 | 4448 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
| 470 | + | |
470 | 471 | | |
471 | 472 | | |
472 | 473 | | |
| |||
956 | 957 | | |
957 | 958 | | |
958 | 959 | | |
| 960 | + | |
959 | 961 | | |
960 | 962 | | |
961 | 963 | | |
| |||
1780 | 1782 | | |
1781 | 1783 | | |
1782 | 1784 | | |
| 1785 | + | |
1783 | 1786 | | |
1784 | 1787 | | |
1785 | 1788 | | |
| |||
| 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 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments