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
9 changes: 7 additions & 2 deletions tslang/include/TypeScript/MLIRLogic/MLIRGenStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ enum class Select: int

struct VariableClass
{
VariableClass() : type{VariableType::Const}, isExport{false}, isImport{false}, isDynamicImport{false}, isPublic{false}, isUsing{false}, isAppendingLinkage{false}, comdat{Select::NotSet}, isUsed{false}, atomic{false}, ordering{0}, syncscope{StringRef()}, isVolatile{false}, nonTemporal{false}, invariant{false}
VariableClass() : type{VariableType::Const}, isExport{false}, isImport{false}, isDynamicImport{false}, isPublic{false}, isUsing{false}, isAppendingLinkage{false}, comdat{Select::NotSet}, isUsed{false}, atomic{false}, ordering{0}, syncscope{StringRef()}, isVolatile{false}, nonTemporal{false}, invariant{false}, isBoxed{false}
{
}

VariableClass(VariableType type_) : type{type_}, isExport{false}, isImport{false}, isDynamicImport{false}, isPublic{false}, isUsing{false}, isAppendingLinkage{false}, comdat{Select::NotSet}, isUsed{false}, atomic{false}, ordering{0}, syncscope{StringRef()}, isVolatile{false}, nonTemporal{false}, invariant{false}
VariableClass(VariableType type_) : type{type_}, isExport{false}, isImport{false}, isDynamicImport{false}, isPublic{false}, isUsing{false}, isAppendingLinkage{false}, comdat{Select::NotSet}, isUsed{false}, atomic{false}, ordering{0}, syncscope{StringRef()}, isVolatile{false}, nonTemporal{false}, invariant{false}, isBoxed{false}
{
}

Expand All @@ -97,6 +97,11 @@ struct VariableClass
bool isVolatile;
bool nonTemporal;
bool invariant;
// @dllimport declaration-only marker: the exported symbol's storage is a
// single boxed pointer to the real data, not the data inline - see
// DeclarationPrinter.cpp's printVariableDeclaration and
// MLIRGenVariables.cpp's isDynamicImport load branch.
bool isBoxed;

inline VariableClass& operator=(VariableType type_) { type = type_; return *this; }

Expand Down
21 changes: 21 additions & 0 deletions tslang/lib/TypeScript/DeclarationPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,27 @@ namespace typescript

printBeforeDeclaration();

// no TS source syntax expresses "this symbol's storage is a single
// boxed pointer to the real data, not the data inline" - an inferred
// (untyped) object-literal export is boxed as ObjectType, but its
// structural-shape declaration text alone is indistinguishable from an
// explicitly-typed (unboxed, inline) export of the same shape. Emit a
// sibling @boxed decorator so the importer's isDynamicImport load
// (MLIRGenVariables.cpp, the branch that actually runs for every
// ordinary `import '...'` - see mlirGenImportSharedLib's '.' hack)
// knows to dereference one extra level instead of reading the tuple
// inline at the resolved symbol address.
if (auto objectType = dyn_cast<mlir_ts::ObjectType>(type))
{
auto storageType = objectType.getStorageType();
if (isa<mlir_ts::TupleType>(storageType) || isa<mlir_ts::ConstTupleType>(storageType) ||
isa<mlir_ts::ObjectStorageType>(storageType))
{
os << "@boxed";
newline();
}
}

os << (isConst ? "const" : "let") << " " << name << " : ";
print(type);
os << ";";
Expand Down
22 changes: 22 additions & 0 deletions tslang/lib/TypeScript/MLIRGenVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,24 @@ namespace mlirgen
auto dllVarName = V(mlirGenStringValue(location, nameStr, true));
auto referenceToStaticFieldOpaque = builder.create<mlir_ts::SearchForAddressOfSymbolOp>(
location, getOpaqueType(), dllVarName);

if (varClass.isBoxed)
{
// 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.
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);
}

auto refToTyped = cast(location, mlir_ts::RefType::get(fieldType), referenceToStaticFieldOpaque, genContext);
auto valueOfField = builder.create<mlir_ts::LoadOp>(location, fieldType, refToTyped);
return std::make_tuple(valueOfField.getType(), V(valueOfField), TypeProvided::Yes);
Expand Down Expand Up @@ -766,6 +784,10 @@ namespace mlirgen
}
}

if (name == "boxed") {
varClass.isBoxed = true;
}

if (name == "used") {
varClass.isUsed = true;
}
Expand Down
6 changes: 0 additions & 6 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,7 @@ add_test(NAME test-compile-shared-decl-emit-class COMMAND test-runner -shared "$
add_test(NAME test-compile-shared-export-import-class-interface COMMAND test-runner -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_interface.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_interface.ts")
add_test(NAME test-compile-shared-export-import-object-literal-with-class-types COMMAND test-runner -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_with_class_types.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_with_class_types.ts")
add_test(NAME test-compile-shared-export-import-object-literal-with-interface COMMAND test-runner -shared -gctors-as-method "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_with_interface.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_with_interface.ts")
# DISABLED: hangs (deadlock, not a crash - see docs/interface-vtable-simplification-design.md
# "Bug 1"). Direct field/method access on an imported untyped-export boxed global reaches a
# still-unfixed cross-module boxed-global initialization-ordering issue. Re-enable once fixed.
add_test(NAME test-compile-shared-export-import-object-literal-untyped COMMAND test-runner -shared -gctors-as-method "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_untyped.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_untyped.ts")
set_tests_properties(test-compile-shared-export-import-object-literal-untyped PROPERTIES DISABLED TRUE)
add_test(NAME test-compile-shared-export-import-object-literal-structural-typed COMMAND test-runner -shared -gctors-as-method "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_structural_typed.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_structural_typed.ts")
add_test(NAME test-compile-shared-export-import-object-literal-structural-typed-params COMMAND test-runner -shared -gctors-as-method "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_structural_typed_params.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_structural_typed_params.ts")
add_test(NAME test-compile-shared-export-import-vars COMMAND test-runner -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_vars.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_vars.ts")
Expand All @@ -875,9 +871,7 @@ add_test(NAME test-jit-shared-decl-emit-class COMMAND test-runner -jit -shared "
add_test(NAME test-jit-shared-export-import-class-interface COMMAND test-runner -jit -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_interface.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_interface.ts")
add_test(NAME test-jit-shared-export-import-object-literal-with-class-types COMMAND test-runner -jit -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_with_class_types.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_with_class_types.ts")
add_test(NAME test-jit-shared-export-import-object-literal-with-interface COMMAND test-runner -jit -shared -gctors-as-method "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_with_interface.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_with_interface.ts")
# DISABLED: same known deadlock as the test-compile variant above.
add_test(NAME test-jit-shared-export-import-object-literal-untyped COMMAND test-runner -jit -shared -gctors-as-method "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_untyped.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_untyped.ts")
set_tests_properties(test-jit-shared-export-import-object-literal-untyped PROPERTIES DISABLED TRUE)
add_test(NAME test-jit-shared-export-import-object-literal-structural-typed COMMAND test-runner -jit -shared -gctors-as-method "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_structural_typed.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_structural_typed.ts")
add_test(NAME test-jit-shared-export-import-object-literal-structural-typed-params COMMAND test-runner -jit -shared -gctors-as-method "${PROJECT_SOURCE_DIR}/test/tester/tests/import_object_literal_structural_typed_params.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_object_literal_structural_typed_params.ts")
add_test(NAME test-jit-shared-export-import-vars COMMAND test-runner -jit -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_vars.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_vars.ts")
Expand Down
Loading