this repo has no description
0
fork

Configure Feed

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

internal/core/adt: remove EvalV2 optional tracking

Remove all OptionalType infrastructure and HasOptional
method as part of EvalV2 cleanup.

- Remove OptionalType type definition and constants
- Remove OptionalTypes() methods from Vertex and StructLit
- Remove FieldTypes field from CloseInfo struct
- Remove types field from StructLit struct
- Remove HasOptional() method (always returned false)
- Simplify verifyStructs() to always return true
- Update deprecated Template() function in cue/types.go
- Update IsOpen() function in internal/pkg/types.go
- Delete optional_test.go

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ic43f6219b0a96e4b4b8111818dfec27e2e8208c9
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1220005
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+6 -186
+3 -6
cue/types.go
··· 1661 1661 return nil 1662 1662 } 1663 1663 1664 - // Implementation for the old evaluator. 1665 - types := v.v.OptionalTypes() 1666 - switch { 1667 - case types&(adt.HasAdditional|adt.HasPattern) != 0: 1668 - case v.v.PatternConstraints != nil: 1669 - default: 1664 + // Simplified after removing OptionalTypes. 1665 + // Check if there are pattern constraints. 1666 + if v.v.PatternConstraints == nil { 1670 1667 return nil 1671 1668 } 1672 1669
-4
internal/core/adt/closed.go
··· 103 103 // Like FromDef, but used by APIs to force FromDef to be true. 104 104 TopDef bool 105 105 106 - // FieldTypes indicates which kinds of fields (optional, dynamic, patterns, 107 - // etc.) are contained in this conjunct. 108 - FieldTypes OptionalType 109 - 110 106 CycleInfo 111 107 } 112 108
-21
internal/core/adt/composite.go
··· 1109 1109 return x.Value() 1110 1110 } 1111 1111 1112 - // OptionalType is a bit field of the type of optional constraints in use by an 1113 - // Acceptor. 1114 - type OptionalType int8 1115 - 1116 - const ( 1117 - HasField OptionalType = 1 << iota // X: T 1118 - HasDynamic // (X): T or "\(X)": T 1119 - HasPattern // [X]: T 1120 - HasComplexPattern // anything but a basic type 1121 - HasAdditional // ...T 1122 - IsOpen // Defined for all fields 1123 - ) 1124 - 1125 1112 func (v *Vertex) Kind() Kind { 1126 1113 // This is possible when evaluating comprehensions. It is potentially 1127 1114 // not known at this time what the type is. ··· 1135 1122 default: 1136 1123 return TopKind 1137 1124 } 1138 - } 1139 - 1140 - func (v *Vertex) OptionalTypes() OptionalType { 1141 - var mask OptionalType 1142 - for _, s := range v.Structs { 1143 - mask |= s.OptionalTypes() 1144 - } 1145 - return mask 1146 1125 } 1147 1126 1148 1127 // IsOptional reports whether a field is explicitly defined as optional,
-36
internal/core/adt/equality.go
··· 90 90 if x.IsClosedList() != y.IsClosedList() { 91 91 return false 92 92 } 93 - if !equalClosed(ctx, x, y, flags) { 94 - return false 95 - } 96 93 } 97 94 98 95 skipRegular := flags&RegularOnly != 0 ··· 139 136 } 140 137 141 138 return equalTerminal(ctx, v, w, flags) 142 - } 143 - 144 - // equalClosed tests if x and y have the same set of close information. 145 - // TODO: the following refinements are possible: 146 - // - unify optional fields and equate the optional fields 147 - // - do the same for pattern constraints, where the pattern constraints 148 - // are collated by pattern equality. 149 - // - a further refinement would collate patterns by ranges. 150 - // 151 - // For all these refinements it would be necessary to have well-working 152 - // structure sharing so as to not repeatedly recompute optional arcs. 153 - func equalClosed(ctx *OpContext, x, y *Vertex, flags Flag) bool { 154 - return verifyStructs(x, y, flags) && verifyStructs(y, x, flags) 155 - } 156 - 157 - func verifyStructs(x, y *Vertex, flags Flag) bool { 158 - outer: 159 - for _, s := range x.Structs { 160 - if (flags&IgnoreOptional != 0) && !s.StructLit.HasOptional() { 161 - continue 162 - } 163 - // span() always returns 0 after EvalV2 removal, so this check is always true 164 - if !s.StructLit.HasOptional() { 165 - continue 166 - } 167 - for _, t := range y.Structs { 168 - if s.StructLit == t.StructLit { 169 - continue outer 170 - } 171 - } 172 - return false 173 - } 174 - return true 175 139 } 176 140 177 141 func equalTerminal(ctx *OpContext, v, w Value, flags Flag) bool {
-24
internal/core/adt/expr.go
··· 60 60 initialized bool 61 61 isComprehension bool 62 62 63 - types OptionalType 64 - 65 63 // administrative fields like hasreferences. 66 64 // hasReferences bool 67 65 } ··· 73 71 74 72 type FieldInfo struct { 75 73 Label Feature 76 - } 77 - 78 - func (x *StructLit) HasOptional() bool { 79 - return x.types&(HasPattern|HasAdditional) != 0 80 74 } 81 75 82 76 func (x *StructLit) Source() ast.Node { return x.Src } ··· 114 108 return v 115 109 } 116 110 117 - // TODO: remove this method 118 - func (o *StructLit) MarkField(f Feature) { 119 - o.Fields = append(o.Fields, FieldInfo{Label: f}) 120 - } 121 - 122 111 func (o *StructLit) Init(ctx *OpContext) { 123 112 if o.initialized { 124 113 return 125 114 } 126 115 o.initialized = true 127 - } 128 - 129 - func (o *StructLit) fieldIndex(f Feature) int { 130 - for i := range o.Fields { 131 - if o.Fields[i].Label == f { 132 - return i 133 - } 134 - } 135 - return -1 136 - } 137 - 138 - func (o *StructLit) OptionalTypes() OptionalType { 139 - return o.types 140 116 } 141 117 142 118 // FIELDS
-15
internal/core/adt/optional.go
··· 1 - // Copyright 2020 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - package adt
-75
internal/core/adt/optional_test.go
··· 1 - // Copyright 2020 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - package adt_test 16 - 17 - import ( 18 - "testing" 19 - 20 - "cuelang.org/go/cue/parser" 21 - "cuelang.org/go/internal" 22 - "cuelang.org/go/internal/core/adt" 23 - "cuelang.org/go/internal/core/compile" 24 - "cuelang.org/go/internal/core/eval" 25 - "cuelang.org/go/internal/core/runtime" 26 - ) 27 - 28 - func TestOptionalTypes(t *testing.T) { 29 - testCases := []struct { 30 - in string 31 - out adt.OptionalType 32 - }{{ 33 - in: ` 34 - ... 35 - `, 36 - out: adt.IsOpen, 37 - }, { 38 - in: ` 39 - [string]: int 40 - `, 41 - // adt.IsOpen means fully defined in this context, which this is not. 42 - out: adt.HasPattern, 43 - }, { 44 - in: ` 45 - bar: 3 // Not counted, as it is not optional. 46 - [string]: int // embedded into end result. 47 - "\(bar)": int 48 - `, 49 - out: adt.HasPattern | adt.HasDynamic, 50 - }} 51 - for _, tc := range testCases { 52 - t.Run("", func(t *testing.T) { 53 - ctx := eval.NewContext(runtime.New(), nil) 54 - if ctx.Version == internal.EvalV3 { 55 - t.Skip("TODO: fix these tests on evalv3") 56 - } 57 - f, err := parser.ParseFile("opt", tc.in) 58 - if err != nil { 59 - t.Fatal(err) 60 - } 61 - 62 - v, errs := compile.Files(nil, ctx, "", f) 63 - if errs != nil { 64 - t.Fatal(errs) 65 - } 66 - 67 - v.Finalize(ctx) 68 - 69 - got := v.OptionalTypes() 70 - if got != tc.out { 71 - t.Errorf("got %x; want %x", got, tc.out) 72 - } 73 - }) 74 - } 75 - }
+3 -5
internal/pkg/types.go
··· 67 67 if !s.node.IsClosedStruct() { 68 68 return true 69 69 } 70 - // Technically this is not correct, but it is in the context of where 71 - // it is used. 70 + // Check for pattern constraints which indicate openness. 72 71 if s.node.PatternConstraints != nil && len(s.node.PatternConstraints.Pairs) > 0 { 73 72 return true 74 73 } 75 - // The equivalent code for the old implementation. 76 - ot := s.node.OptionalTypes() 77 - return ot&^adt.HasDynamic != 0 74 + // After removing OptionalTypes, we rely on other checks for openness. 75 + return false 78 76 } 79 77 80 78 // NumConstraintFields reports the number of explicit optional and required