Scanner Peep. - #6305
Conversation
This adds peep functionality into the scanner, which is combination of CanGet and Peek. It does not alter the existing content of the out parameter (ch) when CanGet is false. NOTE: This is different mechinism to TryParse methods, this is deliberate so that existing value can be used in subsequent conditions.
Usage of Peep in ScannerXML
|
I'm doing a few refinements of the temporary char variables I've introduced, see which I remove (reuse an existing char variable. |
|
tag @dotnet/roslyn-compiler |
|
Test time down to around 18-19 minutes. (On my machine) |
|
Ready for review. |
There was a problem hiding this comment.
Why is this one using ch and the others us cx?
There was a problem hiding this comment.
@TyOverby
I'll re-examine this method.
Some of the case can alter the value of ch as all code path in that case exit from the function. It is the case's that don't I have to be careful with as ch is used after the Select block.
Tweaks to the temporaries use with `Peep`. Removed some commented out code.
|
@dotnet-bot retest this please. |
|
Re-examined the usage of |
|
@dotnet/roslyn-compiler Anybody care to comment on this? @AlekseyTs ? |
|
@AlekseyTs I've also got a branch that integrate this into the |
|
@gafter Ok, I'll do that and rerun the tests. Maybe a couple of hours before the results are posted. |
|
@gafter I think I've calculated those totals and averages correctly. ❓ |
|
This looks good to me. @dotnet/roslyn-compiler Can I please have another set of eyes on this? |
|
Someone at lunch mentioned that having "peek" and "peep" intermingled could confuse readers. Fortunately we have a naming convention for functions that return bool for success/failure and use out parameters. What about changing "peep" to "tryPeek"? |
|
@TyOverby Private Function Peep(skip As Integer, ByRef ch As Char) As BooleanNotice the If Method naming was discussed previously and was suggested that a distinction be made. I also added the XML comments also, so that this information was available in intensense. I didn't want the name to be too long as it is used a lot in the scanner code. A previous PR (#1627) shortened a lot of these common methods, which made the source a lot simple to read.
@gafter Let me just re run the tests as it looks like the proposal has the wrong dll. The one without |
|
@gafter After rerun the test, with the correct DLL (with Peep) for the Proposal |
|
@AdamSpeight2008 Can you please give an example of where, in your code, you depend on
|
|
@gafter ' ch as some existing value before here
While Peep(Here, ch) AndAlso IsFoo(ch)
...
End While
Dim bar = Foo (ch)Imagine the While is false because of the Let say This one
|
|
Another Example Possible Assert Failure |
|
That is way, way too subtle. I'm afraid this code is far too delicate if that is your intent. It is likely to break when next it is maintained. I'd prefer to see that code changed from Perhaps better to only use the new |
|
@gafter Don't blame me for casing, I just working with what already existed. |
It maybe so but they are pre-existing within the scanner source, the PR doesn't change that. It just exposes it because of the PR touch that area of the source.
It still is explicit, just that
All of the usage can be replace with a |
|
I think the code would be much more clear if this kind of method were only used when the "try" pattern were applicable. A method that takes a ref parameter and sometimes assigns it and sometimes does not, and a caller that takes advantage of the difference, is just way too subtle. That was not a pre-existing pattern in the code. That would also enable you to rename the method so it follows a familar "try" coding pattern. |
Completely agree. I've looked at this PR a few times and never noticed that. |
|
The original code was clear because the assignments were explicit, under conditional statements. |
|
It still is explicit under a conditional statement, only that they've been combined into a single function. @Pilchie Any comment?. |
|
Though we appreciate your efforts, we do not want to accept this change as written, though we might consider a change that uses the try pattern where appropriate. To be clear...
No, that is not a try pattern. That is code that could be rewritten into the try pattern. A try pattern is a method (in C# syntax) The reasons we do not want to pull these changes are
If you're interested in contributing to the Roslyn compilers, I recommend you select issues that we've already identified as things we'd like fixed and would welcome community contributions. For example, #2150 is low-hanging fruit. |
|
It would perform worse if it followed the other try patterns, as it would involve an extra assignment on each false. |
|
There are functions with the current source that have the "Try" prefix,return a boolean and don't have an |
Threading and Service Feedback
[Compiler VB Scanner] Implement Peep and usage within the scanner.
Peepis a integration of the contents ofCanGetandPeekas these often appear in close proximity. By combining them the source code is shorter, and potentially slightly quicker as the 'ch` value can be cached, and thus reused later. Reducing repetition of multiple function calls.(On my machine time to run the tests reduced from 21mins to 20mins)
Note:
Peepis similar to aTryParsefunction but it implements different semantics in thefalsecase, where it preserves the existing value contain inchThere may be some potential reduction in the number of temporary char variables, with closer examination, but this can be left for another PR.