Skip to content

feat(metadata): preserve generic array shape in TypeInfo and retire constructor array recovery - #7901

Merged
thomhurst merged 1 commit into
mainfrom
feat/issue-7615-array-typeinfo
Nov 29, 2026
Merged

thomhurst merged 1 commit into
mainfrom
feat/issue-7615-array-typeinfo

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Closes #7615.

Summary

Generic array parameters (T[], T[,], T[][], List<T[]>) now carry their full shape in TypeInfo in both modes, and constructor-row filtering reads that shape directly instead of recovering it through ParameterInfo.

Most of the generator side was already on main: since #7663 GenerateTypeInfo emits ArrayType(element, rank) rather than ConcreteType(typeof(object)). This PR fills the remaining gaps.

Changes

  • ArrayType (additive): adds an IsVector init property that tells T[] apart from a rank-one multidimensional T[*]. It defaults to true for rank 1 and is always false for higher ranks. Also adds a ToString() override (T[], T[*], T[,]). The existing type and constructor are unchanged.
  • Generator: emits { IsVector = false } only for a rank-one non-SZ array. C# source cannot declare one, so no snapshots change.
  • Reflection: a new internal TypeInfoDescriber describes open types the same way the generator does: GenericParameter, ArrayType and ConstructedGeneric for open types, ConcreteType for closed ones. TUnit.Engine's ParameterMetadataFactory uses it, so a parameter whose type is still open gets the same description in both modes. Closed parameter types still produce ConcreteType, so nothing changes for closed instantiations or closed generic methods. That includes TestBuilder.IsDataCompatibleWithExpectedTypes, which only runs with closed metadata.
  • GenericClassRowPartition: removes the private ConstructorArray record, GetConstructorTypeInfo / HasErasedArray / DescribeConstructorType and their ConditionalWeakTable cache. Matching now uses ArrayType directly. The two duplicated local Substitute helpers now call TypeInfoDescriber.Describe(type, substitutions). Variance, nullable unwrapping, CLR array element reduction and the trailing/params rules are unchanged. One fix along the way: GetWholeTupleParameter only treats a vector as a trailing array, where before it accepted any ArrayType.
  • Shape comparers: MetadataExtensions.MatchesTypeInfo and MetadataDependencyExpander.SameTypeInfo now also compare IsVector.
  • Recovery fallback removed: generator and runtime ship in the same package, so the old fallback for T[] erased to object is no longer needed. One effect: generated ArrayType metadata without reflection info used to fail to match, and now matches.

Public API

Additive only, in TUnit.Core, on all three snapshots:

+        public bool IsVector { get; init; }
+        public override string ToString() { }

The Net4_7 snapshot was edited by hand with the same two lines because it is Windows-only; CI checks it.

Validation

  • tests/TUnit.UnitTests (net10.0): 1290 total, 0 failed. GenericClassSourceRuntimeTests were updated from the old erased-object shapes to what the generator actually emits. New coverage:
    • generated metadata without reflection info
    • reflection TypeInfoDescriber matches the generated shapes
    • vector vs T[*] (equality, ToString, and filtering)
    • method generic arrays
  • tests/TUnit.Core.SourceGenerator.Tests (net10.0): 431 total, 0 failed, no snapshot changes.
  • tests/TUnit.PublicAPI (net10.0, net11.0): pass after the additive update.
  • tests/TUnit.TestProject, net10.0, source-gen and --reflection, namespaces Bugs._7118/7573/7596/7223/7883/7208/7209/7399/7366/7099/7108/7639/7638/7520: in each run, the set of failing tests matches unmodified main exactly. Those failures are intentional.
  • Native AOT: dotnet publish -c Release -p:Aot=true --use-current-runtime -f net10.0 of TestProject succeeds, with no trim/AOT warnings in the changed code. The AOT binary gives the same results as JIT on _7883, _7223, _7099 and _7573.
  • TUnit.Engine.Tests was not run locally, per repository guidance.

Not changed

  • MethodMetadata.TypeInfo / ReturnTypeInfo and ClassMetadata.TypeInfo in reflection mode stay ConcreteType. ConstructedGeneric record equality compares its argument array by reference, so a structural description there could change metadata equality.
  • ReflectionTestDataCollector.cs:3271 still builds ConcreteType directly. That file is being changed concurrently.
  • The hot-path measurement follow-ups from the issue comments are not part of this PR.

Summary by CodeRabbit

  • Bug Fixes
    • Improved matching of generic array types, including distinctions between vectors and rank-one non-vector arrays.
    • Made array metadata handling more consistent across generated tests and runtime checks, including array rank, nesting, and element compatibility.

