Skip to content

Commit

Permalink
internal: phase out PkgInfo.IsAnonymous
Browse files Browse the repository at this point in the history
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í <[email protected]>
Change-Id: If8e19bbb6d28d0cd91bfd157d53e49cd736c31e2
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200970
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mvdan committed Sep 12, 2024
1 parent d34eb57 commit 44b4ab5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/core/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions internal/core/runtime/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 44b4ab5

Please sign in to comment.