Skip to content

Commit d8451da

Browse files
committed
internal/core/adt: clear close check
Builtin calls currently may still be evaluated within a different OpContext. This means that any closedness information attached to the returned data is invalid. This is fine, as regular builtin return values should be treated as values. (This is different for non-concrete builtins). Note that such closedness information is still handled correctly _within_ the builtin, and thus there is still typo checking going on there. Just the typo checking information of the returned value can be ignored. We now do this by resetting the closedness information in newReq if we notice that the value originates from a different context. We introduce a helper function and use it in other spots where the typo checking info was previously closed. Fixes #4000 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I0df7bc73498b6bd3cb14abc00f00d2a4038aac08 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1219265 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent b12697e commit d8451da

File tree

3 files changed

+35
-38
lines changed

3 files changed

+35
-38
lines changed

cue/testdata/definitions/issue4000.txtar

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,10 @@ _items: [#VMRuleList]
3131
}
3232
#TypeMeta: kind: string | *"default"
3333
-- out/evalalpha --
34-
Errors:
35-
items: error in call to list.Sort: runtime error: index out of range [13] with length 6:
36-
./in.cue:3:8
37-
38-
Result:
39-
(_|_){
40-
// [eval]
41-
items: (_|_){
42-
// [eval] items: error in call to list.Sort: runtime error: index out of range [13] with length 6:
43-
// ./in.cue:3:8
34+
(struct){
35+
items: (#list){
36+
0: ~(#VMRuleList.0)
37+
1: ~(#VMRuleList.1)
4438
}
4539
#List: (#struct){
4640
items: (#list){
@@ -153,16 +147,16 @@ Result:
153147
}
154148
-- out/evalalpha/stats --
155149
Leaks: 0
156-
Freed: 52
157-
Reused: 20
150+
Freed: 54
151+
Reused: 22
158152
Allocs: 32
159153
Retain: 0
160154

161-
Unifications: 36
162-
Conjuncts: 74
155+
Unifications: 38
156+
Conjuncts: 77
163157
Disjuncts: 12
164158

165-
NumCloseIDs: 16
159+
NumCloseIDs: 17
166160
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
167161
diff old new
168162
--- old
@@ -177,16 +171,16 @@ diff old new
177171
-Unifications: 116
178172
-Conjuncts: 257
179173
-Disjuncts: 161
180-
+Freed: 52
181-
+Reused: 20
174+
+Freed: 54
175+
+Reused: 22
182176
+Allocs: 32
183177
+Retain: 0
184178
+
185-
+Unifications: 36
186-
+Conjuncts: 74
179+
+Unifications: 38
180+
+Conjuncts: 77
187181
+Disjuncts: 12
188182
+
189-
+NumCloseIDs: 16
183+
+NumCloseIDs: 17
190184
-- out/eval/stats --
191185
Leaks: 0
192186
Freed: 152
@@ -201,9 +195,9 @@ Disjuncts: 161
201195
diff old new
202196
--- old
203197
+++ new
204-
@@ -1,85 +1,22 @@
205-
-(struct){
206-
- items: (#list){
198+
@@ -1,85 +1,16 @@
199+
(struct){
200+
items: (#list){
207201
- 0: (#struct){
208202
- spec: (#list){
209203
- 0: (#struct){
@@ -228,16 +222,8 @@ diff old new
228222
- }
229223
- kind: (string){ |(*(string){ "default" }, (string){ string }) }
230224
- }
231-
+Errors:
232-
+items: error in call to list.Sort: runtime error: index out of range [13] with length 6:
233-
+ ./in.cue:3:8
234-
+
235-
+Result:
236-
+(_|_){
237-
+ // [eval]
238-
+ items: (_|_){
239-
+ // [eval] items: error in call to list.Sort: runtime error: index out of range [13] with length 6:
240-
+ // ./in.cue:3:8
225+
+ 0: ~(#VMRuleList.0)
226+
+ 1: ~(#VMRuleList.1)
241227
}
242228
#List: (#struct){
243229
items: (#list){
@@ -300,7 +286,7 @@ diff old new
300286
}
301287
#VMRuleList: (#list){
302288
0: (#struct){
303-
@@ -115,9 +52,9 @@
289+
@@ -115,9 +46,9 @@
304290
expr: (string){ string }
305291
}
306292
#VMRule: (#struct){

internal/core/adt/composite.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,7 @@ func (v *Vertex) toDataAllRec(ctx *OpContext, processed map[*Vertex]*Vertex) *Ve
838838
// Always reset all CloseInfo fields to zero. Normally only the top
839839
// conjuncts matter and get inserted and conjuncts of recursive arcs
840840
// never come in play. ToDataAll is an exception.
841-
w.Conjuncts[i].CloseInfo.opID = 0
842-
w.Conjuncts[i].CloseInfo.defID = 0
843-
w.Conjuncts[i].CloseInfo.outerID = 0
844-
w.Conjuncts[i].CloseInfo.enclosingEmbed = 0
841+
w.Conjuncts[i].CloseInfo = w.Conjuncts[i].CloseInfo.clearCloseCheck()
845842
}
846843

847844
// Store the processed vertex before returning

internal/core/adt/typocheck.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,21 @@ func (c *OpContext) subField(ci CloseInfo) CloseInfo {
421421
return ci
422422
}
423423

424+
// clearCloseCheck clears the CloseInfo for a node, so that it is not
425+
// considered for typo checking.
426+
func (id CloseInfo) clearCloseCheck() CloseInfo {
427+
id.opID = 0
428+
id.defID = 0
429+
id.enclosingEmbed = 0
430+
id.outerID = 0
431+
return id
432+
}
433+
424434
func (n *nodeContext) newReq(id CloseInfo, kind defIDType) CloseInfo {
435+
if id.defID != 0 && id.opID != n.ctx.opID {
436+
return id.clearCloseCheck()
437+
}
438+
425439
dstID := n.ctx.getNextDefID()
426440
n.addReplacement(replaceID{from: id.defID, to: dstID})
427441

0 commit comments

Comments
 (0)