Skip to content

Commit

Permalink
internal/core/adt: do not proactively evaluate let
Browse files Browse the repository at this point in the history
This mimics the behavior of V2 and fixes some
spurious structural cycles when using let.
The main fix is in issue990.txtar.

Note that some evaluations get more expensive.
This is to be expected, as being more permissive
with cycles means that we may take a bit longer
to detect them.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: If3fef8af1320fde0be2bfc187df0d9d2e482fb28
Reviewed-on: https://gerrithub.io/c/cue-lang/cue/+/1206383
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Jan 6, 2025
1 parent 3f4e72d commit d8fabe1
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 193 deletions.
16 changes: 8 additions & 8 deletions cue/testdata/benchmarks/issue1684.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ nestedClosed: passing: {
}
-- out/evalalpha/stats --
Leaks: 2135
Freed: 530
Reused: 530
Freed: 658
Reused: 658
Allocs: 2135
Retain: 0

Unifications: 475
Conjuncts: 4351
Disjuncts: 790
Conjuncts: 4799
Disjuncts: 918
-- out/evalalpha --
(struct){
#Secret: (#struct){
Expand Down Expand Up @@ -144,17 +144,17 @@ diff old new
-Reused: 1064282
-Allocs: 51
+Leaks: 2135
+Freed: 530
+Reused: 530
+Freed: 658
+Reused: 658
+Allocs: 2135
Retain: 0

-Unifications: 792123
-Conjuncts: 2480117
-Disjuncts: 1064333
+Unifications: 475
+Conjuncts: 4351
+Disjuncts: 790
+Conjuncts: 4799
+Disjuncts: 918
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
Expand Down
51 changes: 8 additions & 43 deletions cue/testdata/comprehensions/issue837.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ Conjuncts: 563
Disjuncts: 30
-- out/evalalpha --
Errors:
#Configure.service.description.configed.labstr: undefined field: label:
./in.cue:51:14
#DoDeploy.deployment.description.service.description.configed.labstr: undefined field: label:
./in.cue:51:14
#Configure.service.description.role: undefined field: role:
./in.cue:40:19
#DoDeploy.deployment.description.service.description.role: undefined field: role:
./in.cue:40:19
#RelabelService.out.labstr: undefined field: label:
./in.cue:51:14

Expand Down Expand Up @@ -133,8 +133,8 @@ Result:
}
}
role: (_|_){
// [eval] #DoDeploy.deployment.description.service.description.configed.labstr: undefined field: label:
// ./in.cue:51:14
// [eval] #DoDeploy.deployment.description.service.description.role: undefined field: role:
// ./in.cue:40:19
}
}
}
Expand All @@ -159,8 +159,8 @@ Result:
}
}
role: (_|_){
// [eval] #Configure.service.description.configed.labstr: undefined field: label:
// ./in.cue:51:14
// [eval] #Configure.service.description.role: undefined field: role:
// ./in.cue:40:19
}
}
}
Expand Down Expand Up @@ -202,19 +202,6 @@ Result:
diff old new
--- old
+++ new
@@ -1,8 +1,8 @@
Errors:
-#Configure.service.description.role: undefined field: role:
- ./in.cue:40:19
-#DoDeploy.deployment.description.service.description.role: undefined field: role:
- ./in.cue:40:19
+#Configure.service.description.configed.labstr: undefined field: label:
+ ./in.cue:51:14
+#DoDeploy.deployment.description.service.description.configed.labstr: undefined field: label:
+ ./in.cue:51:14
#RelabelService.out.labstr: undefined field: label:
./in.cue:51:14

