-
Notifications
You must be signed in to change notification settings - Fork 128
Compiler generated code handling #2010
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
Compiler generated code handling #2010
Conversation
|
|
||
| Should not produce any warnings, because the `type` variable is properly annotated. | ||
|
|
||
| #### Intrinsic data flow |
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 are all C# specific examples, maybe you could group them that way.
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 tried to add text which describes that this should ideally be for all compilers, but that we're focusing on C# right now.
|
|
||
| ## Problem | ||
|
|
||
| User authored attributes are not propagated to the compiler generated code. For example: |
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.
Which languages suffer from this problem?
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.
C# - is the one I know of. VB probably as well (didn't try).
While I agree that we should try to come up with solutions which could work for all languages, I think it's OK to start by focusing on C# first.
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 don't have a problem focusing on C# but the wording used in the design doc should indicate that more clearly.
|
Thank you for writing these down! I think another interesting aspect is how we handle lack of annotations. E.g. would we want to tell the user that for this: static void TestLambdaWithCapture(int p)
{
Action a = () => MethodRequiresUnreferencedCode(p);
}the problem is in the TestLambdaWithCapture method and not with the compiler-generated closure class? |
(My opinion) To a developer these look like different methods. Assuming the C# 10 feature gets in for lambda method attributes, I don't feel it would be necessary to propagate the attributes to lambdas and local functions. But obviously for iterators and async methods, these don't appear to be different methods to a developer. Which is why the attributes applying to the "whole method" (from a dev's point of view) makes sense there. |
|
@MichalStrehovsky I added a new section about method names in warnings. It's a very good point!
|
|
@eerhardt I'm yet to write down recommended solution and such... but to comment on your recommendation that lambdas and local functions should not need automatic propagation because developers can explicitly annotate them: In general I agree, but it might be pretty tricky to achieve. Closure+Lambdas and iterators look very similar at the IL level - we would need some new information from the compiler to be able to differentiate (as far as I can tell). But that's an implementation detail. More importantly We could still do something different for RUC, but I'm leaning towards keeping it simple (and thus consistent). |
There's also a question about dataflow annotations: static IEnumerable<int> TestParameter(Type type)
{
type.GetMethod("BeforeIteratorMethod");
yield return 1;
type.GetMethod("AfterIteratorMethod");
}(I took your example and removed the annotation on In the ideal world, this would produce a warning saying that parameter |
|
One interesting thing to note: if the code generated ends up in types, we could unambiguously refer to the type via typeof. But if the user code ends up in a bare method, there's no equivalent encoding for method signatures, including custom modifiers. |
| TestGenericParameter<TestClass> (); | ||
| } | ||
|
|
||
| static async void TestParameter ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type) |
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 checked and it looks like async and iterator methods each get an attribute, Async/IteratorStateMachine along with a typeof pointing to the definition. We could consider generalizing that in some way.
|
@marek-safar Do you happen to have a design doc for VB or F# for the other linker features? We recently discovered serious deficiencies with VB, so I wonder if the rest of the linker was designed with other languages in mind. |
In pre-netcore version of linker we didn't add any language-specific features. There were added later. In our previous testing, we generally focused on C# and F# only. |
|
I added first draft for recommended solutions. Currently it's very high-level. |
72eedf2 to
8a7adac
Compare
Also adds tests for the existing patterns - all of them fail. Either lack of implementation or lack of known outcome.
Co-authored-by: Eric Erhardt <[email protected]>
8a7adac to
2553156
Compare
|
I'm going to merge this so that we have at least some documentation in the repo around this. |
* Problem description and existing patterns * Proposed solutions and some discussion of these Co-authored-by: Eric Erhardt <[email protected]> Commit migrated from dotnet/linker@d74c97b
Also adds tests for the existing patterns - all of them fail. Either lack of implementation or lack of known outcome. The tests are there as they are the complete examples (not just the short versions in the doc).
This is meant to start the discussion on #2001 - determine desired behaviors and eventually also about possible solutions.