Skip to content

Commit c8170aa

Browse files
committed
internal/core/dep: fix handling sharing in non-rooted nodes
If a non-rooted/anonymous node uses structure sharing, we need to treat the references within the structure-shared node as non-rooted as well. The reasons for this is that otherwise this reference does not have an addressable location. It is hard to detect this from the context of a structure- shared node. In CL https://cuelang.org/cl/1202268, this was done by investigating the context. For this we need to be slightly more aggressive picking the current reference. Test changes: - issue2247: reverted to the state before cl/1202268. Not great, but not wrong. - selfref: one good improvement, one regression. - import: reverts to V2, but not a huge deal - let2: now refers to references in let, instead of original. This is not wrong per se, and maybe even desirable. Fixes #3646 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I88f89720be95547bb8f897c34f041af6fb8d65eb Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207402 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Matthew Sackman <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent f8defbb commit c8170aa

File tree

8 files changed

+87
-21
lines changed

8 files changed

+87
-21
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Issue #3646
2+
3+
env CUE_EXPERIMENT=evalv3=0
4+
exec cue cmd two
5+
stdout 'msg.*hello'
6+
7+
env CUE_EXPERIMENT=evalv3=1
8+
exec cue cmd two
9+
stdout 'msg.*hello'
10+
11+
-- input_tool.cue --
12+
package p
13+
14+
import (
15+
"tool/exec"
16+
"encoding/json"
17+
)
18+
19+
command: {
20+
one: exec.Run & {
21+
stdin: "{\"msg\": \"hello\"}"
22+
cmd: ["cat"]
23+
stdout: string
24+
}
25+
two: exec.Run & {
26+
let data = json.Unmarshal(one.stdout)
27+
cmd: ["cat"] // "true" is printed for each json value read
28+
stdin: json.Marshal(data) + "\n"
29+
}
30+
}

cmd/cue/cmd/testdata/script/cmd_print.txtar

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
env CUE_EXPERIMENT=evalv3=0
2+
exec cue cmd print
3+
cmp stdout expect-stdout
4+
5+
env CUE_EXPERIMENT=evalv3=1
16
exec cue cmd print
27
cmp stdout expect-stdout
38

cmd/cue/cmd/testdata/script/def_issue3646.txtar

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
env CUE_EXPERIMENT=evalv3=0
12
exec cue def --inline-imports ./p1
23
stdin stdout
4+
exec cue eval --out=json -
5+
cmp stdout stdout.golden
36

4-
# TODO Fix this test
5-
! exec cue eval --out=json -
7+
env CUE_EXPERIMENT=evalv3=1
8+
exec cue def --inline-imports ./p1
9+
stdin stdout
10+
exec cue eval --out=json -
611
cmp stdout stdout.golden
712

813
-- go.mod --
@@ -38,3 +43,7 @@ package p2
3843

3944
regionMap: #RegionMap
4045
-- stdout.golden --
46+
{
47+
"r": "us-east-1",
48+
"shortRegionName": "ue1"
49+
}

internal/core/dep/dep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func (c *visitor) reportDependency(env *adt.Environment, ref adt.Resolver, v *ad
476476
}
477477
v = w
478478
}
479-
if len(c.pathStack) == 0 && c.topRef != nil {
479+
if inspect && len(c.pathStack) == 0 && c.topRef != nil {
480480
altRef = c.topRef
481481
}
482482

internal/core/dep/testdata/let2.txtar

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# TODO:
2+
# out/dependencies/all: origin should ideally be Let reference not v
3+
14
-- in.cue --
25
v: w: u: d: 0
36

@@ -24,24 +27,29 @@ a: b: {
2427
-- out/dependencies/field --
2528
line reference path of resulting vertex
2629
-- out/dependencies-v3/all --
27-
line reference path of resulting vertex
28-
12: X1 => v.w
29-
13: X2 => v.w
30-
14: X3.w => v.w
31-
20: Y1 => v
32-
21: Y2 => v
30+
line reference path of resulting vertex
31+
3: {c: v}.c.w => v.w
32+
4: {c: {out: v}.out}.c.w => v.w
33+
14: X3.w => v.w
34+
7: v => v
35+
8: v => v
3336
-- diff/-out/dependencies-v3/all<==>+out/dependencies/all --
3437
diff old new
3538
--- old
3639
+++ new
37-
@@ -2,5 +2,5 @@
38-
12: X1 => v.w
39-
13: X2 => v.w
40-
14: X3.w => v.w
40+
@@ -1,6 +1,6 @@
41+
-line reference path of resulting vertex
42+
-12: X1 => v.w
43+
-13: X2 => v.w
44+
-14: X3.w => v.w
4145
-7: v => v
4246
-8: v => v
43-
+20: Y1 => v
44-
+21: Y2 => v
47+
+line reference path of resulting vertex
48+
+3: {c: v}.c.w => v.w
49+
+4: {c: {out: v}.out}.c.w => v.w
50+
+14: X3.w => v.w
51+
+7: v => v
52+
+8: v => v
4553
-- out/dependencies/all --
4654
line reference path of resulting vertex
4755
12: X1 => v.w

internal/core/dep/testdata/selfref.txtar

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#Issue: 1405
2+
3+
# TODO:
4+
# One X.enabled should be a.#combined.enabled
5+
26
-- in.cue --
37
a: {
48
command: alias: {

internal/core/export/testdata/selfcontained/import.txtar

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#inlineImports: true
22

3+
# TODO: slightly more correct is for _hidden_567475F3.a to be `b` and not resolve.
4+
35
-- cue.mod/module.cue --
46
module: "mod.test/a"
57
language: version: "v0.9.0"
@@ -120,7 +122,7 @@ let F = {
120122
let W = {
121123
a: _hidden_567475F3
122124
_hidden_567475F3: {
123-
a: b
125+
a: 1
124126
}
125127
b: 1
126128
x: {

internal/core/export/testdata/selfcontained/issue2247.txtar

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ f: {
4343
e: {
4444
out: c
4545
}.out
46-
f: Q
47-
g: Q
46+
f: {
47+
out: Q
48+
}.out
49+
g: {
50+
out: Q
51+
}.out
4852
h: {
4953
out: {
5054
r: {
@@ -71,7 +75,7 @@ let K = {
7175
diff old new
7276
--- old
7377
+++ new
74-
@@ -25,7 +25,7 @@
78+
@@ -29,7 +29,7 @@
7579
x: [...int]
7680
}
7781

@@ -88,8 +92,12 @@ f: {
8892
e: {
8993
out: c
9094
}.out
91-
f: Q
92-
g: Q
95+
f: {
96+
out: Q
97+
}.out
98+
g: {
99+
out: Q
100+
}.out
93101
h: {
94102
out: {
95103
r: {

0 commit comments

Comments
 (0)