[go] go/build, cmd/go: use ast.ParseDirective for go:embed

1 view
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Oct 21, 2025, 5:49:19 PM (2 days ago) Oct 21
to Austin Clements, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Alan Donovan, golang-co...@googlegroups.com

Gopher Robot submitted the change with unreviewed changes

Unreviewed changes

1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: src/cmd/go/internal/modindex/build_read.go
Insertions: 2, Deletions: 2.

The diff is too large to show. Please review the diff.
```
```
The name of the file: src/go/build/read.go
Insertions: 2, Deletions: 2.

The diff is too large to show. Please review the diff.
```

Change information

Commit message:
go/build, cmd/go: use ast.ParseDirective for go:embed

Currently, "//go:embed" directives are read by bespoke parsers in
go/build and cmd/go/internal/modindex. Replace these bespoke parsers
with scanner.Scanner for finding these directives and
ast.ParseDirective for parsing them.

It's not clear why we had a bespoke parser just for finding
"//go:embed" directives in the first place. We have a bespoke parser
for reading imports in order to avoid having to read the entire source
file into memory, but if we're parsing embeds, we wind up reading the
entire source file into memory anyway. Using scanner.Scanner instead
eliminates some truly confusing code.

This also demonstrates that ast.ParseDirective as proposed in #68021
achieves useful API coverage.

Updates #68021.
Change-Id: Ieb68738121dcff605a6a704a8045ddd2ff35df35
Auto-Submit: Austin Clements <aus...@google.com>
Reviewed-by: Alan Donovan <adon...@google.com>
Files:
  • M src/cmd/go/internal/modindex/build_read.go
  • M src/go/build/read.go
Change size: L
Delta: 2 files changed, 88 insertions(+), 474 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Alan Donovan
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ieb68738121dcff605a6a704a8045ddd2ff35df35
Gerrit-Change-Number: 704836
Gerrit-PatchSet: 10
Gerrit-Owner: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages