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
6 changes: 4 additions & 2 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4088,6 +4088,7 @@ foreach(own_test own_fresh_string own_fresh_array own_return_new own_try_local o
own_generator_take own_rest_array_borrows own_string_copies
own_captured_string_callback own_callback_and_call own_callback_captured own_literal_closures own_literal_variable_closures own_temporary_field_take own_union_narrowed_calls own_named_field_take own_let_field_take own_literal_captures own_literal_object_captures own_literal_interface_captures own_literal_let_captures own_interface_generic_method own_back_reference own_field_function_result
own_callback_shapes own_callback_extended own_callback_interface
own_generic_specializations own_callback_cast own_callback_interface_slot own_equal_strings_into_any)
own_generic_specializations own_callback_cast own_callback_interface_slot
own_any_copies own_array_copies own_string_pushed_twice own_rest_takes own_shares_elements
own_rest_keeps_declared)
Expand Down Expand Up @@ -4120,15 +4121,16 @@ endforeach()

# A generator whose `@keeps` makes its state own its arguments (spec 38), and one given a generator
# that borrows, and one over its `this` parameter; strings copied within a parameter the result borrows;
# elements and fields swapped; a callback given on through a parameter; the same programs under every
# other model.
# elements and fields swapped; a callback given on through a parameter; two equal concatenations
# each boxed into an `any` once; the same programs under every other model.
foreach(keeps_mm rc gc none)
foreach(keeps_test own_generator_keeps own_generator_keeps_bounded own_generator_this_param
own_copy_within_returned_param own_swap_elements own_callback_forwarded
own_optional_record_read own_param_default_kept own_literal_into_array
own_generator_take own_rest_array_borrows own_string_copies
own_captured_string_callback own_callback_and_call own_callback_captured own_literal_closures own_literal_variable_closures own_temporary_field_take own_union_narrowed_calls own_named_field_take own_let_field_take own_literal_captures own_literal_object_captures own_literal_interface_captures own_literal_let_captures own_interface_generic_method own_back_reference own_field_function_result
own_callback_shapes own_callback_extended own_callback_interface
own_generic_specializations own_callback_cast own_callback_interface_slot own_equal_strings_into_any)
own_generic_specializations own_callback_cast own_callback_interface_slot own_rest_keeps_declared)
tslang_add_test(NAME test-jit-${keeps_mm}-${keeps_test} COMMAND test-runner -jit -mm=${keeps_mm} "${PROJECT_SOURCE_DIR}/test/tester/own/${keeps_test}.ts")
tslang_add_test(NAME test-compile-${keeps_mm}-${keeps_test} COMMAND test-runner -mm=${keeps_mm} "${PROJECT_SOURCE_DIR}/test/tester/own/${keeps_test}.ts")
Expand Down
47 changes: 47 additions & 0 deletions tslang/test/tester/own/own_equal_strings_into_any.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// -mm=own: two named consts built from the same run-time concatenation are two strings, each with
// its own owner. The optimiser's CSE would merge them into one value with two owners, so under own
// it does not run ahead of inference (the JIT optimises: `-jit` is the run that found it). Each is
// boxed into an `any` argument once, and both are read after a `churn()`.
class Bag {
keys: any[] = [];
has(key: any) {
for (const k of this.keys) if (k == key) return true;
return false;
}
}

class C {
has(a: any) {
return true;
}
}

function churn() {
const junk: string[] = [];
for (let i = 0; i < 64; i++) {
junk.push("junk" + i);
}
}

function main() {
const c = new C();
const s1 = "Hel" + "lo";
print(c.has(s1));
const s2 = "Hel" + "lo";
print(c.has(s2));

const b = new Bag();
let found = 0;
for (let i = 0; i < 1000; i++) {
const k1 = "k" + "ey";
const k2 = "k" + "ey";
if (b.has(k1)) found++;
if (b.has(k2)) found++;
churn();
assert(k1 == "key" && k2 == "key");
}

assert(found == 0);
assert(s1 == "Hello" && s2 == "Hello");
print("done.");
}
8 changes: 7 additions & 1 deletion tslang/tslang/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ int runMLIRPasses(mlir::MLIRContext &context, llvm::SourceMgr &sourceMgr, mlir::
#ifdef ENABLE_OPT_PASSES
if (enableOpt)
{
optPM.addPass(mlir::createCSEPass());
// optPM runs ahead of own's inference. Not under own: CSE merges two equal allocations
// (`"a" + b` twice) into one value, which before inference has two owners and after it
// two releases. Under rc their retains and releases stay paired.
if (compileOptions.memoryModel != MemoryModelOwn)
{
optPM.addPass(mlir::createCSEPass());
}
pm.addPass(mlir::createLoopInvariantCodeMotionPass());
// Not under --di: stripping left every function a subprogram and every call no
// location, which the LLVM dialect's verifier rejects for a call it could inline
Expand Down
Loading