this repo has no description
0
fork

Configure Feed

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

cue: get rid of internal index type

Change-Id: I0ce4bb9ab8263a1a8a2774ce3cd1ff9de3bbca46
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9365
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>

+44 -59
+8 -21
cue/build.go
··· 31 31 // 32 32 // The zero value of a Runtime is ready to use. 33 33 type Runtime struct { 34 - idx *index 34 + idx *runtime.Runtime 35 35 } 36 36 37 37 func init() { ··· 59 59 60 60 internal.CoreValue = func(value interface{}) (runtime, vertex interface{}) { 61 61 if v, ok := value.(Value); ok && v.v != nil { 62 - return v.idx.Runtime, v.v 62 + return v.idx, v.v 63 63 } 64 64 return nil, nil 65 65 } ··· 67 67 68 68 func dummyLoad(token.Pos, string) *build.Instance { return nil } 69 69 70 - func (r *Runtime) index() *index { 70 + func (r *Runtime) index() *runtime.Runtime { 71 71 if r.idx == nil { 72 72 r.idx = newIndex() 73 73 } ··· 184 184 }) 185 185 } 186 186 187 - // index maps conversions from label names to internal codes. 188 - // 189 - // All instances belonging to the same package should share this index. 190 - type index struct { 191 - *runtime.Runtime 192 - } 193 - 194 187 // NewRuntime creates a *runtime.Runtime with builtins preloaded. 195 188 func NewRuntime() *runtime.Runtime { 196 189 i := newIndex() 197 - i.Runtime.Data = i 198 - return i.Runtime 190 + return i 199 191 } 200 192 201 193 // newIndex creates a new index. 202 - func newIndex() *index { 203 - r := runtime.New() 204 - i := &index{ 205 - Runtime: r, 206 - } 207 - r.Data = i 208 - return i 194 + func newIndex() *runtime.Runtime { 195 + return runtime.New() 209 196 } 210 197 211 198 func isBuiltin(s string) bool { 212 199 return runtime.SharedRuntime.IsBuiltinPackage(s) 213 200 } 214 201 215 - func loadInstance(idx *index, p *build.Instance) *Instance { 216 - v, _ := idx.Runtime.Build(p) 202 + func loadInstance(idx *runtime.Runtime, p *build.Instance) *Instance { 203 + v, _ := idx.Build(p) 217 204 return getImportFromBuild(idx, p, v) 218 205 }
+1 -1
cue/build_test.go
··· 200 200 got = err.Error() 201 201 } else { 202 202 cfg := &debug.Config{Compact: true} 203 - got = debug.NodeString(insts[0].index.Runtime, insts[0].Value().v, cfg) 203 + got = debug.NodeString(insts[0].index, insts[0].Value().v, cfg) 204 204 } 205 205 if got != tc.emit { 206 206 t.Errorf("\n got: %s\nwant: %s", got, tc.emit)
+3 -2
cue/context.go
··· 18 18 "cuelang.org/go/internal/core/adt" 19 19 "cuelang.org/go/internal/core/debug" 20 20 "cuelang.org/go/internal/core/eval" 21 + "cuelang.org/go/internal/core/runtime" 21 22 ) 22 23 23 24 // newContext returns a new evaluation context. 24 - func newContext(idx *index) *adt.OpContext { 25 + func newContext(idx *runtime.Runtime) *adt.OpContext { 25 26 if idx == nil { 26 27 return nil 27 28 } 28 - return eval.NewContext(idx.Runtime, nil) 29 + return eval.NewContext(idx, nil) 29 30 } 30 31 31 32 func debugStr(ctx *adt.OpContext, v adt.Node) string {
+2 -1
cue/errors.go
··· 18 18 "cuelang.org/go/cue/errors" 19 19 "cuelang.org/go/cue/token" 20 20 "cuelang.org/go/internal/core/adt" 21 + "cuelang.org/go/internal/core/runtime" 21 22 ) 22 23 23 24 func (v Value) toErr(b *adt.Bottom) (err errors.Error) { ··· 94 95 Err: errors.Newf(token.NoPos, "undefined value"), 95 96 } 96 97 97 - func mkErr(idx *index, src adt.Node, args ...interface{}) *adt.Bottom { 98 + func mkErr(idx *runtime.Runtime, src adt.Node, args ...interface{}) *adt.Bottom { 98 99 var e *adt.Bottom 99 100 var code adt.ErrorCode = -1 100 101 outer:
+2 -2
cue/go.go
··· 24 24 func init() { 25 25 internal.FromGoValue = func(runtime, x interface{}, nilIsTop bool) interface{} { 26 26 r := runtime.(*Runtime) 27 - ctx := eval.NewContext(r.index().Runtime, nil) 27 + ctx := eval.NewContext(r.index(), nil) 28 28 v := convert.GoValueToValue(ctx, x, nilIsTop) 29 29 n := adt.ToVertex(v) 30 30 return Value{r.idx, n} ··· 32 32 33 33 internal.FromGoType = func(runtime, x interface{}) interface{} { 34 34 r := runtime.(*Runtime) 35 - ctx := eval.NewContext(r.index().Runtime, nil) 35 + ctx := eval.NewContext(r.index(), nil) 36 36 expr, err := convert.GoTypeToExpr(ctx, x) 37 37 if err != nil { 38 38 expr = &adt.Bottom{Err: err}
+10 -10
cue/instance.go
··· 23 23 "cuelang.org/go/internal/core/compile" 24 24 "cuelang.org/go/internal/core/convert" 25 25 "cuelang.org/go/internal/core/eval" 26 + "cuelang.org/go/internal/core/runtime" 26 27 ) 27 28 28 29 // An Instance defines a single configuration based on a collection of 29 30 // underlying CUE files. 30 31 type Instance struct { 31 - index *index 32 + index *runtime.Runtime 32 33 33 34 root *adt.Vertex 34 35 ··· 45 46 // complete bool // for cycle detection 46 47 } 47 48 48 - func addInst(x *index, p *Instance) *Instance { 49 + func addInst(x *runtime.Runtime, p *Instance) *Instance { 49 50 if p.inst == nil { 50 51 p.inst = &build.Instance{ 51 52 ImportPath: p.ImportPath, 52 53 PkgName: p.PkgName, 53 54 } 54 55 } 55 - // fmt.Println(p.ImportPath, "XXX") 56 56 x.AddInst(p.ImportPath, p.root, p.inst) 57 57 x.SetBuildData(p.inst, p) 58 58 p.index = x 59 59 return p 60 60 } 61 61 62 - func lookupInstance(x *index, p *build.Instance) *Instance { 62 + func lookupInstance(x *runtime.Runtime, p *build.Instance) *Instance { 63 63 if x, ok := x.BuildData(p); ok { 64 64 return x.(*Instance) 65 65 } 66 66 return nil 67 67 } 68 68 69 - func getImportFromBuild(x *index, p *build.Instance, v *adt.Vertex) *Instance { 69 + func getImportFromBuild(x *runtime.Runtime, p *build.Instance, v *adt.Vertex) *Instance { 70 70 inst := lookupInstance(x, p) 71 71 72 72 if inst != nil { ··· 91 91 return inst 92 92 } 93 93 94 - func getImportFromNode(x *index, v *adt.Vertex) *Instance { 94 + func getImportFromNode(x *runtime.Runtime, v *adt.Vertex) *Instance { 95 95 p := x.GetInstanceFromNode(v) 96 96 if p == nil { 97 97 return nil ··· 100 100 return getImportFromBuild(x, p, v) 101 101 } 102 102 103 - func getImportFromPath(x *index, id string) *Instance { 103 + func getImportFromPath(x *runtime.Runtime, id string) *Instance { 104 104 node, _ := x.LoadImport(id) 105 105 if node == nil { 106 106 return nil ··· 135 135 } 136 136 137 137 // newInstance creates a new instance. Use Insert to populate the instance. 138 - func newInstance(x *index, p *build.Instance, v *adt.Vertex) *Instance { 138 + func newInstance(x *runtime.Runtime, p *build.Instance, v *adt.Vertex) *Instance { 139 139 // TODO: associate root source with structLit. 140 140 inst := &Instance{ 141 141 root: v, ··· 316 316 p.Complete() 317 317 318 318 idx := inst.index 319 - r := inst.index.Runtime 319 + r := inst.index 320 320 321 321 rErr := r.ResolveFiles(p) 322 322 ··· 411 411 u.AddConjunct(c) 412 412 } 413 413 } else { 414 - ctx := eval.NewContext(inst.index.Runtime, nil) 414 + ctx := eval.NewContext(inst.index, nil) 415 415 expr := convert.GoValueToExpr(ctx, true, x) 416 416 u.AddConjunct(adt.MakeRootConjunct(nil, expr)) 417 417 u.Finalize(ctx)
+1 -1
cue/marshal.go
··· 140 140 return p 141 141 } 142 142 // TODO: support exporting instance 143 - file, _ := export.Def(r.idx.Runtime, i.inst.ID(), i.root) 143 + file, _ := export.Def(r.idx, i.inst.ID(), i.root) 144 144 imports := []string{} 145 145 file.VisitImports(func(i *ast.ImportDecl) { 146 146 for _, spec := range i.Specs {
+1 -1
cue/query.go
··· 63 63 64 64 outer: 65 65 for _, sel := range p.path { 66 - f := sel.sel.feature(v.idx.Runtime) 66 + f := sel.sel.feature(v.idx) 67 67 for _, a := range n.Arcs { 68 68 if a.Label == f { 69 69 n = a
+16 -17
cue/types.go
··· 213 213 // 214 214 type Iterator struct { 215 215 val Value 216 - idx *index 216 + idx *runtime.Runtime 217 217 ctx *adt.OpContext 218 218 arcs []field 219 219 p int ··· 551 551 } 552 552 a = append(a, label) 553 553 default: 554 - a = append(a, f.SelectorString(v.idx.Runtime)) 554 + a = append(a, f.SelectorString(v.idx)) 555 555 } 556 556 } 557 557 return a ··· 560 560 // Value holds any value, which may be a Boolean, Error, List, Null, Number, 561 561 // Struct, or String. 562 562 type Value struct { 563 - idx *index 563 + idx *runtime.Runtime 564 564 v *adt.Vertex 565 565 } 566 566 ··· 575 575 return makeValue(v.idx, node) 576 576 } 577 577 578 - func newVertexRoot(idx *index, ctx *adt.OpContext, x *adt.Vertex) Value { 578 + func newVertexRoot(idx *runtime.Runtime, ctx *adt.OpContext, x *adt.Vertex) Value { 579 579 if ctx != nil { 580 580 // This is indicative of an zero Value. In some cases this is called 581 581 // with an error value. ··· 586 586 return makeValue(idx, x) 587 587 } 588 588 589 - func newValueRoot(idx *index, ctx *adt.OpContext, x adt.Expr) Value { 589 + func newValueRoot(idx *runtime.Runtime, ctx *adt.OpContext, x adt.Expr) Value { 590 590 if n, ok := x.(*adt.Vertex); ok { 591 591 return newVertexRoot(idx, ctx, n) 592 592 } ··· 629 629 // 630 630 // For internal use only. 631 631 func MakeValue(ctx *adt.OpContext, v adt.Value) Value { 632 - runtime := ctx.Impl().(*runtime.Runtime) 633 - index := runtime.Data.(*index) 632 + index := ctx.Impl().(*runtime.Runtime) 634 633 635 634 return newValueRoot(index, newContext(index), v) 636 635 } 637 636 638 - func makeValue(idx *index, v *adt.Vertex) Value { 637 + func makeValue(idx *runtime.Runtime, v *adt.Vertex) Value { 639 638 if v.Status() == 0 || v.BaseValue == nil { 640 639 panic(fmt.Sprintf("not properly initialized (state: %v, value: %T)", 641 640 v.Status(), v.BaseValue)) ··· 969 968 if o.concrete || o.final { 970 969 // inst = v.instance() 971 970 var expr ast.Expr 972 - expr, err = p.Value(v.idx.Runtime, pkgID, v.v) 971 + expr, err = p.Value(v.idx, pkgID, v.v) 973 972 if err != nil { 974 973 return bad(`"cuelang.org/go/internal/core/export".Value`, err) 975 974 } ··· 981 980 } 982 981 // return expr 983 982 } else { 984 - f, err = p.Def(v.idx.Runtime, pkgID, v.v) 983 + f, err = p.Def(v.idx, pkgID, v.v) 985 984 if err != nil { 986 985 return bad(`"cuelang.org/go/internal/core/export".Def`, err) 987 986 } ··· 1491 1490 a[i] = Selector{indexSelector(f)} 1492 1491 1493 1492 case adt.DefinitionLabel, adt.HiddenDefinitionLabel, adt.HiddenLabel: 1494 - a[i] = Selector{definitionSelector(f.SelectorString(v.idx.Runtime))} 1493 + a[i] = Selector{definitionSelector(f.SelectorString(v.idx))} 1495 1494 1496 1495 case adt.StringLabel: 1497 - a[i] = Selector{stringSelector(f.StringValue(v.idx.Runtime))} 1496 + a[i] = Selector{stringSelector(f.StringValue(v.idx))} 1498 1497 } 1499 1498 } 1500 1499 return Path{path: a} ··· 1824 1823 case state.Flag('+'): 1825 1824 _, _ = io.WriteString(state, ctx.Str(v.v)) 1826 1825 default: 1827 - n, _ := export.Raw.Expr(v.idx.Runtime, v.instance().ID(), v.v) 1826 + n, _ := export.Raw.Expr(v.idx, v.instance().ID(), v.v) 1828 1827 b, _ := format.Node(n) 1829 1828 _, _ = state.Write(b) 1830 1829 } ··· 1852 1851 return reference(v.idx, ctx, c.Env, c.Expr()) 1853 1852 } 1854 1853 1855 - func reference(rt *index, c *adt.OpContext, env *adt.Environment, r adt.Expr) (inst *Instance, path []string) { 1854 + func reference(rt *runtime.Runtime, c *adt.OpContext, env *adt.Environment, r adt.Expr) (inst *Instance, path []string) { 1856 1855 ctx := c 1857 1856 defer ctx.PopState(ctx.PushState(env, r.Source())) 1858 1857 ··· 1900 1899 return inst, path 1901 1900 } 1902 1901 1903 - func mkPath(ctx *index, a []string, v *adt.Vertex) (inst *Instance, path []string) { 1902 + func mkPath(ctx *runtime.Runtime, a []string, v *adt.Vertex) (inst *Instance, path []string) { 1904 1903 if v.Parent == nil { 1905 1904 return getImportFromNode(ctx, v), a 1906 1905 } ··· 2390 2389 a.AddConjunct(adt.MakeRootConjunct(env, n.Val)) 2391 2390 b.AddConjunct(adt.MakeRootConjunct(env, disjunct.Val)) 2392 2391 2393 - ctx := eval.NewContext(v.idx.Runtime, nil) 2392 + ctx := eval.NewContext(v.idx, nil) 2394 2393 ctx.Unify(&a, adt.Finalized) 2395 2394 ctx.Unify(&b, adt.Finalized) 2396 2395 if allowed(ctx, v.v, &b) != nil { ··· 2434 2433 a = append(a, remakeValue(v, env, x.X)) 2435 2434 // A string selector is quoted. 2436 2435 a = append(a, remakeValue(v, env, &adt.String{ 2437 - Str: x.Sel.SelectorString(v.idx.Runtime), 2436 + Str: x.Sel.SelectorString(v.idx), 2438 2437 })) 2439 2438 op = SelectorOp 2440 2439
-3
internal/core/runtime/runtime.go
··· 22 22 type Runtime struct { 23 23 index *index 24 24 25 - // Data holds the legacy index strut. It is for transitional purposes only. 26 - Data interface{} 27 - 28 25 loaded map[*build.Instance]interface{} 29 26 } 30 27