···7575 freeze bool
7676}
77777878+const sharedOffset = 0x40000000
7979+7880// sharedIndex is used for indexing builtins and any other labels common to
7981// all instances.
8082var sharedIndex = newSharedIndex(token.NewFileSet())
81838284func newSharedIndex(f *token.FileSet) *index {
8585+ // TODO: nasty hack to indicate FileSet of shared index. Remove the whole
8686+ // FileSet idea from the API. Just take the hit of the extra pointers for
8787+ // positions in the ast, and then optimize the storage in an abstract
8888+ // machine implementation for storing graphs.
8989+ f.AddFile("dummy", sharedOffset, 0)
8390 i := &index{
8491 fset: f,
8592 labelMap: map[string]label{"": 0},
+3-3
cue/builtin.go
···6161 cue string
6262}
63636464-func mustCompileBuiltins(ctx *context, p *builtinPkg) *structLit {
6464+func mustCompileBuiltins(ctx *context, p *builtinPkg, name string) *structLit {
6565 obj := &structLit{}
6666 for _, b := range p.native {
6767 f := ctx.label(b.Name, false) // never starts with _
···76767777 // Parse builtin CUE
7878 if p.cue != "" {
7979- expr, err := parser.ParseExpr(ctx.index.fset, "<builtinPkg>", p.cue)
7979+ expr, err := parser.ParseExpr(ctx.index.fset, name, p.cue)
8080 if err != nil {
8181 fmt.Println(p.cue)
8282 panic(err)
···232232func initBuiltins(pkgs map[string]*builtinPkg) {
233233 ctx := sharedIndex.newContext()
234234 for k, b := range pkgs {
235235- e := mustCompileBuiltins(ctx, b)
235235+ e := mustCompileBuiltins(ctx, b, k)
236236 builtins[k] = e
237237 builtins["-/"+path.Base(k)] = e
238238 }
+8-2
cue/errors.go
···89899090func appendPositions(pos []token.Position, fset *token.FileSet, src source) []token.Position {
9191 if src != nil {
9292- if src.Pos() != token.NoPos {
9292+ if p := src.Pos(); p != token.NoPos {
9393+ if p >= sharedOffset {
9494+ fset = sharedIndex.fset
9595+ }
9396 return append(pos, fset.Position(src.Pos()))
9497 }
9598 if c := src.computed(); c != nil {
···119122120123func appendLocations(locs []string, fset *token.FileSet, src source) []string {
121124 if src != nil {
122122- if src.Pos() != token.NoPos {
125125+ if p := src.Pos(); p != token.NoPos {
126126+ if p >= sharedOffset {
127127+ fset = sharedIndex.fset
128128+ }
123129 return append(locs, fset.Position(src.Pos()).String())
124130 }
125131 if c := src.computed(); c != nil {