Skip to content

Commit 7bfeb43

Browse files
committed
cmd/go: refactor usage of initialized
This commit refactors usage of the global variable `initialized` to the global LoaderState field of the same name. This commit is part of the overall effort to eliminate global modloader state. [git-generate] cd src/cmd/go/internal/modload rf 'ex { initialized -> LoaderState.initialized }' rf 'rm initialized' Change-Id: I97e35bab00f4c22661670b01b69425fc25efe6df Reviewed-on: https://go-review.googlesource.com/c/go/+/698056 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 1d62e92 commit 7bfeb43

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/cmd/go/internal/modload/init.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ var (
6060

6161
// Variables set in Init.
6262
var (
63-
initialized bool
6463

6564
// These are primarily used to initialize the MainModules, and should be
6665
// eventually superseded by them but are still used in cases where the module
@@ -406,15 +405,15 @@ func Reset() {
406405

407406
func setState(s State) State {
408407
oldState := State{
409-
initialized: initialized,
408+
initialized: LoaderState.initialized,
410409
forceUseModules: ForceUseModules,
411410
rootMode: RootMode,
412411
modRoots: modRoots,
413412
modulesEnabled: cfg.ModulesEnabled,
414413
mainModules: MainModules,
415414
requirements: requirements,
416415
}
417-
initialized = s.initialized
416+
LoaderState.initialized = s.initialized
418417
ForceUseModules = s.forceUseModules
419418
RootMode = s.rootMode
420419
modRoots = s.modRoots
@@ -450,10 +449,10 @@ var LoaderState = NewState()
450449
// configures the cfg, codehost, load, modfetch, and search packages for use
451450
// with modules.
452451
func Init() {
453-
if initialized {
452+
if LoaderState.initialized {
454453
return
455454
}
456-
initialized = true
455+
LoaderState.initialized = true
457456

458457
fips140.Init()
459458

@@ -573,7 +572,7 @@ func WillBeEnabled() bool {
573572
// Already enabled.
574573
return true
575574
}
576-
if initialized {
575+
if LoaderState.initialized {
577576
// Initialized, not enabled.
578577
return false
579578
}
@@ -640,7 +639,7 @@ func VendorDir() string {
640639
}
641640

642641
func inWorkspaceMode() bool {
643-
if !initialized {
642+
if !LoaderState.initialized {
644643
panic("inWorkspaceMode called before modload.Init called")
645644
}
646645
if !Enabled() {
@@ -1253,7 +1252,7 @@ func fixVersion(ctx context.Context, fixed *bool) modfile.VersionFixer {
12531252
// This function affects the default cfg.BuildMod when outside of a module,
12541253
// so it can only be called prior to Init.
12551254
func AllowMissingModuleImports() {
1256-
if initialized {
1255+
if LoaderState.initialized {
12571256
panic("AllowMissingModuleImports after Init")
12581257
}
12591258
allowMissingModuleImports = true

0 commit comments

Comments
 (0)