Skip to content

Commit 4ae206d

Browse files
committed
internal/core/debug: dereference non-rooted
A related change in the v3 evaluator allows inline structs to be structure shared. As a consequence, references may be meaningless, as they have no full path. This change does not print a shared address if a node is not rooted. Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: Id10ce012aa5eb7623ac6c3730d9f4d36d44d27cd Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202218 Reviewed-by: Matthew Sackman <matthew@cue.works> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
1 parent c558da0 commit 4ae206d

File tree

5 files changed

+51
-69
lines changed

5 files changed

+51
-69
lines changed

cue/testdata/compile/scope.txtar

+4-9
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ Result:
113113
let B#1 = (struct){
114114
open: (int){ int }
115115
}
116-
f: ~(B#1)
116+
f: (struct){
117+
open: (int){ int }
118+
}
117119
schema: (_|_){
118120
// [structural cycle]
119121
next: (_|_){
@@ -135,14 +137,7 @@ diff old new
135137

136138
Result:
137139
(_|_){
138-
@@ -23,17 +23,14 @@
139-
let B#1 = (struct){
140-
open: (int){ int }
141-
}
142-
- f: (struct){
143-
- open: (int){ int }
144-
- }
145-
+ f: ~(B#1)
140+
@@ -29,11 +29,10 @@
146141
schema: (_|_){
147142
// [structural cycle]
148143
next: (_|_){

cue/testdata/eval/let.txtar

+22-15
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,16 @@ Result:
335335
"\(〈0;let X#1F〉)": 〈0;let X#1F〉
336336
}
337337
}
338-
"0": ~(nestedFor.X#1E)
339-
"1": ~(nestedFor.X#1E)
338+
"0": (struct){
339+
let X#1Fmulti = 〈1;x〉
340+
"2": (int){ 2 }
341+
"1": (int){ 1 }
342+
}
343+
"1": (struct){
344+
let X#1Fmulti = 〈1;x〉
345+
"2": (int){ 2 }
346+
"1": (int){ 1 }
347+
}
340348
}
341349
keepDescending: (struct){
342350
t1: (struct){
@@ -493,26 +501,25 @@ diff old new
493501
}
494502
}
495503
nestedFor: (struct){
496-
@@ -188,16 +164,8 @@
497-
"\(〈0;let X#1F〉)": 〈0;let X#1F〉
498-
}
504+
@@ -190,13 +166,13 @@
499505
}
500-
- "0": (struct){
501-
- let X#1Fmulti = 〈1;x〉
506+
"0": (struct){
507+
let X#1Fmulti = 〈1;x〉
502508
- "1": (int){ 1 }
503509
- "2": (int){ 2 }
504-
- }
505-
- "1": (struct){
506-
- let X#1Fmulti = 〈1;x〉
510+
+ "2": (int){ 2 }
511+
+ "1": (int){ 1 }
512+
}
513+
"1": (struct){
514+
let X#1Fmulti = 〈1;x〉
507515
- "1": (int){ 1 }
508516
- "2": (int){ 2 }
509-
- }
510-
+ "0": ~(nestedFor.X#1E)
511-
+ "1": ~(nestedFor.X#1E)
517+
+ "2": (int){ 2 }
518+
+ "1": (int){ 1 }
519+
}
512520
}
513521
keepDescending: (struct){
514-
t1: (struct){
515-
@@ -234,8 +202,8 @@
522+
@@ -234,8 +210,8 @@
516523
b: (string){ "e" }
517524
}
518525
let T#23multi = 〈1;v〉

cue/testdata/references/let.txtar

+6-22
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,17 @@ Disjuncts: 121
442442
let x#E = (struct){
443443
a: (int){ 1 }
444444
}
445-
0: ~(scalarReference.inList.p0.x#E)
445+
0: (struct){
446+
a: (int){ 1 }
447+
}
446448
}
447449
p1: (#list){
448450
let x#F = (struct){
449451
a: (int){ 1 }
450452
}
451-
0: ~(scalarReference.inList.p1.x#F)
453+
0: (struct){
454+
a: (int){ 1 }
455+
}
452456
}
453457
}
454458
}
@@ -490,26 +494,6 @@ diff old new
490494
// ./in.cue:54:17
491495
}
492496
}
493-
@@ -145,17 +145,13 @@
494-
let x#E = (struct){
495-
a: (int){ 1 }
496-
}
497-
- 0: (struct){
498-
- a: (int){ 1 }
499-
- }
500-
+ 0: ~(scalarReference.inList.p0.x#E)
501-
}
502-
p1: (#list){
503-
let x#F = (struct){
504-
a: (int){ 1 }
505-
}
506-
- 0: (struct){
507-
- a: (int){ 1 }
508-
- }
509-
+ 0: ~(scalarReference.inList.p1.x#F)
510-
}
511-
}
512-
}
513497
-- diff/todo/p3 --
514498
Investigate let divergence. Probably okay.
515499
-- out/eval --

