Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeName parsing API #100094

Merged
merged 52 commits into from Apr 24, 2024
Merged

TypeName parsing API #100094

merged 52 commits into from Apr 24, 2024

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Mar 21, 2024

fixes #97566
fixes #100867

- allow ignoring errors (return null)
- assembly name parsing
- report errorIndex in the ex message
- fix Full Framework build
- fix nested types support
- implement NativeAOT part
… methods, move "allowFullyQualifiedName" to Options bag
…me and they are consistent with Sytem.Type APIs
… in test project and cover with tests, fix edge case bugs
{
Debug.Assert(genericArgs.Length > 0);

ValueStringBuilder result = new(stackalloc char[128]);
Copy link
Member

Choose a reason for hiding this comment

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

This can be made more efficient by creating one top level ValueStringBuilder instead of creating ValueStringBuilder at each level of the generic type recursion.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. But after I've addressed #100094 (comment) FullName is very unlikely to be used for generic types. Since it should be rare I am not going to implement it for now.

adamsitnik and others added 2 commits April 24, 2024 16:26
- don't throw TypeLoadException in the parser, let loader do that
- add Debug.Assert(typeName.IsSimple) for clarity
- always include invalid character index in the error message
- remove resources added to CoreLib (they are never going to be used)
- use [DoesNotReturn] and implement proper throw helper pattern
- remove outdated comment about name validation
- AssemblyNameInfo.Flags should return the exact value provided in ctor
- don't allocate FullName until it's really needed
- refactor Make and Resovle methods into one method
- fix the test: specify namespace to make sure the type loader loads System.Int32 and later throws TypeLoadException for byref to byref
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@jeffhandley
Copy link
Member

/backport to release/9.0-preview4

Copy link
Contributor

Started backporting to release/9.0-preview4: https://github.com/dotnet/runtime/actions/runs/8823414508

Copy link
Contributor

@jeffhandley backporting to release/9.0-preview4 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: TypeNameParser first ref and configurable input validation
Applying: assembly name parsing
Applying: initial generic type info parsing
Applying: decorator parsing
Applying: Handle single dimensional array indexing
Applying: implement TypeName.GetType
Applying: nested types support
Applying: support ignore case
Applying: integrate with System.Private.CoreLib:
Using index info to reconstruct a base tree...
M	src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
M	src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
Falling back to patching base and 3-way merge...
Removing src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeNameParser.cs
Auto-merging src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
Auto-merging src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
Applying: integrate with System.Private.CoreLib:
Using index info to reconstruct a base tree...
M	src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
M	src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
Removing src/coreclr/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs
Auto-merging src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
Applying: integrate with System.Private.CoreLib for Mono and clr tools, improve perf
Applying: build fix 1/n
Applying: make TypeNameParser internal, extend TypeName with Parse and TryParse methods, move "allowFullyQualifiedName" to Options bag
Applying: introduce TotalComplexity
Applying: introduce FullName, so we have Name, FullName and AssemblyQualifiedName and they are consistent with Sytem.Type APIs
Applying: back tick error handling
Applying: move helper methods to a standalone helper type, include it as a link in test project and cover with tests, fix edge case bugs
Applying: increase test coverage, improve edge case handling
Applying: sample SerializationBinder that uses the new APIs
Applying: cover more serialization binder scenarios with the tests to ensure the API is complete
Applying: strict mode parsing: type names
Applying: strict mode parsing: assembly names
Applying: fix the build and apply some design changes
Applying: add escaping support
Applying: fix the last failing tests, increase test coverage, fix the perf, fix the build
Applying: apply changes based on the 1st API Design Review
Applying: apply changes based on the final API Design Review
Applying: solve the TODOs
Using index info to reconstruct a base tree...
M	src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
CONFLICT (content): Merge conflict in src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0028 solve the TODOs
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@jeffhandley an error occurred while backporting to release/9.0-preview4, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

@jeffhandley
Copy link
Member

We're holding off on the backport for now. We may decide to proceed with it on Thursday though.

@JulieLeeMSFT
Copy link
Member

@adamsitnik, as @TIHan mentioned, we have widespread test failures which seem to happen after this PR. Could you please take a quick look? CC @jeffhandley.

matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@LoopedBard3
Copy link
Member

LoopedBard3 commented May 2, 2024

Likely caused improvements:
Linux arm64: dotnet/perf-autofiling-issues#33683

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.

[API Proposal]: New AssemblyName-like type for TypeName parsing TypeNameParser API
8 participants