Skip to content

Migrate scalar builtin types to generated TypeDef assembly format ownership - #147

Merged
jonathanvdc merged 2 commits into
mainfrom
copilot/migrate-scalar-builtin-types
Apr 16, 2026
Merged

jonathanvdc merged 2 commits into
mainfrom
copilot/migrate-scalar-builtin-types

Conversation

Copilot AI commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Scalar builtin types (float, index, none) had split ownership: generated TypeDef classes existed and were registered, but binding still went through hand-written factory delegates and FloatTypeReference held a catch-all TypeDefinition = new("float"). This completes the migration so generated TypeDef definitions own scalar binding end-to-end via assembly formats, matching the pattern already established by IntegerType.

New assembly format classes

  • BuiltinIndexTypeAssemblyFormat — binds BuiltinIndexTypeSyntaxIndexType
  • BuiltinNoneTypeAssemblyFormat — binds BuiltinNoneTypeSyntaxNoneType
  • BuiltinScalarFloatTypeAssemblyFormat — shared format parameterized by a constructor delegate; handles all 18 float variants without per-type subclasses

Metadata-driven generation

BuiltinTypesExtensions.td now supplies csharpAssemblyFormat for all scalar float types plus Builtin_Index and Builtin_None. The generator (TypeEmitter) uses this metadata to:

  • emit assembly format instead of factory delegate
  • fix float constructors to use the MLIR mnemonic ("f32") rather than the qualified registry key ("builtin.f32")
// Before: factory-backed, wrong name in constructor
new TypeDefinition("builtin.f32", factory: static context => Float32Type.BindValue(context));
public Float32Type(...) : base(TypeDefinition.Name, ...)  // "builtin.f32" — wrong

// After: assembly-format-backed, correct mnemonic
new TypeDefinition("builtin.f32", new BuiltinScalarFloatTypeAssemblyFormat(syntax => new Float32Type(syntax)));
public Float32Type(...) : base("f32", ...)  // correct

Binder registry lookup

Binder.GetStructuredTypeDefinitionName now maps scalar syntax to "builtin.integer", "builtin.f32", "builtin.index", "builtin.none", etc., so the registry lookup resolves correctly to the generated builtin TypeDefinition.

FloatTypeReference cleanup

Removed the catch-all TypeDefinition = new("float") static property. The base class now returns null for Definition; generated subclasses override with their own TypeDefinition. Fallback-bound FloatTypeReference values (no registry) thus have Definition == null.

Test coverage

  • Updated existing registered-binding test to use the correct "builtin.integer" lookup key
  • Added tests for: registered float/index/none → generated typed subclasses with non-null Definition; fallback float → Definition == null; all generated scalar TypeDefinitions have AssemblyFormat != null; registered and fallback scalar types compare equal

Copilot AI changed the title [WIP] Migrate scalar builtin types to generated TypeDef ownership Migrate scalar builtin types to generated TypeDef assembly format ownership Apr 16, 2026
Copilot AI requested a review from jonathanvdc April 16, 2026 02:32
@jonathanvdc
jonathanvdc marked this pull request as ready for review April 16, 2026 02:34
@jonathanvdc
jonathanvdc merged commit 65fadb9 into main Apr 16, 2026
1 check passed
@jonathanvdc
jonathanvdc deleted the copilot/migrate-scalar-builtin-types branch April 16, 2026 02:35
@github-actions

Copy link
Copy Markdown

TableGen Interpreter Benchmarks

Commit: cc5dd2ea298b9679bfe3ea06f107bc85840e4bdb

Benchmark Baseline (ms) Candidate (ms) Delta Status
Evaluate.PathologicalDeepClassChain 0.028 0.028 -0.1% Flat
Evaluate.PathologicalListPipeline 0.158 0.152 -3.4% Flat
Evaluate.PreludeArithOps 9.358 8.825 -5.7% Improvement
Evaluate.PreludeMiniDialect 3.463 3.501 +1.1% Flat
Evaluate.SimpleInheritanceLets 0.002 0.002 +6.1% Regression
Evaluate.UtilsTd 0.019 0.018 -1.2% Flat
ParseAndEvaluate.PreludeArithOps 21.629 22.328 +3.2% Flat
ParseAndEvaluate.PreludeMiniDialect 9.289 9.287 0.0% Flat

Interpretation:

  • Regression means candidate mean time is more than 5% slower than baseline.
  • Improvement means candidate mean time is more than 5% faster than baseline.
  • Flat means the change stayed within a 5% noise band.

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.

Migrate scalar builtin types to generated TypeDef ownership

2 participants