…structor array recovery (#7615)

ArrayType gains an additive IsVector property (T[] vs rank-one T[*]) and a
ToString. The source generator emits it, reflection describes open parameter
types with the same shapes through a shared internal TypeInfoDescriber, and
GenericClassRowPartition matches ArrayType directly, retiring its private
ConstructorArray recovery through ParameterInfo.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T19:21:09.245476Z 62d9cfa PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds vector-shape information to array metadata and introduces shared runtime type descriptions for generic-containing arrays. Constructor matching and metadata comparisons use array rank and vector shape. Tests cover generated and reflected metadata.

Changes: Generic array shape metadata

Layer / File(s) Summary
Describe array shapes
src/TUnit.Core/TypeInfo.cs, src/TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs, src/TUnit.Engine/Building/ParameterMetadataFactory.cs, tests/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.*.verified.txt
ArrayType records whether a rank-one array is a vector, and its string representation distinguishes T[] from T[*]. TypeInfoDescriber describes arrays and constructed generic types. The source generator and parameter metadata factory use structural descriptions.
Match constructor array shapes
src/TUnit.Core/Attributes/TestData/GenericClassRowPartition.cs
Constructor matching uses shared type descriptions and checks array rank and vector shape. It removes local reflection recovery and substitution helpers.
Compare and test array shapes
src/TUnit.Core/Extensions/MetadataExtensions.cs, src/TUnit.Engine/Services/MetadataDependencyExpander.cs, tests/TUnit.UnitTests/GenericClassSourceRuntimeTests.cs
Metadata matching and equality compare vector shape. Tests cover structural array descriptions and constructor filtering across generated, reflection-free, and reflected metadata.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • Issue 7596: The issue describes constructor-array filtering when generated metadata loses generic array shape. This change updates generated array descriptions and constructor matching.

Possibly related PRs

  • thomhurst/TUnit#7599: This PR removes the constructor type recovery added by #7599 and matches shared ArrayType descriptions directly.
Merge Risk: Minimal · up to 62d9c

The change preserves array shape (vector versus non-vector, and rank) in generic type metadata and uses it for constructor row matching. No merge-blocking risk was found. The additive public API change is limited to a new property and a ToString override.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive [#7615] The issue asks for preserved element, rank and vector shape for generic arrays, equivalent generated and reflection metadata, constructor filtering parity, additive API only, tests, and Native… Provide readable source for src/TUnit.Core/Attributes/TestData/GenericClassRowPartition.cs and src/TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs at the reviewed head, so the constructor-filter and generator behavior can be checked aga…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: generic array shape is now preserved in TypeInfo, and constructor array recovery is removed. The changeset adds ArrayType.IsVector, the TypeInfoDescriber, and the remo…
Out of Scope Changes check Passed The verified changes in src/TUnit.Core/TypeInfo.cs (ArrayType.IsVector, ToString, TypeInfoDescriber) implement [#7615]. The reported changes also fall within the same objective: the generator IsVector…
Full details: Title check

Explanation

The title names the main change: generic array shape is now preserved in TypeInfo, and constructor array recovery is removed. The changeset adds ArrayType.IsVector, the TypeInfoDescriber, and the removal of the recovery helpers in GenericClassRowPartition. The title uses a conventional commit prefix, which is acceptable. It is specific enough for a teammate scanning history.

Full details: Out of Scope Changes check

Explanation

The verified changes in src/TUnit.Core/TypeInfo.cs (ArrayType.IsVector, ToString, TypeInfoDescriber) implement [#7615]. The reported changes also fall within the same objective: the generator IsVector emission, MetadataExtensions.MatchesTypeInfo and MetadataDependencyExpander.SameTypeInfo shape comparisons, ParameterMetadataFactory using TypeInfoDescriber, additive PublicAPI snapshot lines, and the GenericClassSourceRuntimeTests updates. Removing the private recovery helpers in GenericClassRowPartition is the replacement step that [#7615] describes. No change was found that is unrelated to the linked issue. The GenericClassRowPartition and generator diffs were not readable, so this verdict rests on the summaries for those files.

Full details: Linked Issues check

Explanation

[#7615] The issue asks for preserved element, rank and vector shape for generic arrays, equivalent generated and reflection metadata, constructor filtering parity, additive API only, tests, and Native AOT verification. Verified at the reviewed head in src/TUnit.Core/TypeInfo.cs: ArrayType gains an additive IsVector init property and a ToString override, and TypeInfoDescriber describes open types structurally (GenericParameter, ArrayType, ConstructedGeneric) while closed types stay ConcreteType. The generator change (CodeGenerationHelpers.cs, rank-one non-SZ arrays only) is described in the summary but its diff was not readable. The constructor-filter change in GenericClassRowPartition.cs could not be read: the diff call returned that the changed blobs are missing from the checkout. Its described behavior (private recovery removed, ArrayType matched directly, IsVector checked in GetWholeTupleParameter) rests on the AI summary and PR description only. The test, public API snapshot, and Native AOT results are author-reported; no test run or publish was performed in this review.

Resolution

Provide readable source for src/TUnit.Core/Attributes/TestData/GenericClassRowPartition.cs and src/TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs at the reviewed head, so the constructor-filter and generator behavior can be checked against the acceptance criteria. Confirm the TUnit.UnitTests, source generator snapshot, PublicAPI, and Native AOT results from CI or a re-run before a final verdict.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each bracketed type,
And marks the vectors with care.
Rank and shape now stay in view,
Through generated paths and reflected too.
Then hops away through fields of hare.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 642c5cdc-f204-4d3b-97c9-a39452a62ee3
Commits

Reviewing files that changed from the base of the PR and between 163db63 and 62d9cfa.

Files selected for processing: 10

  • src/TUnit.Core.SourceGenerator/CodeGenerationHelpers.cs
  • src/TUnit.Core/Attributes/TestData/GenericClassRowPartition.cs
  • src/TUnit.Core/Extensions/MetadataExtensions.cs
  • src/TUnit.Core/TypeInfo.cs
  • src/TUnit.Engine/Building/ParameterMetadataFactory.cs
  • src/TUnit.Engine/Services/MetadataDependencyExpander.cs
  • tests/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet10_0.verified.txt
  • tests/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet11_0.verified.txt
  • tests/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.Net4_7.verified.txt
  • tests/TUnit.UnitTests/GenericClassSourceRuntimeTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Preserves open generic array shapes in reflection metadata and lets constructor-row filtering read ArrayType directly.

  • Open generic array descriptions preserve their full shape.
  • Constructor rows match directly against generic parameter shapes.

Acknowledged scope from thomhurst: older-generator recovery is intentionally removed because the generator and runtime ship together. The separate ConcreteType construction in ReflectionTestDataCollector.cs and hot-path measurements are deferred.

Reviews (1) · Last reviewed commit: "feat(metadata): preserve generic array s..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Review of #7901

I read the diff and found no blocking issues. I did not build the PR or run its tests.

What looks good

  • It removes the ConstructorArray shadow type, the ConditionalWeakTable cache and the two duplicated Substitute helpers. All of that is replaced by one TypeInfoDescriber.
  • The generator and the reflection path now describe open types the same way.
  • IsVector is additive and defaults to true for rank 1. The generator only emits IsVector = false for the rank-one non-SZ case, so no generator snapshots change.
  • IsVector is also compared in MatchesTypeInfo and SameTypeInfo, and TypeInfoDescriber.IsVector uses IsSZArray on .NET instead of the name-suffix check.
  • Describe closes no generic types, so it should be fine for Native AOT.

Minor points

  1. ArrayType now carries a private backing field (_isRankOneMultiDimensional) next to the record's primary-constructor properties. Record equality includes private fields. That is consistent today, but a with { Rank = ... } copy after IsVector = false would keep the stale flag when the rank changes to 1 or more. Rank is not mutated that way in practice. A unit test that pins down equality, with behaviour and ToString for T[], T[*] and T[,] would guard it.
  2. ParameterMetadataFactory now returns GenericParameter, ArrayType or ConstructedGeneric for open parameter types. Before, it returned ConcreteType(openType). I grepped src for code that casts TypeInfo to ConcreteType and found none outside GenericClassRowPartition. Still, check consumers such as method-level generic inference against open-typed reflection metadata. CI covers this, as it exercises both modes.
  3. The Net4_7 snapshot was edited by hand. CI will confirm it matches.

Overall this is a sensible consolidation. Approve once CI is green.

@thomhurst
thomhurst merged commit a716f09 into main Nov 29, 2026
28 checks passed
@thomhurst
thomhurst deleted the feat/issue-7615-array-typeinfo branch November 29, 2026 22:21
This was referenced Dec 1, 2026

This branch was previously deployed

1 inactive deployment
Pull Requests — 62d9cfac Deployed Nov 29, 2026 by thomhurst via modularpipeline (ubuntu-latest) #21911
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.

Preserve generic array shape in generated TypeInfo metadata

1 participant