-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Implement lower and upper bound inference in function pointer parameters #50249
Implement lower and upper bound inference in function pointer parameters #50249
Conversation
dotnet#43041 implemented exact inference of function pointer parameters and bounds only, and left a few errors in our tests that needed to be handled. This is also the cause of dotnet#50096. This implements bounds inference, using the same variance rules that function pointer to function pointer conversions do. I still need to spec the rules here, and may need to make a couple of adjustments around handling of delegate*->void* in bounds inference. At least initially, this isn't supported, but I'll work out what the correct rules should be when I spec it and update this PR accordingly. Fixes dotnet#50096.
@@ -1563,7 +1667,6 @@ public static void M() | |||
} | |||
}"); | |||
|
|||
// Some of these errors should become CS0306 after variant conversions are implemented, tracked by https://github.com/dotnet/roslyn/issues/39865 |
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.
None of the remaining 0411 errors can be inferred: they're between function pointers with int and string parameters. There is no reference conversion or implicit pointer conversion, so nothing can be inferred.
@@ -1651,7 +1754,6 @@ public static void M() | |||
} | |||
}"); | |||
|
|||
// These should all work: https://github.com/dotnet/roslyn/issues/39865 |
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.
These could only be inferred if we supported array covariance for implicit pointer conversions. The spec makes no mention of such support, and we do not support int*[]
being converted to void*[]
today, so this is not expected to be supported.
…antly inside a pointer, and any inferences on such `T`s should be done with exact inference.
@dotnet/roslyn-compiler for review. |
@dotnet/roslyn-compiler for review. |
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Show resolved
Hide resolved
* Missed parameter rename. * Ensure error condition is explicity rejected.
@AlekseyTs I believe I've addressed your feedback. I didn't see a review complete comment, so for reference your comments were on commit 3. #Closed |
@333fred It looks like there are some legitimate test failures. #Closed |
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Show resolved
Hide resolved
Done with review pass (commit 4), tests are not looked at. #Closed |
@AlekseyTs addressed feedback. In reply to: 761040006 [](ancestors = 761040006) |
@333fred |
Done with review pass (commit 6) #Closed |
@AlekseyTs addressed feedback. In reply to: 761278444 [](ancestors = 761278444) |
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
Done with review pass (commit 7) #Closed |
@AlekseyTs addressed feedback. In reply to: 765812574 [](ancestors = 765812574) |
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
Done with review pass (commit 9) #Closed |
@AlekseyTs addressed feedback. In reply to: 767076222 [](ancestors = 767076222) |
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 (commit 12), assuming CI is passing.
@@ -1281,60 +1291,79 @@ private bool MethodGroupReturnTypeInference(Binder binder, BoundExpression sourc | |||
// SPEC: yields a single method with return type U then a lower-bound | |||
// SPEC: inference is made from U to Tb. |
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.
nit: Consider updating the spec comments to reflect changes.
@@ -2067,6 +2132,54 @@ private void LowerBoundTypeArgumentInference(NamedTypeSymbol source, NamedTypeSy | |||
targetTypeArguments.Free(); | |||
} | |||
|
|||
#nullable enable | |||
private bool LowerBoundFunctionPointerTypeInference(TypeSymbol source, TypeSymbol target, ref HashSet<DiagnosticInfo> useSiteDiagnostics) |
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.
LowerBoundFunctionPointerTypeInference [](start = 21, length = 38)
Adding new spec comments would help
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 (iteration 12)
@jcouv I'm going to follow up on your comment suggestions in master to get this in now. |
#43041 implemented exact inference of function pointer parameters and bounds only, and left a few errors in our tests that needed to be handled. This is also the cause of #50096. This implements bounds inference, using the same variance rules that function pointer to function pointer conversions do. Note that for parameters and return types, I'm not considering delegate*->void* conversions, as
T
cannot be eithervoid
orvoid*
.Spec PR: dotnet/csharplang#4310
Fixes #50096.