From 76136be02701aab8a4b546956f1847d28dbe0ba2 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sun, 27 Dec 2020 11:26:12 -0800 Subject: [PATCH] [dev.regabi] cmd/compile: check for recursive import in ImportBody After earlier importer refactorings, most of the importer is now reentrant, so we don't need to guard against it at Resolve. The only remaining part that is still not reentrant is inline body importing, so move the recursive-import check there. Passes toolstash -cmp. Change-Id: Ia828f880a03e6125b102668c12a155d4c253d26b Reviewed-on: https://go-review.googlesource.com/c/go/+/280515 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/typecheck/iimport.go | 5 +++++ src/cmd/compile/internal/typecheck/typecheck.go | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index cf2cf87492..546ddcba79 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -71,7 +71,12 @@ func ImportBody(fn *ir.Func) { base.Fatalf("missing import reader for %v", fn) } + if inimport { + base.Fatalf("recursive inimport") + } + inimport = true r.doInline(fn) + inimport = false } func importReaderFor(sym *types.Sym, importers map[*types.Sym]iimporterAndOffset) *importReader { diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index dabfee3bf9..e23c249ff2 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -251,13 +251,7 @@ func Resolve(n ir.Node) (res ir.Node) { } } - if inimport { - base.Fatalf("recursive inimport") - } - inimport = true - n = expandDecl(n) - inimport = false - return n + return expandDecl(n) } r := ir.AsNode(n.Sym().Def) -- 2.48.1