cue/testdata/resolve/035_excluded_embedding_from_closing.txtar

+4-9
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ Result:
9393
let B#1 = (#struct){
9494
open: (int){ int }
9595
}
96-
b: ~(#S.B#1)
96+
b: (#struct){
97+
open: (int){ int }
98+
}
9799
}
98100
V: (_|_){
99101
// [eval]
@@ -139,14 +141,7 @@ diff old new
139141
./in.cue:10:5
140142

141143
Result:
142-
@@ -23,39 +17,31 @@
143-
let B#1 = (#struct){
144-
open: (int){ int }
145-
}
146-
- b: (#struct){
147-
- open: (int){ int }
148-
- }
149-
+ b: ~(#S.B#1)
144+
@@ -29,33 +23,27 @@
150145
}
151146
V: (_|_){
152147
// [eval]

internal/core/debug/debug.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,36 @@ func (w *printer) shared(v *adt.Vertex) {
131131
// printShared prints a reference to a structure-shared node that is a value
132132
// of v, if it is a shared node. It reports the dereferenced node and whether
133133
// the node was printed.
134-
func (w *printer) printShared(v *adt.Vertex) (x *adt.Vertex, ok bool) {
134+
func (w *printer) printShared(v0 *adt.Vertex) (x *adt.Vertex, ok bool) {
135+
135136
// Handle cyclic shared nodes differently. If a shared node was part of
136137
// a disjunction, it will still be wrapped in a disjunct Vertex.
137138
// Similarly, a shared node should never point to a disjunct directly,
138139
// but rather to the original arc that subsequently points to a
139140
// disjunct.
140-
v = v.DerefDisjunct()
141-
useReference := v.IsShared
142-
isCyclic := v.IsCyclic
143-
s, ok := v.BaseValue.(*adt.Vertex)
144-
v = v.DerefValue()
145-
isCyclic = isCyclic || v.IsCyclic
141+
v0 = v0.DerefDisjunct()
142+
isCyclic := v0.IsCyclic
143+
s, ok := v0.BaseValue.(*adt.Vertex)
144+
v1 := v0.DerefValue()
145+
useReference := v0.IsShared && v1.Rooted()
146+
isCyclic = isCyclic || v1.IsCyclic
146147
_ = isCyclic
147148
// NOTE(debug): use this line instead of the following to expand shared
148149
// cases where it is safe to do so.
149150
// if useReference && isCyclic && ok && len(v.Arcs) > 0 {
150-
if useReference && ok && len(v.Arcs) > 0 {
151-
w.shared(s)
152-
return v, true
151+
if useReference && ok && len(v1.Arcs) > 0 {
152+
w.shared(v1)
153+
return v1, true
153154
}
154-
if !w.pushVertex(v) {
155+
if !w.pushVertex(v1) {
155156
if s != nil {
156157
w.shared(s)
157158
w.string(" =>")
158159
}
159-
w.shared(v)
160-
return v, true
160+
w.shared(v1)
161+
return v1, true
161162
}
162-
return v, false
163+
return v1, false
163164
}
164165

165166
func (w *printer) pushVertex(v *adt.Vertex) bool {

0 commit comments

Comments
 (0)