Skip to content

Commit

Permalink
internal/core/adt: automatic renaming
Browse files Browse the repository at this point in the history
This is the last step to make List- and StructMarker
a type different from Value and Expr.

Rename:
Vertex.Value -> Vertex.BaseValue
Vertex.ActualValue() -> Vertex.Value()

This generated changes should be used as a last
manual check that the values are used correctly.

Issue #598

Change-Id: Iadb8eb6d782099cbba4deb7cf99f129ce0363371
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7766
Reviewed-by: Tony Worm <tony@hofstadter.io>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
  • Loading branch information
mpvl committed Nov 28, 2020
1 parent 08a1652 commit 41afc87
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 128 deletions.
2 changes: 1 addition & 1 deletion cue/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (v Value) eval(ctx *context) adt.Value {
panic("undefined value")
}
x := ctx.manifest(v.v)
return x.ActualValue()
return x.Value()
}

// func (v Value) evalFull(u value) (Value, adt.Value) {
Expand Down
4 changes: 2 additions & 2 deletions cue/load/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,12 @@ func (c Config) complete() (cfg *Config, err error) {
v.Finalize(ctx)
prefix := v.Lookup(ctx.StringLabel("module"))
if prefix != nil {
name := ctx.StringValue(prefix.ActualValue())
name := ctx.StringValue(prefix.Value())
if err := ctx.Err(); err != nil {
return &c, err.Err
}
pos := token.NoPos
src := prefix.ActualValue().Source()
src := prefix.Value().Source()
if src != nil {
pos = src.Pos()
}
Expand Down
22 changes: 11 additions & 11 deletions cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ type Value struct {
}

func newErrValue(v Value, b *adt.Bottom) Value {
node := &adt.Vertex{Value: b}
node := &adt.Vertex{BaseValue: b}
if v.v != nil {
node.Label = v.v.Label
node.Parent = v.v.Parent
Expand Down Expand Up @@ -635,9 +635,9 @@ func MakeValue(ctx *adt.OpContext, v adt.Value) Value {
}

func makeValue(idx *index, v *adt.Vertex) Value {
if v.Status() == 0 || v.Value == nil {
if v.Status() == 0 || v.BaseValue == nil {
panic(fmt.Sprintf("not properly initialized (state: %v, value: %T)",
v.Status(), v.Value))
v.Status(), v.BaseValue))
}
return Value{idx, v}
}
Expand All @@ -656,7 +656,7 @@ func remakeValue(base Value, env *adt.Environment, v adt.Expr) Value {
}

func remakeFinal(base Value, env *adt.Environment, v adt.Value) Value {
n := &adt.Vertex{Parent: base.v.Parent, Label: base.v.Label, Value: v}
n := &adt.Vertex{Parent: base.v.Parent, Label: base.v.Label, BaseValue: v}
n.UpdateStatus(adt.Finalized)
return makeValue(base.idx, n)
}
Expand Down Expand Up @@ -843,7 +843,7 @@ func (v Value) Kind() Kind {
if v.v == nil {
return BottomKind
}
c := v.v.Value
c := v.v.BaseValue
if !v.v.IsConcrete() {
return BottomKind
}
Expand Down Expand Up @@ -1061,7 +1061,7 @@ func (v Value) Source() ast.Node {
if len(v.v.Conjuncts) == 1 {
return v.v.Conjuncts[0].Source()
}
return v.v.ActualValue().Source()
return v.v.Value().Source()
}

// Err returns the error represented by v or nil v is not an error.
Expand Down Expand Up @@ -1100,7 +1100,7 @@ func (v Value) IsConcrete() bool {
if v.v == nil {
return false // any is neither concrete, not a list or struct.
}
if b, ok := v.v.Value.(*adt.Bottom); ok {
if b, ok := v.v.BaseValue.(*adt.Bottom); ok {
return !b.IsIncomplete()
}
if !adt.IsConcrete(v.v) {
Expand All @@ -1125,7 +1125,7 @@ func (v Value) Exists() bool {
if v.v == nil {
return false
}
if err, ok := v.v.Value.(*adt.Bottom); ok {
if err, ok := v.v.BaseValue.(*adt.Bottom); ok {
return err.Code != codeNotExist
}
return true
Expand Down Expand Up @@ -2164,15 +2164,15 @@ func (v Value) Expr() (Op, []Value) {
var env *adt.Environment

if v.v.IsData() {
expr = v.v.ActualValue()
expr = v.v.Value()

} else {
switch len(v.v.Conjuncts) {
case 0:
if v.v.Value == nil {
if v.v.BaseValue == nil {
return NoOp, []Value{makeValue(v.idx, v.v)}
}
expr = v.v.ActualValue()
expr = v.v.Value()

case 1:
// the default case, processed below.
Expand Down
2 changes: 1 addition & 1 deletion cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2499,7 +2499,7 @@ func TestWalk(t *testing.T) {
case ListKind:
buf = append(buf, '[')
default:
if b, _ := v.v.Value.(*adt.Bottom); b != nil {
if b, _ := v.v.BaseValue.(*adt.Bottom); b != nil {
s := debugStr(v.ctx(), b)
buf = append(buf, fmt.Sprint(s, ",")...)
return true
Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/adt.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func Pos(n Node) token.Pos {

func (x *Vertex) Concreteness() Concreteness {
// Depends on concreteness of value.
switch v := x.Value.(type) {
switch v := x.BaseValue.(type) {
case nil:
return Concrete // Should be indetermined.

Expand Down
40 changes: 20 additions & 20 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ type Vertex struct {
// SelfCount is used for tracking self-references.
SelfCount int

// Value is the value associated with this vertex. For lists and structs
// BaseValue is the value associated with this vertex. For lists and structs
// this is a sentinel value indicating its kind.
Value BaseValue
BaseValue BaseValue

// ChildErrors is the collection of all errors of children.
ChildErrors *Bottom
Expand Down Expand Up @@ -249,25 +249,25 @@ func (v *Vertex) UpdateStatus(s VertexStatus) {
if v.status > s+1 {
panic(fmt.Sprintf("attempt to regress status from %d to %d", v.Status(), s))
}
if s == Finalized && v.Value == nil {
if s == Finalized && v.BaseValue == nil {
// panic("not finalized")
}
v.status = s
}

// ActualValue returns the Value of v without definitions if it is a scalar
// Value returns the Value of v without definitions if it is a scalar
// or itself otherwise.
func (v *Vertex) ActualValue() Value {
func (v *Vertex) Value() Value {
// TODO: rename to Value.
switch x := v.Value.(type) {
switch x := v.BaseValue.(type) {
case nil:
return nil
case *StructMarker, *ListMarker:
return v
case Value:
return x
default:
panic(fmt.Sprintf("unexpected type %T", v.Value))
panic(fmt.Sprintf("unexpected type %T", v.BaseValue))
}
}

Expand Down Expand Up @@ -302,7 +302,7 @@ func (v *Vertex) ToDataAll() *Vertex {
}
w := *v

w.Value = toDataAll(w.Value)
w.BaseValue = toDataAll(w.BaseValue)
w.Arcs = arcs
w.isData = true
w.Conjuncts = make([]Conjunct, len(v.Conjuncts))
Expand Down Expand Up @@ -352,7 +352,7 @@ func toDataAll(v BaseValue) BaseValue {

func (v *Vertex) IsErr() bool {
// if v.Status() > Evaluating {
if _, ok := v.Value.(*Bottom); ok {
if _, ok := v.BaseValue.(*Bottom); ok {
return true
}
// }
Expand All @@ -361,7 +361,7 @@ func (v *Vertex) IsErr() bool {

func (v *Vertex) Err(c *OpContext, state VertexStatus) *Bottom {
c.Unify(c, v, state)
if b, ok := v.Value.(*Bottom); ok {
if b, ok := v.BaseValue.(*Bottom); ok {
return b
}
return nil
Expand All @@ -374,12 +374,12 @@ func (v *Vertex) Finalize(c *OpContext) {
}

func (v *Vertex) AddErr(ctx *OpContext, b *Bottom) {
v.Value = CombineErrors(nil, v.ActualValue(), b)
v.BaseValue = CombineErrors(nil, v.Value(), b)
v.UpdateStatus(Finalized)
}

func (v *Vertex) SetValue(ctx *OpContext, state VertexStatus, value BaseValue) *Bottom {
v.Value = value
v.BaseValue = value
v.UpdateStatus(state)
return nil
}
Expand All @@ -391,8 +391,8 @@ func ToVertex(v Value) *Vertex {
return x
default:
n := &Vertex{
status: Finalized,
Value: x,
status: Finalized,
BaseValue: x,
}
n.AddConjunct(MakeRootConjunct(nil, v))
return n
Expand All @@ -406,7 +406,7 @@ func Unwrap(v Value) Value {
if !ok {
return v
}
return x.ActualValue()
return x.Value()
}

// Acceptor is a single interface that reports whether feature f is a valid
Expand Down Expand Up @@ -443,10 +443,10 @@ const (
func (v *Vertex) Kind() Kind {
// This is possible when evaluating comprehensions. It is potentially
// not known at this time what the type is.
if v.Value == nil {
if v.BaseValue == nil {
return TopKind
}
return v.Value.Kind()
return v.BaseValue.Kind()
}

func (v *Vertex) OptionalTypes() OptionalType {
Expand All @@ -461,7 +461,7 @@ func (v *Vertex) OptionalTypes() OptionalType {
}

func (v *Vertex) IsClosed(ctx *OpContext) bool {
switch x := v.Value.(type) {
switch x := v.BaseValue.(type) {
case *ListMarker:
// TODO: use one mechanism.
if x.IsOpen {
Expand Down Expand Up @@ -505,7 +505,7 @@ func (v *Vertex) MatchAndInsert(ctx *OpContext, arc *Vertex) {
}

func (v *Vertex) IsList() bool {
_, ok := v.Value.(*ListMarker)
_, ok := v.BaseValue.(*ListMarker)
return ok
}

Expand Down Expand Up @@ -547,7 +547,7 @@ func (v *Vertex) Source() ast.Node { return nil }

// AddConjunct adds the given Conjuncts to v if it doesn't already exist.
func (v *Vertex) AddConjunct(c Conjunct) *Bottom {
if v.Value != nil {
if v.BaseValue != nil {
// TODO: investigate why this happens at all. Removing it seems to
// change the order of fields in some cases.
//
Expand Down
16 changes: 8 additions & 8 deletions internal/core/adt/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (c *OpContext) Resolve(env *Environment, r Resolver) (*Vertex, *Bottom) {
}

for {
x, ok := arc.Value.(*Vertex)
x, ok := arc.BaseValue.(*Vertex)
if !ok {
break
}
Expand Down Expand Up @@ -449,7 +449,7 @@ func (c *OpContext) getDefault(v Value, scalar bool) (result Value, ok bool) {

case *Vertex:
// TODO: return vertex if not disjunction.
switch t := x.Value.(type) {
switch t := x.BaseValue.(type) {
case *Disjunction:
d = t

Expand All @@ -460,7 +460,7 @@ func (c *OpContext) getDefault(v Value, scalar bool) (result Value, ok bool) {
if !scalar {
return x, true
}
return x.ActualValue(), true
return x.Value(), true
}

case *Disjunction:
Expand Down Expand Up @@ -551,7 +551,7 @@ func (c *OpContext) evalState(v Expr, state VertexStatus) (result Value) {
}
if isIncomplete(arc) {
if arc != nil {
return arc.ActualValue() // *Bottom
return arc.Value() // *Bottom
}
return nil
}
Expand All @@ -573,8 +573,8 @@ func (c *OpContext) lookup(x *Vertex, pos token.Pos, l Feature) *Vertex {
}

var kind Kind
if x.Value != nil {
kind = x.Value.Kind()
if x.BaseValue != nil {
kind = x.BaseValue.Kind()
}

switch kind {
Expand Down Expand Up @@ -676,7 +676,7 @@ func (c *OpContext) node(x Expr, scalar bool) *Vertex {

node, ok := v.(*Vertex)
if ok {
v = node.ActualValue()
v = node.Value()
}
switch nv := v.(type) {
case nil:
Expand Down Expand Up @@ -966,7 +966,7 @@ func (c *OpContext) newBool(b bool) Value {
}

func (c *OpContext) newList(src ast.Node, parent *Vertex) *Vertex {
return &Vertex{Parent: parent, Value: &ListMarker{}}
return &Vertex{Parent: parent, BaseValue: &ListMarker{}}
}

// Str reports a debug string of x.
Expand Down
6 changes: 3 additions & 3 deletions internal/core/adt/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (d *Disjunction) Default() Value {

// Default returns the default value or itself if there is no default.
func (v *Vertex) Default() *Vertex {
switch d := v.Value.(type) {
switch d := v.BaseValue.(type) {
default:
return v

Expand All @@ -57,7 +57,7 @@ func (v *Vertex) Default() *Vertex {
w = d.Values[0]
default:
x := *v
x.Value = &Disjunction{
x.BaseValue = &Disjunction{
Src: d.Src,
Values: d.Values[:d.NumDefaults],
NumDefaults: 0,
Expand All @@ -79,7 +79,7 @@ func (v *Vertex) Default() *Vertex {

w := *v
w.Closed = nil
w.Value = &m
w.BaseValue = &m
return &w
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/core/adt/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func isIncomplete(v *Vertex) bool {
if v == nil {
return true
}
if b, ok := v.Value.(*Bottom); ok {
if b, ok := v.BaseValue.(*Bottom); ok {
return b.IsIncomplete()
}
return false
Expand All @@ -148,10 +148,10 @@ func (v *Vertex) AddChildError(recursive *Bottom) {
if recursive.IsIncomplete() {
return
}
x := v.Value
x := v.BaseValue
err, _ := x.(*Bottom)
if err == nil {
v.Value = &Bottom{
v.BaseValue = &Bottom{
Code: recursive.Code,
Value: v,
HasRecursive: true,
Expand All @@ -166,7 +166,7 @@ func (v *Vertex) AddChildError(recursive *Bottom) {
err.Code = recursive.Code
}

v.Value = err
v.BaseValue = err
}

// CombineErrors combines two errors that originate at the same Vertex.
Expand Down

0 comments on commit 41afc87

Please sign in to comment.