Skip to content
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

Scanner(unification) + TryPeek #1463

Closed

Conversation

AdamSpeight2008
Copy link
Contributor

This pull request unifies the contents of TryScanToken and ScanTokenFullWidth.
I retain those methods so not the break existing calls to them. The internals now call a common implementation method ScanTokenCommon.

This reduces the size of the sourcecode and the resulting IL (Debug)

                       Old |  New 
                     ------+------
      TryScanToken:-  1746 |   42
ScanTokenFullWidth:-  1972 |   15
   ScanTokenCommon:-       | 2035
                     ------+------
             Total:-  3718 | 2092

@gafter
Copy link
Member

gafter commented Mar 27, 2015

@AlekseyTs Could you please look at this and decide if it is worth moving forward with it?

@gafter gafter added this to the 1.0 (stable) milestone Mar 27, 2015
@AdamSpeight2008
Copy link
Contributor Author

@dotnet-bot test this please

@AdamSpeight2008
Copy link
Contributor Author

Resubmit within PR #1727 as that PR merge is simpler.

Friend Module CharExts

<Runtime.CompilerServices.Extension>
Friend Function IsAnyOf(c As Char, c0 As Char, c1 As Char) As Boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing the name to something more descriptive. For example, IsEqualToAny.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if I add XML documentation to them instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, XML documentation doesn't help at a call site unless you are reading the code in VS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that LNQ provides the extension method .Any, I don't the contextual meaning isn't that far of a leap.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am simply suggesting to name the methods in such a way so that no leap would be necessary.

@AdamSpeight2008
Copy link
Contributor Author

@dotnet-bot test this please

' TODO: do we allow widechars in keywords?
Dim spelling = "As"
AdvanceChar(2)
If fullWidth Then spelling = GetText(2) Else AdvanceChar(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using multi-line If

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had the feeling that this could be simplified to

AdvanceChar(2)
Return MakeKeyword(SyntaxKind.AsKeyword, "If", precedingTrivia)

or (currently testing)

Return MakeKeyword(SyntaxKind.AsKeyword, GetText(2), precedingTrivia)

but never entirely sure.

       Private Function GetText(length As Integer) As String
            Debug.Assert(length > 0)
            Debug.Assert(CanGet(length - 1))

            If length = 1 Then
                Return GetNextChar()
            End If

            Dim str = GetText(_lineBufferOffset, length)
            AdvanceChar(length)
            Return str
        End Function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlekseyTs I've tried both alternatives and both pass the unit test.
So I'm going with the first alternative.

AdvanceChar(2)
Return MakeKeyword(SyntaxKind.AsKeyword, "If", precedingTrivia)

As it calls less code.

This will then apply to the other cases, as well with the appropriate changes.

@AdamSpeight2008
Copy link
Contributor Author

@jasonwilliams200OK Done and Thank you for the notes on the rebase.

@ghost
Copy link

ghost commented May 31, 2015

👍
@AlekseyTs, all yours. IMO this PR (with highest number of comments) is ready to bring (probably little but) useful value to the roslyn code base. Please consider concluding it before it requires resolving merge conflicts again. :)

@AdamSpeight2008
Copy link
Contributor Author

It makes the vb parser / scanner code a lot nicer to work with. Some section are little more efficient, some occur minor costs for the sake of clarity of code. I've had to resolve merge conflict twice already.

@AlekseyTs
Copy link
Contributor

@VSadov, @gafter, @agocke, @jaredpar, @khyperia FYI

ch = MakeHalfWidth(ch)
Return ScanTokenFullWidth(precedingTrivia, ch)
If fullWidth Then
Debug.Assert(Not IsDoubleQuote(ch))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debating whether it is worth making this as debug only? It be an empty branch (true) body in release mode..

@gafter
Copy link
Member

gafter commented Jun 1, 2015

I think the concerns about overuse of AggressiveInlining should be addressed.

I agree with Jared that we should avoid contractions in method names.

I am concerned that this PR combines too many changes to be effectively reviewed.

@jaredpar
Copy link
Member

jaredpar commented Jun 1, 2015

I agree with @gafter

@AdamSpeight2008
Copy link
Contributor Author

@gafter Strange I thought I'd already addressed those, unless the squash zapped them.

AdamSpeight2008 added 2 commits June 2, 2015 02:07
Rename method so it does't use contraction.
Remove Inlining Attribute.
Restructured and IF statement in ScanTokenCommon
@AdamSpeight2008
Copy link
Contributor Author

@dotnet-bot test this please

@AdamSpeight2008
Copy link
Contributor Author

@gafter @jaredpar @AlekseyTs @jasonwilliams200OK @ljw1004

Hasn't this been slowly reviewed? over the course of its inception to now, through it varied incarnations. A little tweak there another tweak here, since it involve a delicate part of the VB.net compiler. Even if if doesn't make it into current release, it is worth looking at a future one. I think that progression has had side benefits, of us discovering other issues, gotchas and problems in the language specification.

@gafter
Copy link
Member

gafter commented Jun 2, 2015

@AdamSpeight2008 Because this pull request is so large, and has been presented in numerous revisions, I have no idea which parts have been reviewed and which not, and which parts have outstanding issues. It is too large for us to reasonably scan through it to answer such questions. I'd prefer to see such changes presented in a series of separate PRs each focused on a particular set of issues.

@gafter
Copy link
Member

gafter commented Jun 2, 2015

@AdamSpeight2008 I do not have any idea why @jasonwilliams200OK was giving you instructions of what to do with this PR.

@AdamSpeight2008
Copy link
Contributor Author

