Skip to content

[cdac] Move DataType from Abstractions to Contracts#128119

Open
max-charlamb wants to merge 1 commit into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/cdac-datatype-move
Open

[cdac] Move DataType from Abstractions to Contracts#128119
max-charlamb wants to merge 1 commit into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/cdac-datatype-move

Conversation

@max-charlamb
Copy link
Copy Markdown
Member

@max-charlamb max-charlamb commented May 13, 2026

Moves the DataType enum out of the Abstractions assembly into Contracts, since it represents descriptor schema rather than the abstract Target API. Each user of the DataContractReader.Abstractions can define their own DataType schema.

Changes

  • DataType.cs moved from Microsoft.Diagnostics.DataContractReader.Abstractions to Microsoft.Diagnostics.DataContractReader.Contracts.
  • Target.GetTypeInfo(DataType) replaced with abstract Target.GetTypeInfo(string typeName).
  • Added extension method DataTypeTargetExtensions.GetTypeInfo(this Target, DataType) in DataType.cs for ergonomics; it forwards to the string overload via .ToString().
  • Removed Target.FieldInfo.Type (the DataType field); TypeName (string) is now the sole identifier and is what consumers already used in practice.
  • ContractDescriptorTarget now stores types in a single Dictionary<string, Target.TypeInfo>.
  • TestPlaceholderTarget storage is string-keyed internally; Builder.AddTypes(Dictionary<DataType, ...>) is kept for caller convenience and converts to strings.
  • Removed unused TargetTestHelpers.SizeOfTypeInfo.

Verification

  • 2041 / 2041 unit tests pass (Microsoft.Diagnostics.DataContractReader.Tests).
  • Dump tests pending.

Note

This PR description and the underlying changes were drafted with the assistance of GitHub Copilot.

Moves the DataType enum out of the Abstractions assembly and into Contracts, since it is part of the descriptor schema rather than the abstract target API.

Target.GetTypeInfo(DataType) is replaced with a string-based abstract Target.GetTypeInfo(string) plus an extension method DataTypeTargetExtensions.GetTypeInfo(this Target, DataType) that calls .ToString(). Target.FieldInfo.Type is removed; TypeName is the sole identifier.

TestPlaceholderTarget storage is now string-keyed internally. Builder.AddTypes(Dictionary<DataType,...>) is kept for caller convenience.

Also removes the unused TargetTestHelpers.SizeOfTypeInfo helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures cDAC type metadata handling by moving the DataType enum into the Contracts assembly and switching Target.GetTypeInfo from a DataType-based API to a string-based API, with corresponding updates across ContractDescriptorTarget and the unit tests.

Changes:

  • Replaces Target.GetTypeInfo(DataType) with Target.GetTypeInfo(string typeName) and updates implementations/call sites accordingly.
  • Moves type identity from an enum-keyed cache to a string-keyed dictionary in targets and test infrastructure (builder helpers, descriptor parsing, and test setup).
  • Introduces a DataType → string forwarding extension method (DataTypeTargetExtensions.GetTypeInfo(this Target, DataType)).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/native/managed/cdac/tests/TestPlaceholderTarget.cs Switches placeholder target type cache to Dictionary<string, TypeInfo>, adds builder overload to accept Dictionary<DataType, …> and convert to strings, updates GetTypeInfo override.
src/native/managed/cdac/tests/TargetTestHelpers.cs Removes SizeOfTypeInfo helper and updates field layout helpers to populate FieldInfo.TypeName instead of FieldInfo.Type.
src/native/managed/cdac/tests/MethodDescTests.cs Updates test type-info construction to no longer set FieldInfo.Type for AsyncMethodData.Flags.
src/native/managed/cdac/tests/GCMemoryRegionTests.cs Updates test field dictionaries to set TypeName from DataType.ToString().
src/native/managed/cdac/tests/ExecutionManager/HashMapTests.cs Refactors target construction to use TestPlaceholderTarget.Builder and its string-keyed type/global setup.
src/native/managed/cdac/tests/DebuggerTests.cs Adjusts AddTypes call to disambiguate the new overload set.
src/native/managed/cdac/tests/ContractDescriptor/TargetTests.SubDescriptors.cs Removes FieldInfo.Type initialization and leaves TypeName as the identifier.
src/native/managed/cdac/tests/ContractDescriptor/TargetTests.cs Removes FieldInfo.Type initialization and leaves TypeName as the identifier.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/ContractDescriptorTarget.cs Collapses type storage to Dictionary<string, TypeInfo>, populates pointer size via "pointer" key, removes enum-parse path, and uses the new DataType extension for CodePointer lookups.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/DataType.cs Adds DataTypeTargetExtensions.GetTypeInfo(Target, DataType) convenience extension.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Target.cs Changes the abstract GetTypeInfo contract to accept a string and removes FieldInfo.Type from the public surface.
Comments suppressed due to low confidence (1)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/DataType.cs:199

  • This introduces a new public API (DataTypeTargetExtensions.GetTypeInfo(Target, DataType)) in the Contracts assembly. dotnet/runtime generally requires new public surface area to have an approved API proposal (api-approved issue) before merge; if that’s not available, consider making this helper internal (and using the string overload from other assemblies) until API review is completed.

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants