Skip to content

Commit feec53c

Browse files
committed
[dev.typeparams] cmd/compile: skip types2 GC test during bootstrapping
Unified includes a check to make sure that types2 memory has been garbage collected, but it relies on precise finalization, which we provide (for dynamically allocated objects, at least) but isn't guaranteed by the Go spec. In particular, Go 1.4 doesn't provide this. The check is strictly unnecessary and only exists to make sure we don't regress and start holding onto types2 memory accidentally. So just disable the check during bootstrap builds. Change-Id: Ie54fe53b2edba02c0b0b1e5ae39d81be8a0ace8d Reviewed-on: https://go-review.googlesource.com/c/go/+/329269 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
1 parent fb84d21 commit feec53c

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build !compiler_bootstrap
6+
7+
package base
8+
9+
// CompilerBootstrap reports whether the current compiler binary was
10+
// built with -tags=compiler_bootstrap.
11+
const CompilerBootstrap = false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build compiler_bootstrap
6+
7+
package base
8+
9+
// CompilerBootstrap reports whether the current compiler binary was
10+
// built with -tags=compiler_bootstrap.
11+
const CompilerBootstrap = true

src/cmd/compile/internal/noder/unified.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ func writePkgStub(noders []*noder) string {
161161

162162
// freePackage ensures the given package is garbage collected.
163163
func freePackage(pkg *types2.Package) {
164+
// The GC test below relies on a precise GC that runs finalizers as
165+
// soon as objects are unreachable. Our implementation provides
166+
// this, but other/older implementations may not (e.g., Go 1.4 does
167+
// not because of #22350). To avoid imposing unnecessary
168+
// restrictions on the GOROOT_BOOTSTRAP toolchain, we skip the test
169+
// during bootstrapping.
170+
if base.CompilerBootstrap {
171+
return
172+
}
173+
164174
// Set a finalizer on pkg so we can detect if/when it's collected.
165175
done := make(chan struct{})
166176
runtime.SetFinalizer(pkg, func(*types2.Package) { close(done) })

0 commit comments

Comments
 (0)