From 44b4ab55d973296760a6bfc180c9911f0c9dccef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 10 Sep 2024 17:59:21 +0100 Subject: [PATCH] internal: phase out PkgInfo.IsAnonymous MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Its logic can be very easily replicated with ast.File.PackageName, which already treats "_" as equal to a missing package name. Signed-off-by: Daniel Martí Change-Id: If8e19bbb6d28d0cd91bfd157d53e49cd736c31e2 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200970 TryBot-Result: CUEcueckoo Reviewed-by: Roger Peppe Unity-Result: CUE porcuepine --- internal/core/compile/compile.go | 2 +- internal/core/runtime/resolve.go | 5 ++--- internal/internal.go | 5 ----- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/internal/core/compile/compile.go b/internal/core/compile/compile.go index a812b6803d1..9c530ef5cc6 100644 --- a/internal/core/compile/compile.go +++ b/internal/core/compile/compile.go @@ -275,7 +275,7 @@ func (c *compiler) compileFiles(a []*ast.File) *adt.Vertex { // Or value? // - anything in an anonymous file // for _, f := range a { - if p := internal.GetPackageInfo(f); p.IsAnonymous() { + if f.PackageName() == "" { continue } for _, d := range f.Decls { diff --git a/internal/core/runtime/resolve.go b/internal/core/runtime/resolve.go index 59ab5f224d5..843245864b4 100644 --- a/internal/core/runtime/resolve.go +++ b/internal/core/runtime/resolve.go @@ -21,7 +21,6 @@ import ( "cuelang.org/go/cue/ast" "cuelang.org/go/cue/build" "cuelang.org/go/cue/errors" - "cuelang.org/go/internal" ) // TODO(resolve): this is also done in compile, do we need both? @@ -32,7 +31,7 @@ func (r *Runtime) ResolveFiles(p *build.Instance) (errs errors.Error) { // may be linked to any top-level entry of any of the files. allFields := map[string]ast.Node{} for _, f := range p.Files { - if p := internal.GetPackageInfo(f); p.IsAnonymous() { + if f.PackageName() == "" { continue } for _, d := range f.Decls { @@ -44,7 +43,7 @@ func (r *Runtime) ResolveFiles(p *build.Instance) (errs errors.Error) { } } for _, f := range p.Files { - if p := internal.GetPackageInfo(f); p.IsAnonymous() { + if f.PackageName() == "" { continue } err := resolveFile(idx, f, p, allFields) diff --git a/internal/internal.go b/internal/internal.go index bb459deade6..e70008fbbf6 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -138,11 +138,6 @@ type PkgInfo struct { Name string } -// IsAnonymous reports whether the package is anonymous. -func (p *PkgInfo) IsAnonymous() bool { - return p.Name == "" || p.Name == "_" -} - func GetPackageInfo(f *ast.File) PkgInfo { for i, d := range f.Decls { switch x := d.(type) {