VB Feature Implicit Default Optional Parameter#12629
Conversation
+ Check Features for Feature flag + Make CheckFeatureAvailability depend on the LanguageOptions + Alter Parse_Parameter to enable this feature. + Add a new Language Version.
Modify Unit Test to better indicate its meaning.
Add Debug.Asserts into CheckFeatures. ParseOptions in VisualBasicCompilationOpotions will have default non null value.
Making a starts on adding asserts to check for the presence (or not) of the feature.
…Parameter Feature. (PASSED)
|
Think the issue is in the Since it now possible for the parameter to be |
|
Looking at HasExplicitDefaultValue it's not clear if the purpose of this flag is about the syntax or more what's in metadata. So, even with your proposed feature the emitted metadata for a default value should look indistinguishable from what would be emitted were the user to have written "= Nothing". So if you round-trip a method symbol from source to metadata this flag will have HasExplicitDefaultValue = True on the import side. I'm inclined to not change this flag but couldn't track down the consequences if we leave it True without corresponding syntax. |
|
@AnthonyDGreen I'll do a push in bit. |
… the possibility of an optional parameter not having an explicitly stated default value.
|
Somehow my comment about Binder.GetArgumentForParameterDefaultValue disappeared. So I will expand on it and summarize my overall thinking about the current feature implementation. I think that the feature should be just a syntactic relaxation. Meaning that, if optional parameter declaration is omitting the default value, then the behavior should be as if the value was explicitly specified to be NOTHING (NOTHING literal). We should also make sure that:
Given this, I think we cannot rely on the feature availability check (at least the way it is done right now) in Binder.GetArgumentForParameterDefaultValue for correct behavior.
It seems, the simplest way to implement the feature with required behavior would be to adjust behavior of parameter symbol so that, instead of “saying” that it doesn’t have an explicit default value, it would “say” that it does have an explicit default value (despite the fact that the value isn’t specified in the syntax). That default value must exactly match default value corresponding to NOTHING literal. |
|
@AlekseyTs
It is a syntactic relaxation, but additional changes are required because the prior existing code currently assumes the "explicit parameter initializer" is not null. With the feature present is does still passes the prior existing metadata unit test.
The prior existing code, assumes the parameter is never null. Hence requires to be change to account that it could be null.
With all due respect, could you provide evidence (eg unit test) for the "reasons why", will have the alleged affects. Then we can be confident that it doesn't break, and maintains expected results.
The branch is Open-Sourced and I'm willing to accept a Pull Request from the community, |
Let's take a look at the first problem:
Is the same default value used by Compilation2? |
|
@AlekseyTs |
|
If I now revert the requirement for non-null parseoptions. I get these test failures |
|
@AlekseyTs I've managed to remove the requirement for non-null ParseOptions and the FeatureCheck in |
| @@ -3028,86 +3028,15 @@ ProduceBoundNode: | |||
| ' See Section 3 of §11.8.2 Applicable Methods | |||
| ' Deal with Optional arguments. HasDefaultValue is true if the parameter is optional and has a default value. | |||
| Dim defaultConstantValue As ConstantValue = If(param.IsOptional, param.ExplicitDefaultConstantValue(DefaultParametersInProgress), Nothing) | |||
There was a problem hiding this comment.
Since we now don't expect any behavior changes in this file, please revert the file to its original state. The extract method refactorings, if you think they bring a lot of value, could be submitted as a separate PR, but let's not bundle unrelated things in this PR.
There was a problem hiding this comment.
Nope, as it won't work for (<CallerLineNumber> Optional line As Integer)
…tions. Remedial work to correct the references to the new method location.
For example Scenario 1: base - `Public Overridable Sub f(x As Integer, Optional y As Integer)` derived -`Public Overrides Sub f(x As Integer, Optional y As Integer = 0)` Scenario 2: base - `Public Overridable Sub f(x As Integer, Optional y As Integer = 0)` derived -`Public Overrides Sub f(x As Integer, Optional y As Integer)` Scenario 3: base - `Public Overridable Sub f(x As Integer, Optional y As Integer)` derived - `Public Overrides Sub f(x As Integer, Optional y As Integer = 1)` Scenario 4: base - Public Overridable Sub f(x As Integer, Optional y As Integer = 2) derived -Public Overrides Sub f(x As Integer, Optional y As Integer)
…ste, and then not reveiwing the result.
|
@AlekseyTs I've updated the unit tests with your recommendations. |
…o a new private function, so it can be called from another condition. Remove the use of the kludgy use of GoTo.
|
Hey Adam, Thanks again for working on this feature. Thank you to reacting to the feedback and recommendations given thus far. I want the feature and really appreciate you helping out. We’re new to this process of accepting community PRs for language features so I apologize if we haven’t set expectations correctly. I want to try to set some now with the hope that that will make this process smoother moving forward. First, with regards to compiler changes, as frustrating as it may seem you're being held to the same high standard as any compiler developer working on site here in Redmond. Maybe the bar is a little higher while you’re building a proven track record but not by much. This is the same frustrating experience that all new team members experience. It sucks, I know, I’ve been there. My first few (failed) attempts at contributing to the compilers were epic disasters. The Visual Basic compiler is used to compile millions of programs and we (Microsoft) are responsible for any change that breaks any of those programs. Additionally, any “accidental feature” – where a code change allows something to compile unintentionally is also a problem since it might allow something that doesn’t make sense or doesn’t fit with the language but fixing it in a future release will break new programs written since the “accidental feature” was release. It’s an awesome responsibility and consequently every change to the compiler is met with the highest scrutiny. We want to have the highest confidence that your feature is doing what it’s supposed to do, exactly what it’s supposed to do, and absolutely nothing more that it’s supposed to do. Therefore, in the interest of time every compiler change must be surgical. Whether it’s fixing a bug or implementing a new feature the changes you make must be chosen with surgical precision—touching the exact right lines of code and the smallest number of lines of code overall. When I do either I actually spend a lot more time thinking about where to make the change than making the change itself. Measure ten times, cut once When you submit a PR the vast majority of our review will be focused on finding red flags in your code. Feverishly finding places where you forgot something or did too much so you can fix it. Sometimes just asking questions to understand why you did something in a certain way or why you didn’t do it another way and whether you’ve thought about a certain test case. Because not understanding why you did something a certain way or that there were other ways to do it and why you didn’t do it that way or not having thought through a lot of test cases to break the feature is a huge red flag. Other red flags are how much change there is in the code-the more the more likely the code is incorrect. That’s why it’s critical that your changes touch the minimal number of files, minimum number of methods, and minimum number of lines of code in those methods. Put another way, the probability of your PR being accepted is inversely proportional to the square of the size of the PR. Right now here are the red flags I see in your PR:
Second, you seem to take criticism of your code personally (I’ve also done this). Don’t. Your code is being reviewed by very very senior developers with decades of experience (both individually and collectively) writing compilers and working with these languages. If a Roslyn team member asks a question don’t assume it’s an insult. If they give you advice you should probably take it. You should never invite that team member to send you a PR if they feel strongly about something. You should never demand they provide you with hard evidence that something is a problem. It’s their job to raise questions and point these things out and they’re the gate keepers who have to sign-off of the code and take responsibility for what we ship to customers and support that code later. Always be respectful and act on their feedback. That’s the bar for contributing. Third, I know we didn’t set this expectation early and that’s our fault but you should actively reach out and solicit opinions on implementation strategies before making them. I can’t tell you how often when writing a feature, I go to @AlekseyTs, or @VSadov, or @cston, or @gafter and ask “I’m thinking of modifying this code here in this way – does that seem like a reasonable approach to implementing this? What problems do you see with that?”. Or I’ll go to @tmat and say “This code works in Edit & Continue, I have no idea why – please explain”. That’s what it means to be a contributor and part of our extended team. And it will save you and epic amount of time compared to doing the work and then defending the code as written. Again, it’s our fault that we didn’t invite you to solicit feedback on implementation strategies before you did all this work. We’re new to this and we tend to make assumptions or forget that the habits we’ve all developed from working with each other for 2, 5, or 10 years on this compiler or just working in the same building with each other all day are not habits that a community contributor would naturally pick up. We need to fix that. In summary, your PR has too much churn, make your changes minimal and surgical in the future. Please be respectful of team members, less defensive, and more receptive to feedback. Hold us to being more collaborative up front. I know normally we don’t like you to open multiple PRs for the same code change because it loses prior feedback, but I think it’s best to roll a do-over on this one. Believe it or not I’ve had to re-implement or re-apply changes for a language feature 4 or 5 times in various branches too. I’m going to close this PR. Don’t throw away any code (especially test cases). If you’re still interested in doing the feature, I’d like to try this again from the top and taking very very small steps together:
I cannot over emphasize the words bare minimum above. I think if we take this in small layered steps we can get this feature in for VB 15.1 with the least amount of friction and frustration on all sides. Given that we’re still new to this and hadn’t set all the expectations or weren’t as collaborative or responsive as we should have there’s no offense taken if you don’t want to start over. I will chalk it up as a failure on me, not you. My concern was that if we were too prescriptive it would take all the fun out of doing the feature and erred on the side of letting you run with this. In hindsight what I was really doing was denying you the team culture and support you needed to be successful. I apologize. That said, is this something you’re still interested in or would you like someone else to pick up the feature? |
|
@AnthonyDGreen Thank you so much for the wonderful feedback, both the good, the bad and the ugly. Things to take forward ;-
Sad to admit I was expecting a "No Go" on the current PR code for the feature. It way to big as compared to others. Most down to stylistic changes, and feature checks implementations. As proof of concept the PR demonstrates to me, the feature has high potential of get into the Visual Basic language. Even if I'm not the one to implement it. Saying that if it ok with you and the community I'd like to have yet another go at implementing it, as I been on it since inception. *(If another member would like to implement I'm OK with that to).. |
|
@AnthonyDGreen Had a chance to sit back and reflect on this and come the conclusion. That it would be good for the community ( and I ) that if I release development of the feature to someone else. Better to see the feature in a release, rather than waiting for me to eventually implement it. I'll keep that branch publicly available so that whom takes the torch, can reuse the unit tests. |
|
Hey Adam, we're already past the point where I think we'd add this feature to release. I still think it's a good feature and we should work together to get it in an update. We're buttoning up a few things on VB 15 and then we can take another look at implementing this together. Thanks! |
|
@AnthonyDGreen |
…cs (#12629) Fixes dotnet/razor#12628 Needs #81822 to compile
Implements #10293