]> Cypherpunks repositories - gostls13.git/commit
go/parser: switch to resolving objects as a post-processing pass
authorRob Findley <rfindley@google.com>
Wed, 24 Mar 2021 13:36:04 +0000 (09:36 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 31 Mar 2021 20:13:06 +0000 (20:13 +0000)
commit4acefa07b1499b063e1ff63c9d4cab7b7f8d49a2
tree7da459d52edf62500eaa4f5dc11dde4c5f911cdb
parent44dd06670f522e66e7ebfa0bffe14d2b44c93ff8
go/parser: switch to resolving objects as a post-processing pass

Coupling object resolution to parsing complicates the parsing code, and
is a barrier to improvement. It requires passing around context such as
'lhs' or 'keyOk', and even then sometimes requires guess-work, such as
whether to resolve the key in a composite literal.

In this CL we delay object resolution to a separate pass after the file
parse completes. This makes it easier to see logic of scoping, and
removes state from the parsing code. This can enable subsequent
improvements such as optionally skipping object resolution, aligning the
parser with cmd/compile/internal/syntax, and allowing alternative
parsers to reuse object resolution.

The additional AST traversal appears to slow down parsing by around 4%.
That seems small enough not to worry about, especially since performance
sensitive users may eventually be able to disable object resolution
entirely, saving around 18% off the previous baseline. I'll also mail a
speculative CL showing how we can significantly mitigate the cost of
object resolution by transposing scopes.

For #45104

Change-Id: I98d9143fd77ae29e84ec7c3ae2fdb1139510da37
Reviewed-on: https://go-review.googlesource.com/c/go/+/304455
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/parser/interface.go
src/go/parser/parser.go
src/go/parser/resolver.go [new file with mode: 0644]