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
18 changes: 10 additions & 8 deletions tslang/lib/TypeScript/MLIRGenVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,17 +878,19 @@ namespace mlirgen
{
// the resolved symbol's storage is a single boxed
// pointer (ObjectType lowers to `ptr`) to the real
// data, not the data inline - load the pointer first,
// then load through it, instead of reading
// sizeof(fieldType) bytes directly at the symbol's own
// address (which would read past a lone 8-byte slot).
// See DeclarationPrinter.cpp's @boxed emission.
// data, not the data inline - load the pointer,
// instead of reading sizeof(fieldType) bytes directly
// at the symbol's own address (which would read past a
// lone 8-byte slot). The variable is that pointer, as
// the exporter's is: a copy of the data it points to
// was a snapshot, which the exporter's object never saw
// a write to, nor a method call, and a cast to an
// interface copied again. See DeclarationPrinter.cpp's
// @boxed emission.
auto boxedType = getObjectType(fieldType);
auto refToBoxed = cast(location, mlir_ts::RefType::get(boxedType), referenceToStaticFieldOpaque, genContext);
auto boxedPtr = V(builder.create<mlir_ts::LoadOp>(location, boxedType, refToBoxed));
auto refToTyped = V(cast(location, mlir_ts::RefType::get(fieldType), boxedPtr, genContext));
auto valueOfField = builder.create<mlir_ts::LoadOp>(location, fieldType, refToTyped);
return std::make_tuple(valueOfField.getType(), V(valueOfField), TypeProvided::Yes);
return std::make_tuple(boxedPtr.getType(), boxedPtr, TypeProvided::Yes);
}

auto refToTyped = cast(location, mlir_ts::RefType::get(fieldType), referenceToStaticFieldOpaque, genContext);
Expand Down
3 changes: 3 additions & 0 deletions tslang/test/tester/tests/export_object_literal_untyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ namespace A {
// `count: 0.0`: an integer literal is an s32, which the interface's `number` field would widen,
// and a cast of an object whose method writes that field is an error (castObjectToInterface)
export var counterObj = { count: 0.0, inc() { this.count = this.count + 1; } };

// the exporter's own view of the object, after the importer changed it
export function countOf() { return counterObj.count; }
}
4 changes: 4 additions & 0 deletions tslang/test/tester/tests/import_object_literal_untyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ var c: A.Counter = <A.Counter>A.counterObj;
c.inc();
print(c.count);
assert(c.count == 3);
// the interface and the import are one object, the exporter's: the importer's variable is its
// boxed pointer, not a copy of what it points to
assert(A.counterObj.count == 3);
assert(A.countOf() == 3);

print("done.");
Loading