@@ -13,24 +13,10 @@
ref: (#struct){
kind: (string){ "deployment" }
Expand Down Expand Up @@ -308,28 +295,6 @@ diff old new
service: (_|_){
// [eval]
description: (_|_){
@@ -106,8 +57,8 @@
}
}
role: (_|_){
- // [eval] #DoDeploy.deployment.description.service.description.role: undefined field: role:
- // ./in.cue:40:19
+ // [eval] #DoDeploy.deployment.description.service.description.configed.labstr: undefined field: label:
+ // ./in.cue:51:14
}
}
}
@@ -132,8 +83,8 @@
}
}
role: (_|_){
- // [eval] #Configure.service.description.role: undefined field: role:
- // ./in.cue:40:19
+ // [eval] #Configure.service.description.configed.labstr: undefined field: label:
+ // ./in.cue:51:14
}
}
}
@@ -141,9 +92,7 @@
#RelabelService: (_|_){
// [eval]
Expand Down
41 changes: 12 additions & 29 deletions cue/testdata/cycle/evaluate.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,11 @@ Disjuncts: 192
-- out/evalalpha --
Errors:
closeCycle.c: structural cycle
letCycleFail.t1.a.c: structural cycle
printCycle.a.X: structural cycle
structCycle.c: structural cycle
letCycleOK.t2.a.X: structural cycle:
./in.cue:23:11
letCycleFail.t1.a.X: structural cycle:
./in.cue:33:11
disjunctionCycle.b: cannot use 1 (type int) as type list:
./in.cue:56:5
./in.cue:56:9
Expand Down Expand Up @@ -186,8 +185,7 @@ Result:
// [structural cycle] letCycleFail.t1.a.X: structural cycle
}
c: (_|_){
// [structural cycle] letCycleFail.t1.a.X: structural cycle:
// ./in.cue:33:11
// [structural cycle] letCycleFail.t1.a.c: structural cycle
}
}
}
Expand Down Expand Up @@ -350,7 +348,7 @@ Result:
diff old new
--- old
+++ new
@@ -1,50 +1,49 @@
@@ -1,50 +1,48 @@
Errors:
-closeCycle.a: structural cycle
-closeCycle.b.d: structural cycle
Expand All @@ -359,19 +357,17 @@ diff old new
- ./in.cue:105:12
- ./in.cue:106:6
- ./in.cue:107:5
-letCycleFail.t1.a.c: structural cycle
+closeCycle.c: structural cycle
letCycleFail.t1.a.c: structural cycle
-structCycle.a: structural cycle
-structCycle.b.d: structural cycle
-disjunctionCycle.a: cannot use 1 (type int) as type list:
- ./in.cue:56:5
- ./in.cue:56:9
+closeCycle.c: structural cycle
+printCycle.a.X: structural cycle
+structCycle.c: structural cycle
+letCycleOK.t2.a.X: structural cycle:
+ ./in.cue:23:11
+letCycleFail.t1.a.X: structural cycle:
+ ./in.cue:33:11
disjunctionCycle.b: cannot use 1 (type int) as type list:
./in.cue:56:5
./in.cue:56:9
Expand Down Expand Up @@ -428,16 +424,10 @@ diff old new
}
}
}
@@ -59,20 +58,16 @@
// [structural cycle] letCycleFail.t1.a.X: structural cycle
}
c: (_|_){
- // [structural cycle] letCycleFail.t1.a.c: structural cycle
- }
- }
- }
- t2: (struct){
- a: (struct){
@@ -65,14 +63,9 @@
}
t2: (struct){
a: (struct){
- let X#4 = (struct){
- let X#4 = (_|_){
- // [structural cycle] letCycleFail.t2.a.X.X: structural cycle:
Expand All @@ -446,20 +436,13 @@ diff old new
- x: (struct){
- y: (string){ "" }
- }
+ // [structural cycle] letCycleFail.t1.a.X: structural cycle:
+ // ./in.cue:33:11
+ }
+ }
+ }
+ t2: (struct){
+ a: (struct){
+ let X#4 = (_|_){
+ // [structural cycle] letCycleFail.t2.a.X: structural cycle:
+ // ./in.cue:43:6
}
x: (struct){
y: (string){ "" }
@@ -88,17 +83,17 @@
@@ -88,17 +81,17 @@
disjunctionCycle: (_|_){
// [eval]
a: (_|_){
Expand Down Expand Up @@ -488,7 +471,7 @@ diff old new
// ./in.cue:56:5
// ./in.cue:56:9
}
@@ -124,80 +119,77 @@
@@ -124,80 +117,77 @@
}
b: (struct){
}
Expand Down Expand Up @@ -618,7 +601,7 @@ diff old new
}
}
closeFail: (_|_){
@@ -207,21 +199,22 @@
@@ -207,21 +197,22 @@
}
x: (_|_){
// [eval]
Expand Down
Loading

0 comments on commit d8fabe1

Please sign in to comment.