@gafter They were helping me reduce the number of commits ( I think it was in the region of 20) in PR, since I seem to break thing when I do git commands.

@AdamSpeight2008
Copy link
Contributor Author

Quick overview of concern and issues

@gafter wrote:

I can imagine accepting a pull request that does this, but it is hard to imagine the Roslyn team doing this themselves.

I propose that we accept this PR (with the possible addition of an attribute to encourage jit inlining) and keep an eye on the performance for any regression.

  • JIT Inlining
  • Performance

@gafter gafter added the 4 - In Review A fix for the issue is submitted for review. label Jun 16, 2015
@gafter
Copy link
Member

gafter commented Jun 17, 2015

@AlekseyTs Can you please make an executive decision as to whether we want to move forward with this PR, or instead close it and request that the submitter re-submit smaller more focused PRs for the elements of it?

@AdamSpeight2008
Copy link
Contributor Author

Again?! True it's a big PR.

The Scanner(Unification) change affect 2/3 methods, but as the TryParse changes developed some of those changes got incorporated into the Scanner(Unification) methods. Submitting (yet another set of) PRs I don't think would be "better". If the number of comments on this PR (and previous) are anything to go by, have helped refine / improve the changes. It has stabilised and there hasn't been a changes in a while, if there anything that may need altering or change could be fixed in smaller subsequent Pull Requests.

@gafter
Copy link
Member

gafter commented Jun 17, 2015

@AdamSpeight2008 Not again. Still. One reason for the decreasing number of review comments and changes is that some reviewers have grown tired of re-reviewing thousands of lines of code multiple times as you revise the PR. This code has not been reviewed since any of the last 10 revisions (perhaps more), and I am not motivated to review it again because it is so large and keeps changing out from under me.

In any case, my question was for @AlekseyTs.

@AdamSpeight2008
Copy link
Contributor Author

@gafter Oh don't treat me like a doormat, to be walked all over.

It's not like the master branch has not changed under me as well.

  • I've had all of the variable names change. (after the PR was submitted )
    Which invalidated PR merge would now be a build failure, prior it wasn't.
  • Rebase to current state of master
  • Squash the commits
    Both of which came for "Team" members. "Team" member wanted changes / improvements which I've complied with. Hence additional commit to this PR
  • Been instructed to not to submit another PR that is essence this / these.
  • Recent commits are only to rebase to 'master`

See it from me side.
If I do the follow imaginaryl PRs

  1. Scanner Methods (Unified)
  2. TryParse Methods

Merge conflict as the 2nd contains the older methods. Thus I have rebase if
or

  1. TryParse Method
  2. Scanner Methods (Unified)

Merge conflict as the unified method doesn't contain the use of TryParse. Thus require addition commit / rebase.

Either way I'm screwed i terms merge conflicts

Alternative this

  • I submit yet another PR, lets say Scanner Methods (Unified).
  • Wait for the Yah / Nah.
  • Wait for the merge into master.
  • Fork with this new master as a base,
  • Redo all the TryParse implememtations. ( possible missing some / making errors )
  • Submit yet another PR.
  • Wait for the Yah / Nah.

Wouldn't it be simpler for everyone to have one PR (this one)?

@jaredpar
Copy link
Member

@AdamSpeight2008

The issue with this PR is that it's a collection of changes rather than a single change to the scanner:

  • Formatting changes: white space removal, line break changes, etc ...
  • Refactoring: new helper methods: Peep, IsnotFrom, etc ... , rewriting core methods like ScanTokenFullWidth
  • Code hygene changes: switching to interpolated strings

Combining all of these changes into a single PR, and a large one at that, makes it significantly costlier for the Roslyn team to review and verify. The ask from @gafter, which I completely agree with, is for the PR to be broken into smaller focused PRs.

In its current form I don't see any way we could merge this PR into the source tree:

  • The scanner is a very perf sensitive area for the compiler and we don't treat refactoring changes to it lightly. Verifying the change involves careful monitoring of our perf suites plus an investigation to any deviations we see. This is why we are pushing to separate out the refactorings from all of the other changes such as formating, name changes, etc ... It simplifies the investigation process to have the change as minimal as possible.
  • I know you disagree with our formatting and style decisions but they are not going to change and we will not be accepting PRs that contain arbitrary reformattings of our code. I've mentioned this several times in the past.
  • The size of the change and mixed refactorings make it harder to follow. It's difficult to tell if parts of the change are bug fixes or changes that respond to refactorings you made.

There is a general question as to whether we would take the refactoring of the Scanner even if it was separated out from the rest of the change. Some of the pattern changes, like Peep, look good at least to me. Other changes are of questionable value and have a high cost for the team in terms of verifying the changes. Breaking the refactoring into smaller, easier to review, changes would significantly increase the likely hood we would accept it into our source tree.

I do want to thank you for pushing on this change. We are interested in adding value to our code bases and cleaning up parts of our code base which have gone stale. I appreciate that you've put a good deal of effort into this PR and are trying to add value to our code base. But in its current form it's not possible for us to accept it for the reasons listed above. Given all of this I'm closing this PR.

@jaredpar jaredpar closed this Jun 18, 2015
@AdamSpeight2008 AdamSpeight2008 deleted the Scanner(Unification) branch October 31, 2015 22:29
@gafter gafter added Resolution-Won't Fix A real bug, but Triage feels that the issue is not impactful enough to spend time on. and removed 4 - In Review A fix for the issue is submitted for review. labels Dec 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Resolution-Won't Fix A real bug, but Triage feels that the issue is not impactful enough to spend time on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants