Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Share GetConstructor intrinsic a lot of small fixes - #2725

Merged
vitek-karas merged 5 commits into
dotnet:mainfrom
vitek-karas:GetConstructorShare
Apr 6, 2022
Merged

vitek-karas merged 5 commits into
dotnet:mainfrom
vitek-karas:GetConstructorShare

Conversation

@vitek-karas

Copy link
Copy Markdown
Member

The main change is sharing of the GetConstructor intrinsic and related tests.
To make those tests work this also implements Type.EmptyTypes and String.Empty and Array.Empty intrinsics.
These are all treated as special cases:

  • Type.EmptyTypes and String.Empty are actually field accesses, so we don't have infra to share these yet, no need to add one for now
  • Array.Empty is a generic method where we need to know the generic instantiation. The current sharing doesn't propagate this information
    so this forced the implementation to NOT be shared but instead done as a fallback which the shared one doesn't handle.

The rest of the changes are all about fixing how the shared intrinsic handling propagates return value from intrinsics.
Lot of small subtle bugs around null or emtpy inputs and forgetting to add return value and so on. The main changes are in GetMethod and GetNestedType intrinsics which had lot of issues.

Added tests for all of the corner cases.
NestedTypesUsedViaReflection test has been reworked as previously it didn't work correctly. Lot of the [Kept] attributes were fulfilled by some of the negative tests and thus the positive tests didn't have coverage (for example calling GetNestedType(unknownName) will mark all nested types on the type, so a subsequent call to GetNestedType("knownname") will not have an observable effect).


// Go over all types we've seen
foreach (var value in instanceValue) {
if (value is SystemTypeValue systemTypeValue && !BindingFlagsAreUnsupported (bindingFlags)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this also need handling for null/empty inputs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not really - we could add it, but it's not necessary. We need special handling only for intrinsics which set return value, those which don't can have empty foreach loops, it doesn't cause a problem.

Not sure what's better - be consistent with unnecessary lines of code, or keep it shorter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh right, the difference is that it doesn't have a return value. My preference is consistency, but either way is fine.

// GetMethod (string, int, BindingFlags, Binder?, CallingConventions, Type[], ParameterModifier[]?)
//
case IntrinsicId.Type_GetMethod: {
if (instanceValue.IsEmpty () || argumentValues[0].IsEmpty ()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for the null/empty handling cleanup in this PR!

@vitek-karas
vitek-karas merged commit e8b0ba0 into dotnet:main Apr 6, 2022
@vitek-karas
vitek-karas deleted the GetConstructorShare branch April 6, 2022 20:04
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
The main change is sharing of the GetConstructor intrinsic and related tests.
To make those tests work this also implements Type.EmptyTypes and String.Empty and Array.Empty intrinsics.
These are all treated as special cases:
* Type.EmptyTypes and String.Empty are actually field accesses, so we don't have infra to share these yet, no need to add one for now
* Array.Empty is a generic method where we need to know the generic instantiation. The current sharing doesn't propagate this information
  so this forced the implementation to NOT be shared but instead done as a fallback which the shared one doesn't handle.

The rest of the changes are all about fixing how the shared intrinsic handling propagates return value from intrinsics.
Lot of small subtle bugs around null or emtpy inputs and forgetting to add return value and so on. The main changes are in GetMethod and GetNestedType intrinsics which had lot of issues.

Added tests for all of the corner cases.
NestedTypesUsedViaReflection test has been reworked as previously it didn't work correctly. Lot of the [Kept] attributes were fulfilled by some of the negative tests and thus the positive tests didn't have coverage (for example calling GetNestedType(unknownName) will mark all nested types on the type, so a subsequent call to GetNestedType("knownname") will not have an observable effect).

Commit migrated from dotnet/linker@e8b0ba0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants