Skip to content

Commit

Permalink
internal/core/dep: fix differences
Browse files Browse the repository at this point in the history
The additional Finalize is necessary with the new
evaluator. It also prevents some bugs down the line.

Note that evalv2 and evalv3 have a very different
order of evaluation, which may lead to different
locations in the code for Finalize to be needed.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I461c81d7f1c743aa9cd8faa56a47cba9723e8dfa
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202782
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
mpvl committed Oct 21, 2024
1 parent 2fc301a commit cc04ebe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 139 deletions.
4 changes: 4 additions & 0 deletions internal/core/dep/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ func (c *visitor) reportDependency(env *adt.Environment, ref adt.Resolver, v *ad

c.numRefs++

if c.ctxt.Version == internal.DevVersion {
v.Finalize(c.ctxt)
}

d := Dependency{
Node: v,
Reference: altRef,
Expand Down
88 changes: 0 additions & 88 deletions internal/core/export/testdata/selfcontained/import.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -75,94 +75,6 @@ wa: pkg.w.a
// Never expand builtin packages.
run: exec.Run
_hidden: int
-- out/self-v3-noshare/expand_imports --
import "tool/exec"

// Can be inlined.
v: V

// Do not simplify because of multiple usages of enclosing struct.
x: B.c
y: B

// Cannot simplify because of definition.
z: F.#x

// Two references to package, but since the second is a scalar, it can be
// hoisted and only one reference remains. So there is still no need for
// a helper.
// TODO: fix this to eliminate the helper.
w: W
wa: W.a

// Never expand builtin packages.
run: exec.Run
_hidden: int

//cue:path: "mod.test/a/pkg".v.v
let V = {
x: 3
y: x
}

//cue:path: "mod.test/a/pkg".a.b
let B = {
c: {
d: int
}
}

//cue:path: "mod.test/a/pkg".#Def.f
let F = {
#x: {
g: int
}
}

//cue:path: "mod.test/a/pkg".w
let W = {
a: _hidden_567475F3
_hidden_567475F3: {
a: b
}
b: 1
x: {
_hidden2_567475F3: _hidden_567475F3
y: _hidden2_567475F3
}
}
-- diff/-out/self-v3-noshare/expand_imports<==>+out/self/expand_imports --
diff old new
--- old
+++ new
@@ -1,10 +1,7 @@
import "tool/exec"

// Can be inlined.
-v: {
- x: 3
- y: x
-}
+v: V

// Do not simplify because of multiple usages of enclosing struct.
x: B.c
@@ -24,6 +21,12 @@
run: exec.Run
_hidden: int

+//cue:path: "mod.test/a/pkg".v.v
+let V = {
+ x: 3
+ y: x
+}
+
//cue:path: "mod.test/a/pkg".a.b
let B = {
c: {
-- diff/self/todo/p2 --
Investigate differences.
We assign p2, because the differences only appear with sharing off.
-- out/self/expand_imports --
import "tool/exec"

Expand Down
51 changes: 0 additions & 51 deletions internal/core/export/testdata/selfcontained/issue2247.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -35,57 +35,6 @@ r: {out: k: l: string}.out
import "example.com/t"

f: t.p
-- out/self-v3-noshare/expand_imports --
f: P

//cue:path: "example.com/t".p
let P = {
c: [int]
d: [c][0]
// TODO: simplify these:
e: {
out: c
}.out
f: Q
g: Q
h: {
out: {
r: {
s: string
}
}
}.out
i: h.r
j: h.r.s
k: K
l: K.l
}

//cue:path: "example.com/t".q
let Q = {
x: [...int]
}

//cue:path: "example.com/t".r.k
let K = {
l: string
}
-- diff/-out/self-v3-noshare/expand_imports<==>+out/self/expand_imports --
diff old new
--- old
+++ new
@@ -1,4 +1,7 @@
-f: {
+f: P
+
+//cue:path: "example.com/t".p
+let P = {
c: [int]
d: [c][0]
// TODO: simplify these:
-- diff/self/todo/p2 --
Unnecessary let indirection.
We assign p2, because the differences only appear with sharing off.
-- out/self/expand_imports --
f: {
c: [int]
Expand Down

0 comments on commit cc04ebe

Please sign in to comment.