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
50 changes: 50 additions & 0 deletions tslang/lib/TypeScript/MLIRGenImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8336,6 +8336,26 @@ class MLIRGenImpl
}

getGenericTypeAliasMap().insert({namePtr, {typeParameters, typeAliasDeclarationAST->type}});

// support dynamic loading: like a generic class/function/interface, a
// generic type alias has no compiled body or runtime entity at all -
// resolution is pure compile-time type substitution
// (getTypeByTypeReference/resolveGenericTypeInNamespace call
// getType(typeNode, ...) directly on the stored TypeNode, never
// re-invoking mlirGen on the whole declaration), unlike
// GenericClassInfo/GenericFunctionInfo/GenericInterfaceInfo there is no
// dedicated Info struct tracking sourceFile/elementNamespace for this
// declaration kind - print inline here instead of adding one, since this
// is the only place needing it and there is no "already registered"
// early-return branch to retry from (unlike registerGenericClass/
// registerGenericFunctionLike/registerGenericInterface):
// isAddedToExport's own stage gate is unnecessary too since a given
// top-level TypeAliasDeclaration node is visited exactly once per stage,
// so a direct stage check is sufficient dedup.
if (hasExportModifier && stage == Stages::SourceGeneration)
{
addGenericTypeAliasDeclarationToExport(typeAliasDeclarationAST, currentNamespace);
}
}
else
{
Expand Down Expand Up @@ -10438,6 +10458,36 @@ class MLIRGenImpl
genericDeclExports << ss.str().str();
}

void addGenericTypeAliasDeclarationToExport(TypeAliasDeclaration typeAliasDeclarationAST, NamespaceInfo::TypePtr elementNamespace)
{
// same bounds-check as addGenericClassDeclarationToExport - a generic type alias
// re-declared while re-importing another module's embedded declarations still
// carries its own `export` keyword verbatim, but at that point `sourceFile` is
// the ambient/outer file, not the "partial" buffer parsePartialStatements
// actually parsed this declaration from.
auto declEnd = static_cast<size_t>(typeAliasDeclarationAST->_end);
if (declEnd > sourceFile->text.length())
{
return;
}

// like a generic class, a generic type alias has no compiled body for any given
// instantiation: resolution is pure compile-time type substitution, done fresh in
// whichever module references it. So the FULL original source - type parameters
// and the aliased type expression intact, no @dllimport marker - must be
// re-exported verbatim for parsePartialStatements to recompile per reference in
// the importer.
auto declText = convertWideToUTF8(getTextOfNodeFromSourceText(
sourceFile->text, typeAliasDeclarationAST.as<Node>(), true));

SmallVector<char> out;
llvm::raw_svector_ostream ss(out);
MLIRDeclarationPrinter dp(ss);
dp.printGenericClass(elementNamespace, declText);

genericDeclExports << ss.str().str();
}

auto getNamespaceName() -> StringRef
{
return currentNamespace->name;
Expand Down
3 changes: 3 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ add_test(NAME test-compile-export-import-class-static COMMAND test-runner "${PRO
# See class-generic-declaration-export-fix memory for the full account.
add_test(NAME test-compile-export-import-class-generic COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_generic.ts")
add_test(NAME test-compile-export-import-function-generic COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/import_function_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_function_generic.ts")
add_test(NAME test-compile-export-import-type-alias-generic COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/import_type_alias_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_type_alias_generic.ts")
add_test(NAME test-compile-export-import-class-accessor COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_accessor.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_accessor.ts")
add_test(NAME test-compile-export-import-class-indexer COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_indexer.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_indexer.ts")
add_test(NAME test-compile-export-import-interface-indexer COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/import_interface_indexer.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_interface_indexer.ts")
Expand Down Expand Up @@ -957,6 +958,7 @@ add_test(NAME test-compile-shared-export-import-class-structural-interface COMMA
# FIXED: see the matching test-compile-export-import-class-generic comment above (2026-07-22).
add_test(NAME test-compile-shared-export-import-class-generic COMMAND test-runner -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_generic.ts")
add_test(NAME test-compile-shared-export-import-function-generic COMMAND test-runner -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_function_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_function_generic.ts")
add_test(NAME test-compile-shared-export-import-type-alias-generic COMMAND test-runner -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_type_alias_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_type_alias_generic.ts")
# FIXED (2026-07-22): the -shared declaration-reconstruction path never printed real
# get/set syntax for a class's accessors, only the underlying get_x/set_x funcOps as
# ordinary methods - so property-style access ("Class member 'celsius' can't be found")
Expand Down Expand Up @@ -1004,6 +1006,7 @@ add_test(NAME test-jit-shared-export-import-class-structural-interface COMMAND t
# FIXED: see the matching test-compile-export-import-class-generic comment above (2026-07-22).
add_test(NAME test-jit-shared-export-import-class-generic COMMAND test-runner -jit -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_generic.ts")
add_test(NAME test-jit-shared-export-import-function-generic COMMAND test-runner -jit -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_function_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_function_generic.ts")
add_test(NAME test-jit-shared-export-import-type-alias-generic COMMAND test-runner -jit -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_type_alias_generic.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_type_alias_generic.ts")
# FIXED: see the matching test-compile-shared-export-import-class-accessor comment above (2026-07-22).
add_test(NAME test-jit-shared-export-import-class-accessor COMMAND test-runner -jit -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_accessor.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_accessor.ts")
add_test(NAME test-jit-shared-export-import-class-indexer COMMAND test-runner -jit -shared "${PROJECT_SOURCE_DIR}/test/tester/tests/import_class_indexer.ts" "${PROJECT_SOURCE_DIR}/test/tester/tests/export_class_indexer.ts")
Expand Down
18 changes: 18 additions & 0 deletions tslang/test/tester/tests/export_type_alias_generic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace M {

// Cross-module counterpart to 00type_aliases_in_generics.ts. The
// genericTypeAliasMap entry (MLIRGenStore.h) has no dedicated Info struct
// (unlike GenericClassInfo/GenericFunctionInfo/GenericInterfaceInfo) - it
// was the last unverified item flagged in
// decls-cross-module-declaration-mechanism / generic-interface-cross-module-export-fix
// as a plausible instance of the same "never routed into declExports" gap.

export type Box<T> = {
value: T;
};

export type Pair<A, B> = {
first: A;
second: B;
};
}
12 changes: 12 additions & 0 deletions tslang/test/tester/tests/import_type_alias_generic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './export_type_alias_generic'

function main() {
const b: M.Box<number> = { value: 42 };
assert(b.value == 42);

const p: M.Pair<number, string> = { first: 1, second: "one" };
assert(p.first == 1);
assert(p.second == "one");

print("done.");
}
Loading