-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Proper type name parser for native AOT compiler #83657
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e33895c
Proper type name parser for native AOT compiler
jkotas efae78e
Fix one more TODO
jkotas bf35fdd
Fix some of the test failures
vitek-karas 7bebd88
Track failure of CA search rules in the type name parser
jkotas 04d3154
Fix test build breaks
jkotas b85048f
Fix test
jkotas f6f582d
Better match the current illink behavior
jkotas cd2c376
Supress new native AOT warning for libraries tests
jkotas 24fd6c1
Merge branch 'main' into typename-parser-nativeaot
jkotas af3eca6
Fix one more test
jkotas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 0 additions & 99 deletions
99
.../tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectionMethodBodyScanner.cs
This file was deleted.
Oops, something went wrong.
151 changes: 151 additions & 0 deletions
151
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeNameParser.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Reflection; | ||
|
|
||
| using Internal.TypeSystem; | ||
|
|
||
| namespace System.Reflection | ||
| { | ||
| internal unsafe ref partial struct TypeNameParser | ||
| { | ||
| private TypeSystemContext _context; | ||
| private ModuleDesc _callingModule; | ||
| private List<ModuleDesc> _referencedModules; | ||
| private bool _typeWasNotFoundInAssemblyNorBaseLibrary; | ||
|
|
||
| public static TypeDesc ResolveType(string name, ModuleDesc callingModule, | ||
| TypeSystemContext context, List<ModuleDesc> referencedModules, out bool typeWasNotFoundInAssemblyNorBaseLibrary) | ||
| { | ||
| var parser = new System.Reflection.TypeNameParser(name) | ||
| { | ||
| _context = context, | ||
| _callingModule = callingModule, | ||
| _referencedModules = referencedModules | ||
| }; | ||
|
|
||
| TypeDesc result = parser.Parse()?.Value; | ||
|
|
||
| typeWasNotFoundInAssemblyNorBaseLibrary = parser._typeWasNotFoundInAssemblyNorBaseLibrary; | ||
| return result; | ||
| } | ||
|
|
||
| private sealed class Type | ||
| { | ||
| public Type(TypeDesc type) => Value = type; | ||
| public TypeDesc Value { get; } | ||
|
|
||
| public Type MakeArrayType() => new Type(Value.MakeArrayType()); | ||
| public Type MakeArrayType(int rank) => new Type(Value.MakeArrayType(rank)); | ||
| public Type MakePointerType() => new Type(Value.MakePointerType()); | ||
| public Type MakeByRefType() => new Type(Value.MakeByRefType()); | ||
|
|
||
| public Type MakeGenericType(Type[] typeArguments) | ||
| { | ||
| TypeDesc[] instantiation = new TypeDesc[typeArguments.Length]; | ||
| for (int i = 0; i < typeArguments.Length; i++) | ||
| instantiation[i] = typeArguments[i].Value; | ||
| return new Type(((MetadataType)Value).MakeInstantiatedType(instantiation)); | ||
| } | ||
| } | ||
|
|
||
| private static bool CheckTopLevelAssemblyQualifiedName() => true; | ||
|
|
||
| private Type GetType(string typeName, ReadOnlySpan<string> nestedTypeNames, string assemblyNameIfAny) | ||
| { | ||
| ModuleDesc module; | ||
|
|
||
| if (assemblyNameIfAny != null) | ||
| { | ||
| module = (TryParseAssemblyName(assemblyNameIfAny) is AssemblyName an) ? | ||
| _context.ResolveAssembly(an, throwIfNotFound: false) : null; | ||
| } | ||
| else | ||
| { | ||
| module = _callingModule; | ||
| } | ||
|
|
||
| Type type; | ||
|
|
||
| if (module != null) | ||
| { | ||
| type = GetTypeCore(module, typeName, nestedTypeNames); | ||
| if (type != null) | ||
| { | ||
| _referencedModules?.Add(module); | ||
| return type; | ||
| } | ||
| } | ||
|
|
||
| // If it didn't resolve and wasn't assembly-qualified, we also try core library | ||
| if (assemblyNameIfAny == null) | ||
| { | ||
| type = GetTypeCore(_context.SystemModule, typeName, nestedTypeNames); | ||
| if (type != null) | ||
| { | ||
| _referencedModules?.Add(_context.SystemModule); | ||
| return type; | ||
| } | ||
|
|
||
| _typeWasNotFoundInAssemblyNorBaseLibrary = true; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| private static AssemblyName TryParseAssemblyName(string assemblyName) | ||
| { | ||
| try | ||
| { | ||
| return new AssemblyName(assemblyName); | ||
| } | ||
| catch (FileLoadException) | ||
| { | ||
| return null; | ||
| } | ||
| catch (ArgumentException) | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static Type GetTypeCore(ModuleDesc module, string typeName, ReadOnlySpan<string> nestedTypeNames) | ||
| { | ||
| string typeNamespace, name; | ||
|
|
||
| int separator = typeName.LastIndexOf('.'); | ||
| if (separator <= 0) | ||
| { | ||
| typeNamespace = ""; | ||
| name = typeName; | ||
| } | ||
| else | ||
| { | ||
| if (typeName[separator - 1] == '.') | ||
| separator--; | ||
| typeNamespace = typeName.Substring(0, separator); | ||
| name = typeName.Substring(separator + 1); | ||
| } | ||
|
|
||
| MetadataType type = module.GetType(typeNamespace, name, throwIfNotFound: false); | ||
| if (type == null) | ||
| return null; | ||
|
|
||
| for (int i = 0; i < nestedTypeNames.Length; i++) | ||
| { | ||
| type = type.GetNestedType(nestedTypeNames[i]); | ||
| if (type == null) | ||
| return null; | ||
| } | ||
|
|
||
| return new Type(type); | ||
| } | ||
|
|
||
| private static void ParseError() | ||
| { | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.