Skip to content

Commit

Permalink
internal/core/adt: adapt handling of inline structs
Browse files Browse the repository at this point in the history
Before inline structs were always recomputed for any
given arc, so it was safe to assume a rooted
struct could be dropped.

This does not have a big impact on performance as of
this CL, but it will have a big impact in combination
with upcoming changes.

Now inline structs can be structure shared, it is
important to know where the inline struct orginated.
This has an effect on dependency analysis.

It also allows us to work around some issues with
internal/core/dep w.r.t. these upcoming changes.

Issue #2854

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: Id795fc7d710b992782342d4db046a41f9ef703ff
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202264
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Matthew Sackman <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mpvl committed Oct 10, 2024
1 parent 90b5c9d commit 99407a4
Show file tree
Hide file tree
Showing 15 changed files with 450 additions and 75 deletions.
210 changes: 210 additions & 0 deletions cue/testdata/builtins/incomplete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,216 @@ Retain: 61
Unifications: 109
Conjuncts: 264
Disjuncts: 156
-- out/evalalpha --
Errors:
badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
./in.cue:79:11
badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
./in.cue:79:11
badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
./in.cue:85:11
./in.cue:86:11

Result:
(_|_){
// [eval]
list1: (struct){
Out1: (#list){
0: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
}
Out2: (#list){
0: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
}
Out3: (#list){
0: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
}
Top: (#list){
0: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
}
_Sub: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
a: (struct){
}
}
list2: (struct){
Out1: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
Out2: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
Out3: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
_Top: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
#Sub: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
a: (struct){
}
}
value1: (struct){
a: (_|_){
// [incomplete] value1.a: unresolved disjunction 'sf' | 'dd' (type bytes):
// ./in.cue:39:5
}
}
value2: (_|_){
// [incomplete] value2: unresolved disjunction 'sf' | 'dd' (type bytes):
// ./in.cue:43:2
}
incompleteArgDecimalList: (struct){
a: (#struct){
param: (int){ 123 }
transformed: (int){ 123 }
max: (int){ 123 }
}
#a: (#struct){
param: (int){ int }
transformed: (_|_){
// [incomplete] incompleteArgDecimalList.#a.transformed: operand param of '+' not concrete (was int):
// ./in.cue:50:17
}
max: (_|_){
// [incomplete] 0: operand param of '+' not concrete (was int):
// ./in.cue:50:17
}
}
}
incompleteArgStringList: (struct){
a: (#struct){
param: (string){ "123" }
transformed: (string){ "123" }
joined: (string){ "123" }
}
#a: (#struct){
param: (string){ string }
transformed: (_|_){
// [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
// ./in.cue:59:16
// ./in.cue:58:16
}
joined: (_|_){
// [incomplete] 0: non-concrete value string in operand to +:
// ./in.cue:59:16
// ./in.cue:58:16
}
}
}
incompleteList: (struct){
x: (_){ _ }
decimal: (_|_){
// [incomplete] incompleteList.decimal: non-concrete list for argument 0:
// ./in.cue:66:11
}
str: (_|_){
// [incomplete] incompleteList.str: non-concrete list for argument 0:
// ./in.cue:67:11
}
}
incompleteListError: (struct){
x: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:72:11
}
y: (_){ _ }
decimal: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:72:11
}
str: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:72:11
}
}
badListType: (_|_){
// [eval]
x: (int){ 2 }
decimal: (_|_){
// [eval] badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
// ./in.cue:79:11
}
str: (_|_){
// [eval] badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
// ./in.cue:79:11
}
}
badListError: (_|_){
// [eval]
x: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:85:11
// ./in.cue:86:11
}
y: (string){ "foo" }
decimal: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:85:11
// ./in.cue:86:11
}
str: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:85:11
// ./in.cue:86:11
}
}
multipleErrors: (struct){
#T: (#struct){
params: (#struct){
x: (string){ string }
y: (string){ string }
}
out: (_|_){
// [incomplete] multipleErrors.#T.out: error in call to text/template.Execute: cannot convert non-concrete value string:
// ./in.cue:99:8
// ./in.cue:96:4
}
}
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -89,7 +89,7 @@
// ./in.cue:50:17
}
max: (_|_){
- // [incomplete] incompleteArgDecimalList.#a.0: operand param of '+' not concrete (was int):
+ // [incomplete] 0: operand param of '+' not concrete (was int):
// ./in.cue:50:17
}
}
@@ -108,7 +108,7 @@
// ./in.cue:58:16
}
joined: (_|_){
- // [incomplete] incompleteArgStringList.#a.0: non-concrete value string in operand to +:
+ // [incomplete] 0: non-concrete value string in operand to +:
// ./in.cue:59:16
// ./in.cue:58:16
}
-- out/eval --
Errors:
badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
Expand Down
78 changes: 64 additions & 14 deletions cue/testdata/builtins/validators.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,25 @@ Disjuncts: 131
Errors:
callOfCallToValidator.e: cannot call previously called validator b:
./in.cue:94:5
issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:1:24
./issue3418.cue:1:16
./issue3418.cue:1:31
./issue3418.cue:1:35
./issue3418.cue:1:37
issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:2:41
./issue3418.cue:2:16
./issue3418.cue:2:48
./issue3418.cue:2:52
./issue3418.cue:2:54
issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:6:5
./issue3418.cue:4:5
./issue3418.cue:6:12
./issue3418.cue:6:16
./issue3418.cue:6:18
issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:10:5
./issue3418.cue:9:5
./issue3418.cue:10:12
Expand Down Expand Up @@ -337,15 +337,15 @@ Result:
issue3418: (_|_){
// [eval]
t1: (_|_){
// [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:1:24
// ./issue3418.cue:1:16
// ./issue3418.cue:1:31
// ./issue3418.cue:1:35
// ./issue3418.cue:1:37
}
t2: (_|_){
// [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:2:41
// ./issue3418.cue:2:16
// ./issue3418.cue:2:48
Expand All @@ -355,7 +355,7 @@ Result:
t3: (_|_){
// [eval]
x: (_|_){
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:6:5
// ./issue3418.cue:4:5
// ./issue3418.cue:6:12
Expand All @@ -366,7 +366,7 @@ Result:
t4: (_|_){
// [eval]
x: (_|_){
// [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:10:5
// ./issue3418.cue:9:5
// ./issue3418.cue:10:12
Expand Down Expand Up @@ -446,15 +446,36 @@ Result:
diff old new
--- old
+++ new
@@ -16,7 +16,6 @@
issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
@@ -1,49 +1,43 @@
Errors:
callOfCallToValidator.e: cannot call previously called validator b:
./in.cue:94:5
-issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:1:24
./issue3418.cue:1:16
./issue3418.cue:1:31
./issue3418.cue:1:35
./issue3418.cue:1:37
-issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:2:41
./issue3418.cue:2:16
./issue3418.cue:2:48
./issue3418.cue:2:52
./issue3418.cue:2:54
-issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:6:5
./issue3418.cue:4:5
- ./issue3418.cue:5:5
./issue3418.cue:6:12
./issue3418.cue:6:16
./issue3418.cue:6:18
@@ -26,24 +25,19 @@
-issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:10:5
./issue3418.cue:9:5
./issue3418.cue:10:12
./issue3418.cue:10:16
./issue3418.cue:10:18
Expand Down Expand Up @@ -513,15 +534,44 @@ diff old new
// ./in.cue:112:20
}
}
@@ -171,7 +158,6 @@
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
@@ -150,7 +137,7 @@
issue3418: (_|_){
// [eval]
t1: (_|_){
- // [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+ // [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:1:24
// ./issue3418.cue:1:16
// ./issue3418.cue:1:31
@@ -158,7 +145,7 @@
// ./issue3418.cue:1:37
}
t2: (_|_){
- // [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+ // [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:2:41
// ./issue3418.cue:2:16
// ./issue3418.cue:2:48
@@ -168,10 +155,9 @@
t3: (_|_){
// [eval]
x: (_|_){
- // [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+ // [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:6:5
// ./issue3418.cue:4:5
- // ./issue3418.cue:5:5
// ./issue3418.cue:6:12
// ./issue3418.cue:6:16
// ./issue3418.cue:6:18
@@ -186,7 +172,6 @@
@@ -180,13 +166,12 @@
t4: (_|_){
// [eval]
x: (_|_){
- // [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+ // [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:10:5
// ./issue3418.cue:9:5
// ./issue3418.cue:10:12
// ./issue3418.cue:10:16
// ./issue3418.cue:10:18
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/cycle/chain.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Allocs: 20363
Retain: 0

Unifications: 7655
Conjuncts: 109511
Conjuncts: 109521
Disjuncts: 13941
-- out/evalalpha --
Errors:
Expand Down Expand Up @@ -735,7 +735,7 @@ diff old new
-Conjuncts: 3177
-Disjuncts: 1979
+Unifications: 7655
+Conjuncts: 109511
+Conjuncts: 109521
+Disjuncts: 13941
-- diff/-out/evalalpha<==>+out/eval --
diff old new
Expand Down
Loading

0 comments on commit 99407a4

Please sign in to comment.