-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Proposal: CallerArgumentExpressionAttribute #22596
Comments
cc'ing people from the csharplang threads (dotnet/csharplang#287 and dotnet/csharplang#205): @gafter, @CyrusNajmabadi, @HaloFour, @ig-sinicyn, @tannergooding, @svick, @jnm2 |
Cool proposal. I have made several frameworks in the past to accomplish something similar, with either less performance or more verbose notation, that might become redundant by this. https://github.com/jjvanzon/JJ.Framework/tree/master/Framework/Exceptions Those are not even the only ones! |
Should the |
@svick Sure, why not. I think such a property may even have a practical use for reflective code that wants to determine the parameter being referenced. (Although, that may already be possible (in a slightly less cleaner way) through this API which allows you to get the ctor arguments of an attribute.) Updated the proposal. |
@karelz, I think this api is safe to mark ready-for-review. The C# team has already approved this and explicitly said we should start the process for getting this in, see here. The addition of this api to corefx is what is causing them to push this feature back to 7.x, I do not think we should risk further delays. |
What of the other caller info attributes? |
@AlexGhiondea @joperezr are area owners and should do first-level API review. If they are happy with it, they will be able to mark it 'api-ready-for-review'. |
@AlexGhiondea @joperezr Please consider marking this ready-for-review: the C# language design team has already approved of it, and this attribute needs to get into the fx for them to take any further action. |
proposal looks reasonable. Marking as ready for review. |
@karelz When are you planning to do an API review for this issue? There seem to be quite a few issues-- some since January-- marked ready-for-review that are not approved yet. |
We have a small backlog accumulated over the summer. Except one special-case exception, all api-ready-for-review issues were marked as such after 6/24. So far I have been trying to bundle API review issues into similar blocks (Reflection last week, sadly the recording of the session failed to record properly), and prioritize the easy ones. This one should be part of next badge in ~10 days or the week after. |
@karelz Yeah, it helps. Thanks for the update! 😄 |
API review: Looks good as proposed, but we should wait for final language feature. In general, I would recommend to not file API proposals ahead of LDM being further down the road. |
@karelz I don't think it makes sense to mark this as blocked. The compiler team has said that they are waiting on the type to be added before they will discuss it further... it's like an issue deadlock. |
I expect the compiler team to add the relevant language feature in the next release (minor or major) following the addition of this supporting attribute. /cc @jcouv |
@gafter if you can confirm the API shape fits Roslyn needs, we can unblock the API addition in 2.1. |
@karelz From discussion with LDM over email, the API shape was confirmed to be good. I forwarded you the thread. Thanks! |
Unblocked, it is ready to roll. Any takers? -- should be fairly straightforward to add |
Tagging @alrz who is working on compiler change to see if he could implement the type as well. |
I didn't find other caller info attributes in this repo. sounds like System.Private.CoreLib.csproj is private? |
WOOT! Been waiting for this for so long 🎉 |
@jamesqo glad to hear. I must say there is one more language issue that came up afterwards: how can existing APIs adopt the attribute? Adding an optional string parameter causes problems in typical methods we're thinking of (such as asserts). |
@jcouv Just gave you a really long response about binary compatibility on the csharplang issue. |
Marking as blocked again, until we resolve the language feature. |
@karelz I think it's resolved. They said there wouldn't be a binary compatibility issue. |
Yes, here are the relevant LDM notes. Thanks |
Removed the "blocked" label accordingly. |
It looks like this API is approved, but how it'll actually manifest is still under debate. However, if putting this in'll get things moving, this is something I'd like to see. I'm not sure where this would be added in corefx, though. There are some CompilerServices Attributes in Common\src\CoreLib\System\Runtime\CompilerServices, but these files are just for including in other projects, if I understand correctly. I'd be glad to add it if I know where to ^_^ |
@jswolf19 I didn't read the LDM discussion carefully. My naive understanding was that it is ready to be added into CoreFX. @danmosemsft would probably know more ... |
@karelz So, if I add to the Common\src\CoreLib\System\Runtime\CompilerServices, it'll eventually make its way to the CoreCLR and CoreRT repos? |
I admit I don't know which way the mirror goes :( ... either check history of such additions (I suspect CoreCLR is the primary source), or wait for someone knowledgeable to chime in ... |
The LDM linked is newer than much of the discussion at the issue, so it would seem that this API is what has gotten consensus. I'll see what I can find as far as addition history. |
So this is what I'm perceiving the order of things that needs to get done is. Please let me know if I should do things differently, otherwise, I'll submit the CoreCLR pull request this week.
For the last step, I have questions about whitespace handling and corner cases (see below). If there are any other cases that I should include, please let me know.
|
@jswolf19 somehow I missed this issue. Yes your sequence looks correct. Note the mirroring you care about from coreclr to corefx is the insertion of the coreclr SHA not the mirroring of coreclr source code (which is for code reuse) |
Your questions about test expectations are msybe questions for Roslyn repo since they will be producing the result. |
…ly (#30469) * Expose CallerArgumentExpressionAttribute (#21809) * added basic CallerArgumentExpressionAttribute tests * added test to show that overload without optional parameter is taken over method with * added tests to illustrate behavior of CallerArgumentExpressionAttribute (final behavior may differ) * added type CallerArgumentExpressionAttribute to uapaot ApiCompatBaseline * Moved CallerArgumentExpressionTests to non-netfx section * added newlines as per review
@jswolf19 I've answered your questions in parentheses below:
|
@jamesqo Thanks for your reply. There's an inline comment in the ExtensionMethod example, so I'm guessing that should not be included? (2 instead of 1 below)
It doesn't appear to be possible in c#, but I'm pretty sure it is possible in vb. |
It should be included (IMO). The compiler will simply give you the unprocessed span of the code from the start of the first token in the arg to the end of the last token in the arg. All intermediate 'trivia' (including comments, whitespace, newlines, and even preprocessor directives) would be included. |
Note: in Roslyn parlance, this would be equivalent to calling: Note: another important case to consider is:
Presumably we want |
Rationale
In order to facilitate the language feature at dotnet/csharplang#287, which has been championed and discussed in the LDM, we should add
CallerArgumentExpressionAttribute
to the framework. The LDM notes seem to approve of getting this into the framework: see here.Proposal
Notes
parameterName
and notargumentName
. Parameters refer to the variables declared inside the callee, while arguments are the values passed by the caller.The text was updated successfully, but these errors were encountered: