Skip to content

Commit

Permalink
internal/core/adt: evaluate packages after loading
Browse files Browse the repository at this point in the history
This allows us to do more robust error checking
for upcoming changes.
It also eliminates some V2 vs V3 differences.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ieb45c50c6db825386f1ae1c7453c184a0f6484c2
Dispatch-Trailer: {"type":"trybot","CL":1200792,"patchset":1,"ref":"refs/changes/92/1200792/1","targetBranch":"master"}
  • Loading branch information
mpvl authored and cueckoo committed Sep 6, 2024
1 parent ffe934e commit 99cff3c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 190 deletions.
8 changes: 4 additions & 4 deletions cue/testdata/definitions/hidden.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ package pkg

#D: {_val: f: 3}
-- out/eval/stats --
Leaks: 1
Freed: 29
Leaks: 0
Freed: 30
Reused: 24
Allocs: 6
Retain: 2
Retain: 0

Unifications: 30
Conjuncts: 40
Disjuncts: 31
Disjuncts: 30
-- out/evalalpha --
Errors:
e._name.c: field not allowed:
Expand Down
16 changes: 8 additions & 8 deletions cue/testdata/export/issue854.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ package c
theb: 〈import;"mod.test/b"〉.name
}
-- out/eval/stats --
Leaks: 4
Freed: 2
Reused: 0
Allocs: 6
Retain: 8
Leaks: 0
Freed: 7
Reused: 2
Allocs: 5
Retain: 0

Unifications: 6
Conjuncts: 8
Disjuncts: 8
Unifications: 7
Conjuncts: 9
Disjuncts: 7
-- out/eval --
(struct){
theb: (_|_){
Expand Down
14 changes: 7 additions & 7 deletions cue/testdata/packages/embed.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ package baz

x: 1
-- out/eval/stats --
Leaks: 2
Freed: 9
Reused: 6
Leaks: 0
Freed: 15
Reused: 10
Allocs: 5
Retain: 4
Retain: 2

Unifications: 11
Conjuncts: 25
Disjuncts: 13
Unifications: 15
Conjuncts: 29
Disjuncts: 17
-- out/evalalpha --
(struct){
z: (int){ 3 }
Expand Down
14 changes: 7 additions & 7 deletions cue/testdata/packages/issue398.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ package baz

xx: 1
-- out/eval/stats --
Leaks: 1
Freed: 6
Reused: 3
Leaks: 0
Freed: 9
Reused: 5
Allocs: 4
Retain: 2
Retain: 0

Unifications: 7
Conjuncts: 13
Disjuncts: 8
Unifications: 9
Conjuncts: 15
Disjuncts: 9
-- out/evalalpha --
(struct){
zz: (int){ 3 }
Expand Down
10 changes: 5 additions & 5 deletions cue/testdata/packages/sub.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ package pkg1

Object: "World"
-- out/eval/stats --
Leaks: 2
Freed: 2
Leaks: 0
Freed: 4
Reused: 0
Allocs: 4
Retain: 3
Retain: 1

Unifications: 4
Conjuncts: 5
Disjuncts: 4
Conjuncts: 6
Disjuncts: 5
-- out/eval --
(string){
"Hello World!"
Expand Down
14 changes: 7 additions & 7 deletions cue/testdata/references/package.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ Settings: {}
-- out/ --

-- out/eval/stats --
Leaks: 1
Freed: 4
Leaks: 0
Freed: 6
Reused: 1
Allocs: 4
Retain: 2
Allocs: 5
Retain: 1

Unifications: 5
Conjuncts: 6
Disjuncts: 6
Unifications: 6
Conjuncts: 7
Disjuncts: 7
-- out/eval --
(struct){
a: (int){ 1 }
Expand Down
2 changes: 2 additions & 0 deletions internal/core/adt/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ func (x *ImportReference) resolve(ctx *OpContext, state combinedFlags) *Vertex {
v := ctx.Runtime.LoadImport(path)
if v == nil {
ctx.addErrf(EvalError, x.Src.Pos(), "cannot find package %q", path)
} else if !v.isFinal() {
v.Finalize(ctx)
}
return v
}
Expand Down
97 changes: 0 additions & 97 deletions internal/core/export/testdata/selfcontained/import.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -75,103 +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: {
@@ -42,7 +45,7 @@
let W = {
a: _hidden_567475F3
_hidden_567475F3: {
- a: 1
+ a: b
}
b: 1
x: {
-- 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
55 changes: 0 additions & 55 deletions internal/core/export/testdata/selfcontained/issue2247.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -35,61 +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: {
out: Q
}.out
g: {
out: Q
}.out
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 99cff3c

Please sign in to comment.