From 68d9c0b785af40b28ff8a9ac074f2d4cf5deb48a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 18 Apr 2026 10:24:20 +0100 Subject: [PATCH] cue/ast: remove the deprecated File.Imports slice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The replacement, File.ImportSpecs, was added in mid 2025 alongside a deprecation and a `//go:fix inline` directive. This was all released with CUE v0.15.0 in November 2025. Now that we're working towards CUE v0.17.0, probably to be released around June 2026, it's time to remove this as planned. Signed-off-by: Daniel Martí Change-Id: Ib2d0d0d716ffffb3900a9739734948733a7b18bb Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1235757 Unity-Result: CUE porcuepine Reviewed-by: Matthew Sackman TryBot-Result: CUEcueckoo --- cue/ast/ast.go | 4 -- cue/ast/astutil/sanitize.go | 16 ++----- cue/build/instance_test.go | 1 - cue/parser/parser.go | 4 -- .../testdata/debugprint/file.txtar | 47 ------------------- 5 files changed, 5 insertions(+), 67 deletions(-) diff --git a/cue/ast/ast.go b/cue/ast/ast.go index d24b83550..a23671edd 100644 --- a/cue/ast/ast.go +++ b/cue/ast/ast.go @@ -1093,10 +1093,6 @@ type File struct { Filename string Decls []Decl // top-level declarations; or nil - // Deprecated: use [File.ImportSpecs]. - // TODO(mvdan): remove in mid 2026. - Imports []*ImportSpec // imports in this file - Unresolved []*Ident // unresolved identifiers in this file // TODO remove this field: it's here as a temporary diff --git a/cue/ast/astutil/sanitize.go b/cue/ast/astutil/sanitize.go index ae407fdd7..84538601e 100644 --- a/cue/ast/astutil/sanitize.go +++ b/cue/ast/astutil/sanitize.go @@ -17,6 +17,7 @@ package astutil import ( "fmt" "math/rand/v2" + "slices" "strings" "cuelang.org/go/cue/ast" @@ -171,19 +172,12 @@ func (z *sanitizer) markUsed(s *scope, n *ast.Ident) bool { } func (z *sanitizer) cleanImports() { - var fileImports []*ast.ImportSpec for decl := range z.file.ImportDecls() { - newLen := 0 - for _, spec := range decl.Specs { - if _, ok := z.referenced[spec]; ok { - fileImports = append(fileImports, spec) - decl.Specs[newLen] = spec - newLen++ - } - } - decl.Specs = decl.Specs[:newLen] + decl.Specs = slices.DeleteFunc(decl.Specs, func(spec *ast.ImportSpec) bool { + _, ok := z.referenced[spec] + return !ok + }) } - z.file.Imports = fileImports // Ensure that the first import always starts a new section // so that if the file has a comment, it won't be associated with // the import comment rather than the file. diff --git a/cue/build/instance_test.go b/cue/build/instance_test.go index 9d046969c..4e63a7a6b 100644 --- a/cue/build/instance_test.go +++ b/cue/build/instance_test.go @@ -44,7 +44,6 @@ func TestPartiallyResolved(t *testing.T) { Expr: &ast.Ident{Name: "bar", Node: spec2}, }, }, - Imports: []*ast.ImportSpec{spec1, spec2}, } p := &Instance{ diff --git a/cue/parser/parser.go b/cue/parser/parser.go index d344bdc33..e53b11412 100644 --- a/cue/parser/parser.go +++ b/cue/parser/parser.go @@ -72,8 +72,6 @@ type parser struct { // Non-syntactic parser control exprLev int // < 0: in control clause, >= 0: in expression - - imports []*ast.ImportSpec // list of imports } func (p *parser) init(filename string, src []byte, opts []Option) { @@ -1860,7 +1858,6 @@ func (p *parser) parseImportSpec(_ int) *ast.ImportSpec { Path: &ast.BasicLit{ValuePos: pos, Kind: token.STRING, Value: path}, } c.closeNode(p, spec) - p.imports = append(p.imports, spec) return spec } @@ -1978,7 +1975,6 @@ func (p *parser) parseFile() *ast.File { p.closeList() f := &ast.File{ - Imports: p.imports, Decls: decls, LanguageVersion: p.cfg.Version, } diff --git a/internal/astinternal/testdata/debugprint/file.txtar b/internal/astinternal/testdata/debugprint/file.txtar index 0abdcbcd6..5901f0ec2 100644 --- a/internal/astinternal/testdata/debugprint/file.txtar +++ b/internal/astinternal/testdata/debugprint/file.txtar @@ -100,33 +100,6 @@ import ( Rparen: token.Pos("imports.cue:8:1", newline) } } - Imports: []*ast.ImportSpec{ - { - Path: *ast.BasicLit{ - ValuePos: token.Pos("imports.cue:3:8", blank) - Kind: token.Token("STRING") - Value: "\"foo\"" - } - } - { - Path: *ast.BasicLit{ - ValuePos: token.Pos("imports.cue:6:2", newline) - Kind: token.Token("STRING") - Value: "\"bar\"" - } - } - { - Name: *ast.Ident{ - NamePos: token.Pos("imports.cue:7:2", newline) - Name: "name" - } - Path: *ast.BasicLit{ - ValuePos: token.Pos("imports.cue:7:7", blank) - Kind: token.Token("STRING") - Value: "\"baz\"" - } - } - } LanguageVersion: "v0.13.0" } -- out/debugprint/empty.cue/omitempty-strings -- @@ -199,25 +172,5 @@ import ( } } } - Imports: []*ast.ImportSpec{ - { - Path: *ast.BasicLit{ - Value: "\"foo\"" - } - } - { - Path: *ast.BasicLit{ - Value: "\"bar\"" - } - } - { - Name: *ast.Ident{ - Name: "name" - } - Path: *ast.BasicLit{ - Value: "\"baz\"" - } - } - } LanguageVersion: "v0.13.0" } -- 2.51.2