Skip to content

Commit

Permalink
cmd/go/internal/modindex: update index_format.txt
Browse files Browse the repository at this point in the history
This incorporates the changes from CL 453603 and CL 416178.

Please review carefully: I did my best to read through the CLs, but
I'm not entirely confident I haven't made a mistake.

Fixes #59770.

Change-Id: Ib8937e55dcd11e3f75c16b28519d3d91df1d4da3
Reviewed-on: https://go-review.googlesource.com/c/go/+/492596
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed May 13, 2023
1 parent db22489 commit 91b8cc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/cmd/go/internal/modindex/index_format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ The index format is an encoding of a series of RawPackage structs

Field names refer to fields on RawPackage and rawFile.
The file uses little endian encoding for the uint32s.
Strings are written into the string table at the end of the file. Each string
is null-terminated. String offsets are relative to the start of the string table.
Strings are written into the string table at the end of the file.
Each string is prefixed with a uvarint-encoded length.
Bools are written as uint32s: 0 for false and 1 for true.

The following is the format for a full module:

“go index v0\n”
“go index v2\n”
str uint32 - offset of string table
n uint32 - number of packages
dirnames [n]uint32 - offsets to package names in string table; names sorted by raw string
packages [n]uint32 - offset where package begins
for each RawPackage:
for each rawPackage:
dirname - string offset
package - offset where package begins
for each rawPackage:
error uint32 - string offset // error is produced by fsys.ReadDir or fmt.Errorf
dir uint32 - string offset (directory path relative to module root)
len(sourceFiles) uint32
Expand All @@ -35,11 +36,16 @@ for each RawPackage:
for each rawImport:
path - string offset
position - file, offset, line, column - uint32
len(embeds) numEmbeds uint32
len(embeds) uint32
for each embed:
pattern - string offset
position - file, offset, line, column - uint32
len(directives) uint32
for each directive:
text - string offset
position - file, offset, line, column - uint32
[string table]
0xFF (marker)

The following is the format for a single indexed package:

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modindex/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ func (sf *sourceFile) embedsOffset() int {
func (sf *sourceFile) directivesOffset() int {
pos := sf.embedsOffset()
n := sf.d.intAt(pos)
// each import is 5 uint32s (string + tokpos)
// each embed is 5 uint32s (string + tokpos)
return pos + 4 + n*(4*5)
}

Expand Down

0 comments on commit 91b8cc0

Please sign in to comment.