Skip to content

Fix cross-module generic interface export and add coverage#286

Merged
ASDAlexander77 merged 2 commits into
mainfrom
fix/generic-interface-cross-module-export
Jul 23, 2026
Merged

Fix cross-module generic interface export and add coverage#286
ASDAlexander77 merged 2 commits into
mainfrom
fix/generic-interface-cross-module-export

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

  • decls-cross-module-declaration-mechanism / generic-function-cross-module-export-fix flagged GenericInterfaceInfo as structurally analogous to GenericClassInfo/GenericFunctionInfo, and a plausible, unverified instance of the same "never routed into declExports" gap (Fix cross-module generic class export/import (4 co-operating bugs) #280, Fix cross-module generic function export and add coverage #285). Confirmed for interfaces: -shared cross-module use of a generic interface failed name resolution entirely (can't resolve name: M).
  • Added addGenericInterfaceDeclarationToExport, mirroring addGenericClassDeclarationToExport/addGenericFunctionDeclarationToExport: re-prints the bare generic interface's full original source (type params and member signatures intact, no @dllimport marker) into the __decls_generic_* embedded declaration global. Wired into registerGenericInterface at both the initial-registration site and the "already registered" early-return path (needed because registration happens during Stages::Discovering, before isAddedToExport's stage gate does anything).
  • Unlike the class/function cases, no export-bleed suppression was needed. mlirGen(InterfaceDeclaration) does call addInterfaceDeclarationToExport for a concrete instantiation (reusing the same AST node's export modifier - same shape of bug that hit classes/functions), but interfaces don't carry a linker-visible dllexport symbol the way a class/function's compiled body does. Confirmed via dumpbin /directives on the built object: no /EXPORT: entry for either a single- or multi-type-param interface instantiation (Box<number>, Pair<number,string>), only the harmless __decls_generic_* marker. No lld crash, so no fix needed for that half.

Test plan

  • New export_interface_generic.ts / import_interface_generic.ts cross-module pair (single- and two-type-param generic interfaces, used via implements and as a variable type annotation), 3 tiers: test-compile-export-import-interface-generic, test-compile-shared-export-import-interface-generic, test-jit-shared-export-import-interface-generic
  • Full suite: ctest -C Debug -j8 — 802/802 green (799 previously green + 3 new)

🤖 Generated with Claude Code

ASDAlexander77 added a commit that referenced this pull request Jul 23, 2026
Last remaining item from decls-cross-module-declaration-mechanism.md's
unverified list (after generic classes/PR #280, generic functions/PR
#285, generic interfaces/PR #286): genericTypeAliasMap's registration
path in mlirGen(TypeAliasDeclaration) never called any export function
for the generic branch - only the non-generic else-branch calls
addTypeDeclarationToExport. Confirmed with a cross-module repro: a
generic type alias failed cross-module resolution under -shared.

Unlike the other three generic declaration kinds, there is no
dedicated GenericTypeAliasInfo struct tracking sourceFile/
elementNamespace for a generic type alias - genericTypeAliasMap's
value is just {typeParams, typeNode}, since resolution
(getTypeByTypeReference / resolveGenericTypeInNamespace) is pure
compile-time type substitution on the stored TypeNode, never
re-invoking mlirGen on the whole declaration the way a class/function/
interface instantiation does. So instead of adding a new Info struct,
addGenericTypeAliasDeclarationToExport takes the AST node and
namespace directly and is called inline from the one registration
site, gated on `stage == Stages::SourceGeneration` (a given top-level
TypeAliasDeclaration is visited exactly once per stage, so this is
sufficient dedup - no "already registered" early-return branch exists
here to retry from, unlike the class/function/interface fixes).

Tested with both a single- and two-type-param alias (Box<T>,
Pair<A,B>) to check for the classes/functions' export-bleed-on-
instantiation bug; neither triggered it, matching generic interfaces'
outcome - a type alias has no compiled body or runtime entity at all,
so there's nothing for an instantiation to wrongly dllexport in the
first place. All 3 tiers passed on the first attempt, no follow-up fix
needed - the simplest of the four generic-declaration-kind fixes.

New export_type_alias_generic.ts/import_type_alias_generic.ts
cross-module test pair (compile, -shared compile, -jit -shared tiers).
802/802 green. This closes out the generic cross-module export arc.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Resolves conflicts with #285 (generic functions) and #287 (generic
type aliases), both merged in the meantime: all three PRs added a new
addGenericXDeclarationToExport function at the same insertion point in
MLIRGenImpl.h, and a matching add_test entry at the same anchor lines
in CMakeLists.txt. Kept all four functions
(class/function/interface/type-alias) and all test entries side by
side.

Full suite re-verified after merge: 808/808 green.
@ASDAlexander77
ASDAlexander77 merged commit 4949eac into main Jul 23, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix/generic-interface-cross-module-export branch July 23, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant