Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions TSLANG_ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ should be a complete file that was run (`tslang file.ts`, JIT, Windows x64), wit

## Open

Items 1-26 (collected 2026-10-12 to pre-alpha115) are fixed or answered; their write-ups are in this
file's git history. The last three, fixed by #775 (regression tests
Items 1-27 (collected 2026-10-12 to pre-alpha116) are fixed or answered; their write-ups are in this
file's git history. 24-26 were fixed by #775 (regression tests
`tslang/test/tester/tests/00tslang_issues_24_26.ts` and `ref_element_layout_error.ts`): 24 (an array
literal holding `const X = 1 << n` widened to 64-bit elements: shifts and bitwise operators now give an
`s32`, as `int` is); 25 (`cond ? [1] : []` crashed when iterated: an empty array literal now takes the
other branch's array type); 26 (`Ref(x)` of a `number` was accepted for a `Ref<f32>` parameter: a
reference to a number laid out otherwise is now an error).
reference to a number laid out otherwise is now an error). 27 (`-mm=rc`: a template literal passed
straight to a call reached the callee with no reference behind it, so `console.log(text)` freed it
before `this.message = text` stored it): a template, and an object or literal array printed into a
string, now carry a reference of their own as `"a" + b` does, which the caller gives back after the
call. Under `-mm=own` and rc the same strings also leaked (3M template arguments: ~570 MB, now ~50 MB).
Regression test `tslang/test/tester/tests/00tslang_issue_27.ts`.
13 changes: 10 additions & 3 deletions tslang/lib/TypeScript/MLIRGenCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,11 @@ namespace mlirgen
auto concatValues =
builder.create<mlir_ts::StringConcatOp>(location, stringType, mlir::ArrayRef<mlir::Value>{strs});

return V(concatValues);
}
// a new string, owned as a template's is (TSLANG 27)
markFreshBlockOwned(location, concatValues);

return V(concatValues);
}

return mlir::failure();
}
Expand Down Expand Up @@ -587,7 +590,11 @@ namespace mlirgen
auto concatValues =
builder.create<mlir_ts::StringConcatOp>(location, stringType, mlir::ArrayRef<mlir::Value>{strs});

return V(concatValues);
// `<string>{ a: 1 }` builds a new string, owned as a template's is: unmarked, passed
// straight to a call it reached the callee with no reference behind it (TSLANG 27)
markFreshBlockOwned(location, concatValues);

return V(concatValues);
}

// An interface printed: its `toString` when it has one, as a class's is; else its fields, read
Expand Down
7 changes: 7 additions & 0 deletions tslang/lib/TypeScript/MLIRGenExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,13 @@ namespace mlirgen
auto concatValues =
builder.create<mlir_ts::StringConcatOp>(location, stringType, mlir::ArrayRef<mlir::Value>{strs});

// a template builds a new string, as `"a" + b` does: it carries a reference of its own,
// which a receiver takes over and which is given back at the end of the block otherwise.
// Unmarked, `f(\`a${b}\`)` passed a string nothing held: under rc a callee that handed its
// parameter to a call (`console.log(text)`) dropped the count to zero and freed it before
// `this.message = text` stored it (TSLANG 27).
markFreshBlockOwned(location, concatValues);

return V(concatValues);
}

Expand Down
5 changes: 5 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,11 @@ endforeach()
foreach(issues_mm gc rc none own)
tslang_add_test(NAME test-jit-00-tslang-issues-24-26-${issues_mm} COMMAND test-runner -jit -mm=${issues_mm} "${PROJECT_SOURCE_DIR}/test/tester/tests/00tslang_issues_24_26.ts")
endforeach()
# TSLANG_ISSUES 27: a template literal argument is held by the caller until the call returns
foreach(issues_mm gc rc none own)
tslang_add_test(NAME test-jit-00-tslang-issue-27-${issues_mm} COMMAND test-runner -jit -mm=${issues_mm} "${PROJECT_SOURCE_DIR}/test/tester/tests/00tslang_issue_27.ts")
tslang_add_test(NAME test-compile-00-tslang-issue-27-${issues_mm} COMMAND test-runner -mm=${issues_mm} "${PROJECT_SOURCE_DIR}/test/tester/tests/00tslang_issue_27.ts")
endforeach()
# ...a reference to a number is no reference to an f32
add_test(NAME test-compile-ref-element-layout-error
COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/ref_element_layout_error.ts")
Expand Down
54 changes: 54 additions & 0 deletions tslang/test/tester/tests/00tslang_issue_27.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// TSLANG_ISSUES 27: a template literal passed straight to a call is a new string the caller holds
// until the call returns. Under rc it arrived with no reference behind it, so a callee handing its
// parameter to a call first (console.log, whose rest array retains and releases it) dropped the
// count to zero and freed the string before it stored it.

const NAMES = ["down", "off", "point", "tilt"];

// stands for console.log: the rest array holds what it is given and lets go of it on return
function log(...parts: string[]) {
print(parts[0]);
}

class Hud {
message: string = "";
show(text: string) {
log(text);
this.message = text;
}
}

let kept = "";
function keep(text: string) {
log(text);
kept = text;
}

function main() {
const hud = new Hud();
for (let i = 0; i < 8; i++) {
hud.show(`Gravity: ${NAMES[i % 4]}`);
// a fresh string made in the block reuses what was freed
const other = `XXXXXXXX: ${NAMES[(i + 1) % 4]}`;
assert(hud.message == "Gravity: " + NAMES[i % 4], "the method kept its template argument");
assert(other == "XXXXXXXX: " + NAMES[(i + 1) % 4], "the next template");

keep(`Keep ${i}: ${NAMES[i % 4]}`);
const again = `YYYYYYYY: ${NAMES[(i + 2) % 4]}`;
assert(kept == "Keep " + i + ": " + NAMES[i % 4], "the function kept its template argument");
assert(again.length == 10 + NAMES[(i + 2) % 4].length, "the template after it");

// an object or a literal array printed into a string is a new string too
keep(<string>{ a: i });
const third = `ZZZZZZZZ: ${NAMES[(i + 3) % 4]}`;
assert(kept == "{ a: " + i + " }", "the function kept an object printed into a string");
assert(third.length == 10 + NAMES[(i + 3) % 4].length, "the template after the object");

hud.show(<string>[1, 2]);
const fourth = `WWWWWWWW: ${NAMES[i % 4]}`;
assert(hud.message == "[ 1, 2 ]", "the method kept a literal array printed into a string");
assert(fourth.length == 10 + NAMES[i % 4].length, "the template after the array");
}

print("done.");
}
Loading