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

cmd/internal/src: XPos.After doesn't necessarily match Pos.After #20390

Open
mdempsky opened this issue May 17, 2017 · 3 comments
Open

cmd/internal/src: XPos.After doesn't necessarily match Pos.After #20390

mdempsky opened this issue May 17, 2017 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mdempsky
Copy link
Member

XPos.After (and XPos.Before) compares XPoses with different bases according to their base index, which is determined by the order they're added to the PosTable. I think this is worrying because we don't currently have any code in the compiler to ensure PosBase are registered in order.

Possible solutions I see:

  1. Change XPos.After's signature to take a *PosTable parameter and return the result of comparing the corresponding Pos values.
  2. Change package syntax's parser to register PosBase with the PosTable during parsing. (Will require locking.)
  3. Change package syntax's parser to collect all PosBase into a slice which we can register serially once parsing is done.

/cc @griesemer

@griesemer
Copy link
Contributor

I'd rather not tie more information about positions into the syntax package (in fact, I've been trying to see if I can come up with an approach that takes that dependency on the pos package out again). I'm still hoping we can keep this package pretty clean, so that at some point we can expose it outside.

Regarding the issue: What is the actual problem? Is it that we want to the base indices be representative somehow of the order in which files were presented to the compiler?

@mdempsky
Copy link
Member Author

The motivating issue is I was working on reviewing CL 40095, which has an API like (simplify):

func openScope(start, end src.XPos)
func closeScope()

So this API requires converting the { and } token positions to src.XPos before actually processing the contents within. I.e., it can register PosBases out of order.

This is problematic in practice for cgo, because it very heavily uses //line annotations. (To paraphrase Obi-Wan, "It's more pragma now, than code.")

I'm leaning towards changing the API to "openScope(start)" and "closeScope(end)" separately, which hopefully avoids the issue, but I worry there could still be other places where we Pos->XPos transform out of order.

@mdempsky mdempsky added this to the Go1.10 milestone May 18, 2017
@mdempsky
Copy link
Member Author

Discussed with @griesemer: not important for Go 1.9 (we can workaround it), but something to think about for 1.10.

@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 14, 2018
@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Unplanned Jun 14, 2018
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants