Skip to content

Commit d713052

Browse files
committed
internal/core/adt: apply vertex rewriting to blocked tasks
Now we rewrite nodes, this means we can rewrite ALL waiting tasks. Task are now only added to the respective queues after they have been rewritten. Issue #3967 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I0081496389fef3271a161d24832c709f5cf40285 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1217086 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 5c5f970 commit d713052

File tree

3 files changed

+79
-198
lines changed

3 files changed

+79
-198
lines changed

cue/testdata/eval/disjunctioncross.txtar

Lines changed: 53 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,18 @@ issue3967: error: local: {
103103
}
104104
}
105105
-- out/evalalpha/stats --
106-
Leaks: 282
106+
Leaks: 291
107107
Freed: 0
108108
Reused: 0
109-
Allocs: 282
109+
Allocs: 291
110110
Retain: 0
111111

112-
Unifications: 162
113-
Conjuncts: 364
114-
Disjuncts: 68
112+
Unifications: 165
113+
Conjuncts: 379
114+
Disjuncts: 74
115115

116-
CloseIDElems: 1555
117-
NumCloseIDs: 88
116+
CloseIDElems: 1476
117+
NumCloseIDs: 91
118118
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
119119
diff old new
120120
--- old
@@ -132,18 +132,18 @@ diff old new
132132
-
133133
-CloseIDElems: 0
134134
-NumCloseIDs: 8
135-
+Leaks: 282
135+
+Leaks: 291
136136
+Freed: 0
137137
+Reused: 0
138-
+Allocs: 282
138+
+Allocs: 291
139139
+Retain: 0
140140
+
141-
+Unifications: 162
142-
+Conjuncts: 364
143-
+Disjuncts: 68
141+
+Unifications: 165
142+
+Conjuncts: 379
143+
+Disjuncts: 74
144144
+
145-
+CloseIDElems: 1555
146-
+NumCloseIDs: 88
145+
+CloseIDElems: 1476
146+
+NumCloseIDs: 91
147147
-- out/eval/stats --
148148
Leaks: 16
149149
Freed: 292
@@ -205,12 +205,12 @@ NumCloseIDs: 8
205205
}) }
206206
}
207207
#Application: (#struct){
208-
oneOrTwo: (#struct){ |(*(#struct){
208+
oneOrTwo: (#struct){ |((#struct){
209209
kind: (string){ "one" }
210210
one: (#struct){
211211
oneField: (string){ "value" }
212212
}
213-
}, *(#struct){
213+
}, (#struct){
214214
kind: (string){ "two" }
215215
two: (#struct){
216216
optional?: (string){ string }
@@ -234,11 +234,16 @@ NumCloseIDs: 8
234234
}
235235
#Application: (#struct){
236236
oneOrTwo: (#struct){ |(*(#struct){
237+
kind: (string){ "two" }
238+
two: (#struct){
239+
optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
240+
}
241+
}, (#struct){
237242
kind: (string){ "one" }
238243
one: (#struct){
239244
oneField: (string){ "value" }
240245
}
241-
}, *(#struct){
246+
}, (#struct){
242247
kind: (string){ "two" }
243248
two: (#struct){
244249
optional?: (string){ string }
@@ -258,12 +263,12 @@ NumCloseIDs: 8
258263
}
259264
}
260265
#Application: (#struct){
261-
oneOrTwo: (#struct){ |(*(#struct){
266+
oneOrTwo: (#struct){ |((#struct){
262267
kind: (string){ "one" }
263268
one: (#struct){
264269
oneField: (string){ "value" }
265270
}
266-
}, *(#struct){
271+
}, (#struct){
267272
kind: (string){ "two" }
268273
two: (#struct){
269274
optional?: (string){ string }
@@ -273,20 +278,30 @@ NumCloseIDs: 8
273278
}
274279
local: (struct){
275280
out: (#struct){
276-
oneOrTwo: (#struct){
277-
two: (#struct){
278-
optional?: (string){ string }
279-
}
280-
kind: (string){ "two" }
281-
}
281+
oneOrTwo: (#struct){ |(*(#struct){
282+
two: (#struct){
283+
optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
284+
}
285+
kind: (string){ "two" }
286+
}, (#struct){
287+
two: (#struct){
288+
optional?: (string){ string }
289+
}
290+
kind: (string){ "two" }
291+
}) }
282292
}
283293
#Application: (#struct){
284294
oneOrTwo: (#struct){ |(*(#struct){
295+
kind: (string){ "two" }
296+
two: (#struct){
297+
optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
298+
}
299+
}, (#struct){
285300
kind: (string){ "one" }
286301
one: (#struct){
287302
oneField: (string){ "value" }
288303
}
289-
}, *(#struct){
304+
}, (#struct){
290305
kind: (string){ "two" }
291306
two: (#struct){
292307
optional?: (string){ string }
@@ -350,90 +365,21 @@ NumCloseIDs: 8
350365
diff old new
351366
--- old
352367
+++ new
353-
@@ -46,49 +46,39 @@
368+
@@ -45,12 +45,7 @@
369+
}) }
354370
}
355371
#Application: (#struct){
356-
oneOrTwo: (#struct){ |(*(#struct){
357-
- kind: (string){ "two" }
358-
- two: (#struct){
359-
- optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
360-
- }
361-
- }, (#struct){
362-
- kind: (string){ "one" }
363-
- one: (#struct){
364-
- oneField: (string){ "value" }
365-
- }
366-
- }, (#struct){
367-
- kind: (string){ "two" }
368-
- two: (#struct){
369-
- optional?: (string){ string }
370-
- }
371-
- }) }
372-
- }
373-
- }
374-
- local: (struct){
375-
- out: (#struct){
376372
- oneOrTwo: (#struct){ |(*(#struct){
377373
- kind: (string){ "two" }
378374
- two: (#struct){
379375
- optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
380376
- }
381377
- }, (#struct){
382-
- kind: (string){ "two" }
383-
- two: (#struct){
384-
- optional?: (string){ string }
385-
- }
386-
- }) }
387-
- }
388-
- #Application: (#struct){
389-
- oneOrTwo: (#struct){ |(*(#struct){
390-
- kind: (string){ "two" }
391-
- two: (#struct){
392-
- optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
393-
- }
394-
- }, (#struct){
395-
- kind: (string){ "one" }
396-
- one: (#struct){
397-
- oneField: (string){ "value" }
398-
- }
399-
- }, (#struct){
400-
+ kind: (string){ "one" }
401-
+ one: (#struct){
402-
+ oneField: (string){ "value" }
403-
+ }
404-
+ }, *(#struct){
405-
+ kind: (string){ "two" }
406-
+ two: (#struct){
407-
+ optional?: (string){ string }
408-
+ }
409-
+ }) }
410-
+ }
411-
+ }
412-
+ local: (struct){
413-
+ out: (#struct){
414-
+ oneOrTwo: (#struct){ |(*(#struct){
415-
+ kind: (string){ "two" }
416-
+ two: (#struct){
417-
+ optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
418-
+ }
419-
+ }, (#struct){
420-
+ kind: (string){ "two" }
421-
+ two: (#struct){
422-
+ optional?: (string){ string }
423-
+ }
424-
+ }) }
425-
+ }
426-
+ #Application: (#struct){
427-
+ oneOrTwo: (#struct){ |(*(#struct){
428-
+ kind: (string){ "one" }
429-
+ one: (#struct){
430-
+ oneField: (string){ "value" }
431-
+ }
432-
+ }, *(#struct){
433-
kind: (string){ "two" }
434-
two: (#struct){
435-
optional?: (string){ string }
436-
@@ -100,63 +90,43 @@
378+
+ oneOrTwo: (#struct){ |((#struct){
379+
kind: (string){ "one" }
380+
one: (#struct){
381+
oneField: (string){ "value" }
382+
@@ -100,25 +95,15 @@
437383
fieldDiscriminator: (struct){
438384
crossing: (struct){
439385
out: (#struct){
@@ -456,67 +402,6 @@ diff old new
456402
- optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
457403
- }
458404
- }, (#struct){
459-
- kind: (string){ "one" }
460-
- one: (#struct){
461-
- oneField: (string){ "value" }
462-
- }
463-
- }, (#struct){
464-
- kind: (string){ "two" }
465-
- two: (#struct){
466-
- optional?: (string){ string }
467-
- }
468-
- }) }
469-
- }
470-
- }
471-
- local: (struct){
472-
- out: (#struct){
473-
- oneOrTwo: (#struct){ |(*(#struct){
474-
- two: (#struct){
475-
- optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
476-
- }
477-
- kind: (string){ "two" }
478-
- }, (#struct){
479-
- two: (#struct){
480-
- optional?: (string){ string }
481-
- }
482-
- kind: (string){ "two" }
483-
- }) }
484-
- }
485-
- #Application: (#struct){
486-
- oneOrTwo: (#struct){ |(*(#struct){
487-
- kind: (string){ "two" }
488-
- two: (#struct){
489-
- optional: (string){ |(*(string){ "optional set" }, (string){ string }) }
490-
- }
491-
- }, (#struct){
492-
- kind: (string){ "one" }
493-
- one: (#struct){
494-
- oneField: (string){ "value" }
495-
- }
496-
- }, (#struct){
497-
+ oneOrTwo: (#struct){
498-
+ two: (#struct){
499-
+ optional?: (string){ string }
500-
+ }
501-
+ kind: (string){ "two" }
502-
+ }
503-
+ }
504-
+ #Application: (#struct){
505-
+ oneOrTwo: (#struct){ |(*(#struct){
506-
+ kind: (string){ "one" }
507-
+ one: (#struct){
508-
+ oneField: (string){ "value" }
509-
+ }
510-
+ }, *(#struct){
511-
+ kind: (string){ "two" }
512-
+ two: (#struct){
513-
+ optional?: (string){ string }
514-
+ }
515-
+ }) }
516-
+ }
517-
+ }
518-
+ local: (struct){
519-
+ out: (#struct){
520405
+ oneOrTwo: (#struct){
521406
+ two: (#struct){
522407
+ optional?: (string){ string }
@@ -525,16 +410,11 @@ diff old new
525410
+ }
526411
+ }
527412
+ #Application: (#struct){
528-
+ oneOrTwo: (#struct){ |(*(#struct){
529-
+ kind: (string){ "one" }
530-
+ one: (#struct){
531-
+ oneField: (string){ "value" }
532-
+ }
533-
+ }, *(#struct){
534-
kind: (string){ "two" }
535-
two: (#struct){
536-
optional?: (string){ string }
537-
@@ -168,45 +138,48 @@
413+
+ oneOrTwo: (#struct){ |((#struct){
414+
kind: (string){ "one" }
415+
one: (#struct){
416+
oneField: (string){ "value" }
417+
@@ -168,45 +153,48 @@
538418
issue3967: (struct){
539419
error: (struct){
540420
nested: (struct){

internal/core/adt/disjunct2.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,12 @@ func (n *nodeContext) doDisjunct(c Conjunct, m defaultMode, mode runMode, orig *
504504

505505
n.scheduler.blocking = n.scheduler.blocking[:0]
506506

507+
// TODO(perf): do not set to nil, but rather maintain an index to unwind
508+
// to avoid allocting new arrays.
509+
saved := n.ctx.blocking
510+
n.ctx.blocking = nil
511+
defer func() { n.ctx.blocking = saved }()
512+
507513
d := oc.cloneRoot(n)
508514

509515
n.ctx.pushOverlay(n.node, oc.vertexMap)
@@ -526,12 +532,6 @@ func (n *nodeContext) doDisjunct(c Conjunct, m defaultMode, mode runMode, orig *
526532

527533
oc.unlinkOverlay()
528534

529-
// TODO(perf): do not set to nil, but rather maintain an index to unwind
530-
// to avoid allocting new arrays.
531-
saved := n.ctx.blocking
532-
n.ctx.blocking = nil
533-
defer func() { n.ctx.blocking = saved }()
534-
535535
d.defaultMode = n.defaultMode
536536
d.origDefaultMode = m
537537

0 commit comments

Comments
 (0)