this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue: fix file offsets for shared builtins

Change-Id: I289e1b7fe9ba17f6aedbb9346db6223e8ac59b02
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1921
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>

authored by

Marcel van Lohuizen and committed by
Marcel van Lohuizen
46103919 a460fe84

+18 -5
+7
cue/build.go
··· 75 75 freeze bool 76 76 } 77 77 78 + const sharedOffset = 0x40000000 79 + 78 80 // sharedIndex is used for indexing builtins and any other labels common to 79 81 // all instances. 80 82 var sharedIndex = newSharedIndex(token.NewFileSet()) 81 83 82 84 func newSharedIndex(f *token.FileSet) *index { 85 + // TODO: nasty hack to indicate FileSet of shared index. Remove the whole 86 + // FileSet idea from the API. Just take the hit of the extra pointers for 87 + // positions in the ast, and then optimize the storage in an abstract 88 + // machine implementation for storing graphs. 89 + f.AddFile("dummy", sharedOffset, 0) 83 90 i := &index{ 84 91 fset: f, 85 92 labelMap: map[string]label{"": 0},
+3 -3
cue/builtin.go
··· 61 61 cue string 62 62 } 63 63 64 - func mustCompileBuiltins(ctx *context, p *builtinPkg) *structLit { 64 + func mustCompileBuiltins(ctx *context, p *builtinPkg, name string) *structLit { 65 65 obj := &structLit{} 66 66 for _, b := range p.native { 67 67 f := ctx.label(b.Name, false) // never starts with _ ··· 76 76 77 77 // Parse builtin CUE 78 78 if p.cue != "" { 79 - expr, err := parser.ParseExpr(ctx.index.fset, "<builtinPkg>", p.cue) 79 + expr, err := parser.ParseExpr(ctx.index.fset, name, p.cue) 80 80 if err != nil { 81 81 fmt.Println(p.cue) 82 82 panic(err) ··· 232 232 func initBuiltins(pkgs map[string]*builtinPkg) { 233 233 ctx := sharedIndex.newContext() 234 234 for k, b := range pkgs { 235 - e := mustCompileBuiltins(ctx, b) 235 + e := mustCompileBuiltins(ctx, b, k) 236 236 builtins[k] = e 237 237 builtins["-/"+path.Base(k)] = e 238 238 }
+8 -2
cue/errors.go
··· 89 89 90 90 func appendPositions(pos []token.Position, fset *token.FileSet, src source) []token.Position { 91 91 if src != nil { 92 - if src.Pos() != token.NoPos { 92 + if p := src.Pos(); p != token.NoPos { 93 + if p >= sharedOffset { 94 + fset = sharedIndex.fset 95 + } 93 96 return append(pos, fset.Position(src.Pos())) 94 97 } 95 98 if c := src.computed(); c != nil { ··· 119 122 120 123 func appendLocations(locs []string, fset *token.FileSet, src source) []string { 121 124 if src != nil { 122 - if src.Pos() != token.NoPos { 125 + if p := src.Pos(); p != token.NoPos { 126 + if p >= sharedOffset { 127 + fset = sharedIndex.fset 128 + } 123 129 return append(locs, fset.Position(src.Pos()).String()) 124 130 } 125 131 if c := src.computed(); c != nil {