Fix cross-module generic function export and add coverage#285
Merged
Conversation
This was referenced Jul 23, 2026
ASDAlexander77
added a commit
that referenced
this pull request
Jul 23, 2026
Resolves conflict with #285 (generic function export fix, merged in the meantime): both PRs added a new add_test entry for their respective generic-declaration-kind test pair at the same anchor lines in CMakeLists.txt. Kept both sets of entries side by side. MLIRGenImpl.h auto-merged cleanly - the two addGenericXDeclarationToExport functions (function/type-alias) sit at different insertion points. Full suite re-verified after merge: 805/805 green.
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>
ASDAlexander77
added a commit
that referenced
this pull request
Jul 23, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GenericFunctionInfoas structurally analogous toGenericClassInfo, and a plausible, unverified instance of the "never routed intodeclExports" gap that took 4 fixes to close for generic classes (Fix cross-module generic class export/import (4 co-operating bugs) #280). Confirmed for functions and fixed with the same two-part approach:addGenericFunctionDeclarationToExport(mirroringaddGenericClassDeclarationToExport) - re-prints the bare generic function's full original source (type params and body intact, no@dllimportmarker) into the__decls_generic_*embedded declaration global, since - like a generic class - it has no compiled body for any given instantiation todllimportagainst. Wired intoregisterGenericFunctionLikeat both the initial-registration site and the "already registered" early-return path (needed because registration happens duringStages::Discovering, beforeisAddedToExport's stage gate does anything - the export retry has to fire again duringStages::SourceGeneration).identity<number>,pair<number,string>) reprocesses the SAME AST node as the bare template, soprocessFunctionAttributes'sgetExportModifiercheck marked the LOCAL, per-instantiation specialization as exported too - harmless for single-type-param instantiations, but a hard lldinvalid /export:error for multi-param ones, since the mangled name's raw comma is a linker-directive metacharacter. Exact function analog of the class-generic fix'sisExport=falsesuppression - added asuppressExportparameter toprocessFunctionAttributes(has to be suppressed inside that function, before it pushes the"export"attribute intoattrs- overriding the returned bool afterward does nothing).Test plan
export_function_generic.ts/import_function_generic.tscross-module pair (single- and multi-type-param generic functions), 3 tiers:test-compile-export-import-function-generic,test-compile-shared-export-import-function-generic,test-jit-shared-export-import-function-genericctest -C Debug -j8— 802/802 green (799 previously green + 3 new)🤖 Generated with Claude Code