Repository navigation
feat(metadata): preserve generic array shape in TypeInfo and retire constructor array recovery - #7901
Conversation
…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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryPreserves open generic array shapes in reflection metadata and lets constructor-row filtering read
Acknowledged scope from Reviews (1) · Last reviewed commit: "feat(metadata): preserve generic array s..." · Reviewed by Greptile |
Review of #7901I read the diff and found no blocking issues. I did not build the PR or run its tests. What looks good
Minor points
Overall this is a sensible consolidation. Approve once CI is green. |
Closes #7615.
Summary
Generic array parameters (
T[],T[,],T[][],List<T[]>) now carry their full shape inTypeInfoin both modes, and constructor-row filtering reads that shape directly instead of recovering it throughParameterInfo.Most of the generator side was already on main: since #7663
GenerateTypeInfoemitsArrayType(element, rank)rather thanConcreteType(typeof(object)). This PR fills the remaining gaps.Changes
ArrayType(additive): adds anIsVectorinit property that tellsT[]apart from a rank-one multidimensionalT[*]. It defaults to true for rank 1 and is always false for higher ranks. Also adds aToString()override (T[],T[*],T[,]). The existing type and constructor are unchanged.{ IsVector = false }only for a rank-one non-SZ array. C# source cannot declare one, so no snapshots change.TypeInfoDescriberdescribes open types the same way the generator does:GenericParameter,ArrayTypeandConstructedGenericfor open types,ConcreteTypefor closed ones.TUnit.Engine'sParameterMetadataFactoryuses it, so a parameter whose type is still open gets the same description in both modes. Closed parameter types still produceConcreteType, so nothing changes for closed instantiations or closed generic methods. That includesTestBuilder.IsDataCompatibleWithExpectedTypes, which only runs with closed metadata.GenericClassRowPartition: removes the privateConstructorArrayrecord,GetConstructorTypeInfo/HasErasedArray/DescribeConstructorTypeand theirConditionalWeakTablecache. Matching now usesArrayTypedirectly. The two duplicated localSubstitutehelpers now callTypeInfoDescriber.Describe(type, substitutions). Variance, nullable unwrapping, CLR array element reduction and the trailing/params rules are unchanged. One fix along the way:GetWholeTupleParameteronly treats a vector as a trailing array, where before it accepted anyArrayType.MetadataExtensions.MatchesTypeInfoandMetadataDependencyExpander.SameTypeInfonow also compareIsVector.T[]erased toobjectis no longer needed. One effect: generatedArrayTypemetadata without reflection info used to fail to match, and now matches.Public API
Additive only, in
TUnit.Core, on all three snapshots: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.GenericClassSourceRuntimeTestswere updated from the old erased-objectshapes to what the generator actually emits. New coverage:TypeInfoDescribermatches the generated shapesT[*](equality,ToString, and filtering)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, namespacesBugs._7118/7573/7596/7223/7883/7208/7209/7399/7366/7099/7108/7639/7638/7520: in each run, the set of failing tests matches unmodifiedmainexactly. Those failures are intentional.dotnet publish -c Release -p:Aot=true --use-current-runtime -f net10.0of TestProject succeeds, with no trim/AOT warnings in the changed code. The AOT binary gives the same results as JIT on_7883,_7223,_7099and_7573.TUnit.Engine.Testswas not run locally, per repository guidance.Not changed
MethodMetadata.TypeInfo/ReturnTypeInfoandClassMetadata.TypeInfoin reflection mode stayConcreteType.ConstructedGenericrecord equality compares its argument array by reference, so a structural description there could change metadata equality.ReflectionTestDataCollector.cs:3271still buildsConcreteTypedirectly. That file is being changed concurrently.Summary by CodeRabbit