-
Notifications
You must be signed in to change notification settings - Fork 128
Remove redundant checks in IntrinsicId switch statements #3060
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
Conversation
sbomer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
vitek-karas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall
| Debug.Assert (requiresDataFlowAnalysis || annotatedMethodReturnValue.DynamicallyAccessedMemberTypes == DynamicallyAccessedMemberTypes.None); | ||
|
|
||
| intrinsicId = Intrinsics.GetIntrinsicIdForMethod (calledMethod); | ||
| intrinsicId = knownIntrinsicId ?? Intrinsics.GetIntrinsicIdForMethod (calledMethod); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer we make the parameter mandatory. In linker it should be always known, in analyzer it isn't, but it's easy to call the helper.
| && calledMethod.HasParameterOfType (0, "System.Reflection.BindingFlags") | ||
| && !calledMethod.IsStatic (): { | ||
|
|
||
| case IntrinsicId.Type_GetConstructors: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're in this area - could you please rename these enums to be more descriptive? For example GetMethods has two overloads, with and without parameters. This one is the one with the parameter, but the enum doesn't make that obvious in any way. So maybe GetMethod_BindingFlags or something like that.
There's a related work item #1623 which is about making the matches more specific and robust. Maybe not in this change, but it would be a really nice thing to cleanup.
Rename GetMembers(BindingFlags) enum variants Make intrinsicId a required param Add doc comments for a few intrinsicIds
…er#3060) Remove redundant checks on intrinsicIds Rename Get<Member>s(BindingFlags) enum variants Make intrinsicId a required param Add doc comments for a few intrinsicIds Commit migrated from dotnet/linker@6000a84
In ReflectionMethodBodyScanner and HandleCallAction, we do many of the same checks that already occur in
GetIntrinsicIdFromMethod, and in a few places we have 'when' conditions that could just be regular cases. This removes the extra checks so the switch can be simpler and more optimized.In the linker, we also get the IntrinsicId twice, so this adds an optional parameter for a known IntrinsicId.