this repo has no description
0
fork

Configure Feed

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

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 <mpvl@gmail.com>
Change-Id: I0df7bc73498b6bd3cb14abc00f00d2a4038aac08
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1219265
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+35 -38
+20 -34
cue/testdata/definitions/issue4000.txtar
··· 31 31 } 32 32 #TypeMeta: kind: string | *"default" 33 33 -- 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) 44 38 } 45 39 #List: (#struct){ 46 40 items: (#list){ ··· 153 147 } 154 148 -- out/evalalpha/stats -- 155 149 Leaks: 0 156 - Freed: 52 157 - Reused: 20 150 + Freed: 54 151 + Reused: 22 158 152 Allocs: 32 159 153 Retain: 0 160 154 161 - Unifications: 36 162 - Conjuncts: 74 155 + Unifications: 38 156 + Conjuncts: 77 163 157 Disjuncts: 12 164 158 165 - NumCloseIDs: 16 159 + NumCloseIDs: 17 166 160 -- diff/-out/evalalpha/stats<==>+out/eval/stats -- 167 161 diff old new 168 162 --- old ··· 177 171 -Unifications: 116 178 172 -Conjuncts: 257 179 173 -Disjuncts: 161 180 - +Freed: 52 181 - +Reused: 20 174 + +Freed: 54 175 + +Reused: 22 182 176 +Allocs: 32 183 177 +Retain: 0 184 178 + 185 - +Unifications: 36 186 - +Conjuncts: 74 179 + +Unifications: 38 180 + +Conjuncts: 77 187 181 +Disjuncts: 12 188 182 + 189 - +NumCloseIDs: 16 183 + +NumCloseIDs: 17 190 184 -- out/eval/stats -- 191 185 Leaks: 0 192 186 Freed: 152 ··· 201 195 diff old new 202 196 --- old 203 197 +++ new 204 - @@ -1,85 +1,22 @@ 205 - -(struct){ 206 - - items: (#list){ 198 + @@ -1,85 +1,16 @@ 199 + (struct){ 200 + items: (#list){ 207 201 - 0: (#struct){ 208 202 - spec: (#list){ 209 203 - 0: (#struct){ ··· 228 222 - } 229 223 - kind: (string){ |(*(string){ "default" }, (string){ string }) } 230 224 - } 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) 241 227 } 242 228 #List: (#struct){ 243 229 items: (#list){ ··· 300 286 } 301 287 #VMRuleList: (#list){ 302 288 0: (#struct){ 303 - @@ -115,9 +52,9 @@ 289 + @@ -115,9 +46,9 @@ 304 290 expr: (string){ string } 305 291 } 306 292 #VMRule: (#struct){
+1 -4
internal/core/adt/composite.go
··· 838 838 // Always reset all CloseInfo fields to zero. Normally only the top 839 839 // conjuncts matter and get inserted and conjuncts of recursive arcs 840 840 // 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() 845 842 } 846 843 847 844 // Store the processed vertex before returning
+14
internal/core/adt/typocheck.go
··· 421 421 return ci 422 422 } 423 423 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 + 424 434 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 + 425 439 dstID := n.ctx.getNextDefID() 426 440 n.addReplacement(replaceID{from: id.defID, to: dstID}) 427 441