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

Create shared WellKnownTypes enum #2692

Merged
merged 9 commits into from
Mar 18, 2022

Conversation

jtschuster
Copy link
Member

Create an enum in the shared project for well known types to simplify type checking, avoid using string comparisons when possible, and avoid dereferencing null properties in Roslyn APIs.

Copy link
Contributor

@tlakollo tlakollo left a comment

Choose a reason for hiding this comment

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

Looks good to me

src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs Outdated Show resolved Hide resolved
src/linker/Linker/TypeReferenceExtensions.cs Outdated Show resolved Hide resolved
Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

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

Looks good - I'd like to employ the MetadataType as well, but that can be done in a subsequent change.

Comment on lines +364 to +365
var (@namespace, name) = type.GetNamespaceAndName ();
return tr.IsTypeOf (@namespace, name);
Copy link
Member

Choose a reason for hiding this comment

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

Cecil has a similar concept to SpecialType - it's called MetadataType and through it one can detect primitive types (and couple of other cases) faster than string compares.

For example

if ((parameters.Count == 3 && parameters[2].ParameterType.MetadataType == MetadataType.Boolean && methodParams[2].AsConstInt () != 0) ||
does a boolean check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good to know, I'll add that in a new PR. Thanks!

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.

4 participants