Remove std::function churn and wasted arena interning in MLIRGen#203
Merged
Conversation
- Rewrite the three StringSwitch<std::function> utility-type tables (getEmbeddedTypeWithParam*/ManyParams) as enum dispatch; the old form constructed every case closure eagerly on each call - Replace all std::bind sites with lambdas or member-function pointers - Add concatFullNamespaceName() (no interning) and use it where the full name is transient (getNameOfFunction, enum type refs, dynamic import names); getFullNamespaceName keeps interning for stored names Review doc item A4. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 11, 2026
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
Implements item A4 (allocation hot spots) from
docs/MLIRGen-refactoring-review.md:getEmbeddedTypeWithParamBuiltins/...NoBuiltins/...ManyParamsBuiltinsusedllvm::StringSwitch<std::function<...>>, which constructs every case's closure eagerly on each call (~17std::functions pergetTypeof a builtin utility type). Rewritten asStringSwitch<enum>+ a plainswitch— allocation-free, and the shared "evaluate first type argument" prologue is now hoisted once. Behavior notes: cases that previously returned a possibly-null type without checking (Readonly/Partial/Required/ThisType) are unchanged in effect, since returning a nullmlir::Typeequals returningmlir::Type(); the NoBuiltins variant deliberately keeps no null check, matching the original.std::bindelimination (18 sites → 0). The four verbatim 5-placeholdercastbinds became one explicit lambda; the twoanyOrUndefined/optionalValueOrUndefinedternaries became member-function-pointer selection (identical signatures) invoked viathis->*; the constructor's fourMLIRTypeHelpercallbacks and thegetGlobalsFullNamespaceNamebind became lambdas.getFullNamespaceName(name)permanently interned its result into the never-freedBumpPtrAllocatoron every call. NewconcatFullNamespaceName()builds the name without interning and is used where the result is transient —getNameOfFunction(which immediately called.str()), the two enumFlatSymbolRefAttrsites (MLIR interns into the context anyway), and the dynamic-import symbol name. Registration paths keep interning.Test plan
tslangrebuilt cleanly (vs2026 debug)Uppercase,Capitalize,Pick,Record,Readonly,ReturnType,Exclude), spread-into-fixed-params (member-pointervalueFactorypath),Array.push(cast-lambda path), enums and namespaced functions (concatFullNamespaceNamepaths) — JIT output5 1 / ABC Hello 1 x 3 true c / 6 / 42, all as expected42 15 42 3 1and5 21 7 xMLIRGenTests.exe: 12/12 pass🤖 Generated with Claude Code