aboutsummaryrefslogtreecommitdiff
path: root/src/internal/pkgbits
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-08-04 10:32:51 -0700
committerMatthew Dempsky <mdempsky@google.com>2022-08-04 10:32:51 -0700
commita10afb15e060386615dcc0ecf2bd60ca3abbc04c (patch)
treea89e2d4e921b2b966aee9d86cbdd3d5ff9df01c7 /src/internal/pkgbits
parent85d87b9c7507628144db51bd1e7e80cc3afed128 (diff)
parentd558507db42d600e5ad82748bda0cb91df57b97d (diff)
downloadgo-a10afb15e060386615dcc0ecf2bd60ca3abbc04c.tar.xz
all: REVERSE MERGE dev.unified (d558507) into master
This commit is a REVERSE MERGE. It merges dev.unified back into its parent branch, master. This marks the end of development on dev.unified. Merge List: + 2022-08-04 d558507db4 [dev.unified] all: merge master (85d87b9) into dev.unified + 2022-08-03 c9f2150cfb [dev.unified] cmd/compile: start using runtime dictionaries + 2022-07-30 994ff78ba0 [dev.unified] go/internal: set underlying types in proper order + 2022-07-28 23554d4744 [dev.unified] all: merge master (462b78f) into dev.unified + 2022-07-28 c8d5ccf82e [dev.unified] go/internal/gcimporter: flatten imports + 2022-07-28 ac0844ec27 [dev.unified] cmd/compile: move "has init" to private metadata + 2022-07-28 f995946094 [dev.unified] cmd/compile: implement simple inline body pruning heuristic + 2022-07-28 f2851c67fd [dev.unified] cmd/compile: allow inlining to fail gracefully + 2022-07-28 831fdf1dff [dev.unified] cmd/compile: extract nil handling from exprType + 2022-07-28 92798176e7 [dev.unified] cmd/compile: write iface conversion RTTI into unified IR + 2022-07-28 9b70178d58 [dev.unified] cmd/compile: write RTTI into unified IR export data + 2022-07-25 fc72b7705d [dev.unified] cmd/compile: add method expressions to dictionaries + 2022-07-25 f48fa643f1 [dev.unified] cmd/compile: remove obsolete RTTI wiring + 2022-07-22 131f981df0 [dev.unified] cmd/compile: make Unified IR always writes concrete type for const exprs + 2022-07-20 ae43bdc3e3 Merge "[dev.unified] all: merge master (8e1e64c) into dev.unified" into dev.unified + 2022-07-19 7a8ba83b72 [dev.unified] cmd/compile/internal/reflectdata: remove hasRType's `required` param + 2022-07-19 64cd6faa13 [dev.unified] cmd/compile/internal/noder: simplify mixed tag/case RTTI wiring + 2022-07-19 a4c5198a3c [dev.unified] cmd/compile/internal/noder: better switch statements + 2022-07-19 318027044a [dev.unified] cmd/compile/internal/noder: explicit nil handling + 2022-07-19 e971b6a9be [dev.unified] test: add switch test case for tricky nil handling + 2022-07-19 878439cfe5 [dev.unified] cmd/compile/internal/noder: preserve RTTI for select statements + 2022-07-19 e376746e54 [dev.unified] cmd/compile/internal/noder: wire RTTI for implicit conversions + 2022-07-19 c846fd8e13 [dev.unified] cmd/compile/internal/noder: implicit conversions for binary exprs + 2022-07-19 ebd34e3e45 [dev.unified] test: relax panic message expectations + 2022-07-19 76a82f09d6 [dev.unified] cmd/compile/internal/noder: prefer *At functions + 2022-07-19 de649a2a98 [dev.unified] all: merge master (8e1e64c) into dev.unified + 2022-07-19 055a5e55fa [dev.unified] test: change Unicode file/package name to use characters not translated by macOS. + 2022-07-18 2cf632cd57 [dev.unified] cmd/compile/internal/reflectdata: prefer ITabAddrAt in ConvIfaceTypeWord + 2022-07-12 9371a65584 internal/pkgbits: change EnableSync into a dynamic knob + 2022-07-01 d667be8831 [dev.unified] cmd/compile/internal/walk: RType fields for range assignments + 2022-06-30 1b838e9556 [dev.unified] all: merge master (993c387) into dev.unified + 2022-06-30 0a503cf43a [dev.unified] cmd/compile: refactor `range` desugaring + 2022-06-30 3635b07d16 [dev.unified] cmd/compile/internal/noder: implicit conversions for multi-valued expressions + 2022-06-30 e7219cc093 [dev.unified] cmd/compile/internal/noder: refactor N:1 expression handling + 2022-06-30 2f3ef73e18 [dev.unified] test: tweak nilcheck test + 2022-06-30 95d7ce9ab1 [dev.unified] test: break escape_iface.go into unified/nounified variants + 2022-06-30 f751319a0b [dev.unified] test: relax live_regabi.go + 2022-06-30 e3cdc981c8 [dev.unified] cmd/compile/internal/walk: fix typo in debug print + 2022-06-29 2280d897d6 [dev.unified] test: add regress test for generic select statements + 2022-06-27 4b78ece3d7 [dev.unified] cmd/compile: drop package height from Unified IR importer + 2022-06-27 398d46d538 [dev.unified] cmd/compile/internal/types2: remove package height + 2022-06-24 e7100adbca [dev.unified] all: merge master (5a1c5b8) into dev.unified + 2022-06-23 09a838ad86 [dev.unified] cmd/compile: rename haveRType and implicitExpr + 2022-06-23 421e9e9db2 [dev.unified] cmd/compile: implicit conversions for return statements + 2022-06-23 a3fea7796a [dev.unified] cmd/compile/internal/noder: implicit conversions for writer.assignStmt + 2022-06-23 82a958a661 [dev.unified] cmd/compile/internal/noder: refactor stmtAssign generation + 2022-06-23 711dacd8cf [dev.unified] cmd/compile/internal/noder: implicit conversion of call arguments + 2022-06-23 46b01ec667 [dev.unified] cmd/compile/internal/noder: remove needType logic + 2022-06-23 a3e474f867 [dev.unified] cmd/compile/internal/noder: implicit conversions for complits + 2022-06-23 5f5422a2dd [dev.unified] cmd/compile/internal/noder: start writing implicit conversions + 2022-06-23 9cb784ac69 [dev.unified] cmd/compile/internal/noder: add pkgWriter.typeOf helper + 2022-06-23 c70e93ff3d [dev.unified] cmd/compile/internal/typecheck: replace unreachable code with assert + 2022-06-23 20e1d5ac8c [dev.unified] cmd/compile: special case f(g()) calls in Unified IR + 2022-06-23 61ae2b734c [dev.unified] cmd/compile: plumb rtype through OSWITCH/OCASE clauses + 2022-06-23 3d432b6c4b [dev.unified] cmd/compile: plumb rtype through for OMAPLIT + 2022-06-23 7368647ac6 [dev.unified] cmd/compile: start setting RType fields for Unified IR + 2022-06-23 5960f4ec10 [dev.unified] cmd/compile: add RType fields + 2022-06-21 5e0258c700 [dev.unified] cmd/compile: avoid reflectType in ssagen + 2022-06-21 93833cd5d8 [dev.unified] cmd/compile: extract rtype code from walk + 2022-06-21 f70775ff22 [dev.unified] cmd/compile: refactor reflectdata.{TypePtr,ITabAddr} + 2022-06-21 fc5dad6646 [dev.unified] cmd/compile/internal/walk: minor prep refactoring + 2022-06-16 1f4e8afafe [dev.unified] all: merge master (635b124) into dev.unified + 2022-06-15 8a9485c023 [dev.unified] test: extract different inline test between unified and non-unified + 2022-06-14 394ea70cc9 [dev.unified] cmd/compile: more Unified IR docs and review + 2022-06-10 f73ad3d24d [dev.unified] test: add regress tests for #53276 and #53328 + 2022-06-09 8ef8b60e18 [dev.unified] cmd/compile/internal/noder: stop handling type expressions as expressions + 2022-06-09 1a6c96bb9b [dev.unified] test: relax issue7921.go diagnostic message + 2022-06-09 c50c6bbc03 [dev.unified] cmd/compile: set base.Pos when process assignDef in Unified IR + 2022-06-09 d6df08693c [dev.unified] cmd/compile: fix unified IR don't report type size too large error + 2022-06-08 e7ef58542c [dev.unified] cmd/compile: restore Unified IR linkname pragma diagnostic + 2022-06-07 9e5c968021 [dev.unified] cmd/compile: visit LHS before RHS/X in assign/for statement + 2022-06-06 46ddf0873e [dev.unified] cmd/compile: export/import implicit attribute for conversion exprs + 2022-06-06 a8780f94c3 [dev.unified] cmd/compile: fix missing method value wrapper in unified IR + 2022-06-06 3a1f1e1575 [dev.unified] cmd/compile: remove package height + 2022-06-06 df7cb59de4 [dev.unified] cmd/compile: only sort symbols by name and package path + 2022-06-06 b39ac80871 [dev.unified] cmd/compile/internal/noder: push exprBlank up into assignment handling + 2022-06-06 55fc07e164 [dev.unified] cmd/compile/internal/noder: add optExpr for optional expressions + 2022-06-06 6c33f1d52e [dev.unified] cmd/compile/internal/noder: rename exprName to exprGlobal + 2022-06-06 4d28fcabb4 [dev.unified] all: update codereview.cfg for dev.unified branch Change-Id: I604d057735e8a365621c91c206f9e46eabb4679b
Diffstat (limited to 'src/internal/pkgbits')
-rw-r--r--src/internal/pkgbits/decoder.go26
-rw-r--r--src/internal/pkgbits/encoder.go36
-rw-r--r--src/internal/pkgbits/flags.go9
-rw-r--r--src/internal/pkgbits/sync.go16
-rw-r--r--src/internal/pkgbits/syncmarker_string.go61
5 files changed, 99 insertions, 49 deletions
diff --git a/src/internal/pkgbits/decoder.go b/src/internal/pkgbits/decoder.go
index 0b5fd9705c..5e233b8770 100644
--- a/src/internal/pkgbits/decoder.go
+++ b/src/internal/pkgbits/decoder.go
@@ -18,6 +18,12 @@ import (
// A PkgDecoder provides methods for decoding a package's Unified IR
// export data.
type PkgDecoder struct {
+ // version is the file format version.
+ version uint32
+
+ // sync indicates whether the file uses sync markers.
+ sync bool
+
// pkgPath is the package path for the package to be decoded.
//
// TODO(mdempsky): Remove; unneeded since CL 391014.
@@ -52,6 +58,9 @@ type PkgDecoder struct {
// TODO(mdempsky): Remove; unneeded since CL 391014.
func (pr *PkgDecoder) PkgPath() string { return pr.pkgPath }
+// SyncMarkers reports whether pr uses sync markers.
+func (pr *PkgDecoder) SyncMarkers() bool { return pr.sync }
+
// NewPkgDecoder returns a PkgDecoder initialized to read the Unified
// IR export data from input. pkgPath is the package path for the
// compilation unit that produced the export data.
@@ -67,9 +76,18 @@ func NewPkgDecoder(pkgPath, input string) PkgDecoder {
r := strings.NewReader(input)
- var version uint32
- assert(binary.Read(r, binary.LittleEndian, &version) == nil)
- assert(version == 0)
+ assert(binary.Read(r, binary.LittleEndian, &pr.version) == nil)
+
+ switch pr.version {
+ default:
+ panic(fmt.Errorf("unsupported version: %v", pr.version))
+ case 0:
+ // no flags
+ case 1:
+ var flags uint32
+ assert(binary.Read(r, binary.LittleEndian, &flags) == nil)
+ pr.sync = flags&flagSyncMarkers != 0
+ }
assert(binary.Read(r, binary.LittleEndian, pr.elemEndsEnds[:]) == nil)
@@ -215,7 +233,7 @@ func (r *Decoder) rawReloc(k RelocKind, idx int) Index {
//
// If EnableSync is false, then Sync is a no-op.
func (r *Decoder) Sync(mWant SyncMarker) {
- if !EnableSync {
+ if !r.common.sync {
return
}
diff --git a/src/internal/pkgbits/encoder.go b/src/internal/pkgbits/encoder.go
index 1326a135cf..ec47e352cb 100644
--- a/src/internal/pkgbits/encoder.go
+++ b/src/internal/pkgbits/encoder.go
@@ -14,6 +14,16 @@ import (
"runtime"
)
+// currentVersion is the current version number.
+//
+// - v0: initial prototype
+//
+// - v1: adds the flags uint32 word
+//
+// TODO(mdempsky): For the next version bump:
+// - remove the legacy "has init" bool from the public root
+const currentVersion uint32 = 1
+
// A PkgEncoder provides methods for encoding a package's Unified IR
// export data.
type PkgEncoder struct {
@@ -25,15 +35,21 @@ type PkgEncoder struct {
// elems[RelocString][stringsIdx[s]] == s (if present).
stringsIdx map[string]Index
+ // syncFrames is the number of frames to write at each sync
+ // marker. A negative value means sync markers are omitted.
syncFrames int
}
+// SyncMarkers reports whether pw uses sync markers.
+func (pw *PkgEncoder) SyncMarkers() bool { return pw.syncFrames >= 0 }
+
// NewPkgEncoder returns an initialized PkgEncoder.
//
// syncFrames is the number of caller frames that should be serialized
// at Sync points. Serializing additional frames results in larger
// export data files, but can help diagnosing desync errors in
-// higher-level Unified IR reader/writer code.
+// higher-level Unified IR reader/writer code. If syncFrames is
+// negative, then sync markers are omitted entirely.
func NewPkgEncoder(syncFrames int) PkgEncoder {
return PkgEncoder{
stringsIdx: make(map[string]Index),
@@ -51,7 +67,13 @@ func (pw *PkgEncoder) DumpTo(out0 io.Writer) (fingerprint [8]byte) {
assert(binary.Write(out, binary.LittleEndian, x) == nil)
}
- writeUint32(0) // version
+ writeUint32(currentVersion)
+
+ var flags uint32
+ if pw.SyncMarkers() {
+ flags |= flagSyncMarkers
+ }
+ writeUint32(flags)
// Write elemEndsEnds.
var sum uint32
@@ -204,7 +226,7 @@ func (w *Encoder) rawReloc(r RelocKind, idx Index) int {
}
func (w *Encoder) Sync(m SyncMarker) {
- if !EnableSync {
+ if !w.p.SyncMarkers() {
return
}
@@ -297,8 +319,14 @@ func (w *Encoder) Code(c Code) {
// section (if not already present), and then writing a relocation
// into the element bitstream.
func (w *Encoder) String(s string) {
+ w.StringRef(w.p.StringIdx(s))
+}
+
+// StringRef writes a reference to the given index, which must be a
+// previously encoded string value.
+func (w *Encoder) StringRef(idx Index) {
w.Sync(SyncString)
- w.Reloc(RelocString, w.p.StringIdx(s))
+ w.Reloc(RelocString, idx)
}
// Strings encodes and writes a variable-length slice of strings into
diff --git a/src/internal/pkgbits/flags.go b/src/internal/pkgbits/flags.go
new file mode 100644
index 0000000000..654222745f
--- /dev/null
+++ b/src/internal/pkgbits/flags.go
@@ -0,0 +1,9 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package pkgbits
+
+const (
+ flagSyncMarkers = 1 << iota // file format contains sync markers
+)
diff --git a/src/internal/pkgbits/sync.go b/src/internal/pkgbits/sync.go
index 72f776af05..1520b73afb 100644
--- a/src/internal/pkgbits/sync.go
+++ b/src/internal/pkgbits/sync.go
@@ -10,17 +10,6 @@ import (
"strings"
)
-// EnableSync controls whether sync markers are written into unified
-// IR's export data format and also whether they're expected when
-// reading them back in. They're inessential to the correct
-// functioning of unified IR, but are helpful during development to
-// detect mistakes.
-//
-// When sync is enabled, writer stack frames will also be included in
-// the export data. Currently, a fixed number of frames are included,
-// controlled by -d=syncframes (default 0).
-const EnableSync = true
-
// fmtFrames formats a backtrace for reporting reader/writer desyncs.
func fmtFrames(pcs ...uintptr) []string {
res := make([]string, 0, len(pcs))
@@ -109,6 +98,7 @@ const (
SyncExprs
SyncExpr
SyncExprType
+ SyncAssign
SyncOp
SyncFuncLit
SyncCompLit
@@ -139,4 +129,8 @@ const (
SyncStmtsEnd
SyncLabel
SyncOptLabel
+
+ SyncMultiExpr
+ SyncRType
+ SyncConvRTTI
)
diff --git a/src/internal/pkgbits/syncmarker_string.go b/src/internal/pkgbits/syncmarker_string.go
index 39db9eddad..4a5b0ca5f2 100644
--- a/src/internal/pkgbits/syncmarker_string.go
+++ b/src/internal/pkgbits/syncmarker_string.go
@@ -45,39 +45,40 @@ func _() {
_ = x[SyncExprs-35]
_ = x[SyncExpr-36]
_ = x[SyncExprType-37]
- _ = x[SyncOp-38]
- _ = x[SyncFuncLit-39]
- _ = x[SyncCompLit-40]
- _ = x[SyncDecl-41]
- _ = x[SyncFuncBody-42]
- _ = x[SyncOpenScope-43]
- _ = x[SyncCloseScope-44]
- _ = x[SyncCloseAnotherScope-45]
- _ = x[SyncDeclNames-46]
- _ = x[SyncDeclName-47]
- _ = x[SyncStmts-48]
- _ = x[SyncBlockStmt-49]
- _ = x[SyncIfStmt-50]
- _ = x[SyncForStmt-51]
- _ = x[SyncSwitchStmt-52]
- _ = x[SyncRangeStmt-53]
- _ = x[SyncCaseClause-54]
- _ = x[SyncCommClause-55]
- _ = x[SyncSelectStmt-56]
- _ = x[SyncDecls-57]
- _ = x[SyncLabeledStmt-58]
- _ = x[SyncUseObjLocal-59]
- _ = x[SyncAddLocal-60]
- _ = x[SyncLinkname-61]
- _ = x[SyncStmt1-62]
- _ = x[SyncStmtsEnd-63]
- _ = x[SyncLabel-64]
- _ = x[SyncOptLabel-65]
+ _ = x[SyncAssign-38]
+ _ = x[SyncOp-39]
+ _ = x[SyncFuncLit-40]
+ _ = x[SyncCompLit-41]
+ _ = x[SyncDecl-42]
+ _ = x[SyncFuncBody-43]
+ _ = x[SyncOpenScope-44]
+ _ = x[SyncCloseScope-45]
+ _ = x[SyncCloseAnotherScope-46]
+ _ = x[SyncDeclNames-47]
+ _ = x[SyncDeclName-48]
+ _ = x[SyncStmts-49]
+ _ = x[SyncBlockStmt-50]
+ _ = x[SyncIfStmt-51]
+ _ = x[SyncForStmt-52]
+ _ = x[SyncSwitchStmt-53]
+ _ = x[SyncRangeStmt-54]
+ _ = x[SyncCaseClause-55]
+ _ = x[SyncCommClause-56]
+ _ = x[SyncSelectStmt-57]
+ _ = x[SyncDecls-58]
+ _ = x[SyncLabeledStmt-59]
+ _ = x[SyncUseObjLocal-60]
+ _ = x[SyncAddLocal-61]
+ _ = x[SyncLinkname-62]
+ _ = x[SyncStmt1-63]
+ _ = x[SyncStmtsEnd-64]
+ _ = x[SyncLabel-65]
+ _ = x[SyncOptLabel-66]
}
-const _SyncMarker_name = "EOFBoolInt64Uint64StringValueValRelocsRelocUseRelocPublicPosPosBaseObjectObject1PkgPkgDefMethodTypeTypeIdxTypeParamNamesSignatureParamsParamCodeObjSymLocalIdentSelectorPrivateFuncExtVarExtTypeExtPragmaExprListExprsExprAssertTypeOpFuncLitCompLitDeclFuncBodyOpenScopeCloseScopeCloseAnotherScopeDeclNamesDeclNameStmtsBlockStmtIfStmtForStmtSwitchStmtRangeStmtCaseClauseCommClauseSelectStmtDeclsLabeledStmtUseObjLocalAddLocalLinknameStmt1StmtsEndLabelOptLabel"
+const _SyncMarker_name = "EOFBoolInt64Uint64StringValueValRelocsRelocUseRelocPublicPosPosBaseObjectObject1PkgPkgDefMethodTypeTypeIdxTypeParamNamesSignatureParamsParamCodeObjSymLocalIdentSelectorPrivateFuncExtVarExtTypeExtPragmaExprListExprsExprExprTypeAssignOpFuncLitCompLitDeclFuncBodyOpenScopeCloseScopeCloseAnotherScopeDeclNamesDeclNameStmtsBlockStmtIfStmtForStmtSwitchStmtRangeStmtCaseClauseCommClauseSelectStmtDeclsLabeledStmtUseObjLocalAddLocalLinknameStmt1StmtsEndLabelOptLabel"
-var _SyncMarker_index = [...]uint16{0, 3, 7, 12, 18, 24, 29, 32, 38, 43, 51, 57, 60, 67, 73, 80, 83, 89, 95, 99, 106, 120, 129, 135, 140, 147, 150, 160, 168, 175, 182, 188, 195, 201, 209, 214, 218, 228, 230, 237, 244, 248, 256, 265, 275, 292, 301, 309, 314, 323, 329, 336, 346, 355, 365, 375, 385, 390, 401, 412, 420, 428, 433, 441, 446, 454}
+var _SyncMarker_index = [...]uint16{0, 3, 7, 12, 18, 24, 29, 32, 38, 43, 51, 57, 60, 67, 73, 80, 83, 89, 95, 99, 106, 120, 129, 135, 140, 147, 150, 160, 168, 175, 182, 188, 195, 201, 209, 214, 218, 226, 232, 234, 241, 248, 252, 260, 269, 279, 296, 305, 313, 318, 327, 333, 340, 350, 359, 369, 379, 389, 394, 405, 416, 424, 432, 437, 445, 450, 458}
func (i SyncMarker) String() string {
i -= 1