Skip to content

Commit

Permalink
internal/core/adt: fix resolving disjunctions in calls
Browse files Browse the repository at this point in the history
Arguments to calls that were disjunctions were not
always properly resolved, causing the argument to
be top, instead of the right value.

The current solution is not super principled, but does
the job for now. It is quite tricky to find the right balance
as evaluating too aggressively quickly leads to
spurious cycles.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I74b28e5e0b6dfe75e60cb8d5227515128c7c4669
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1206321
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mpvl committed Dec 24, 2024
1 parent b1803fa commit 3ee8b07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 54 deletions.
54 changes: 0 additions & 54 deletions cue/testdata/builtins/args.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,6 @@ Retain: 1
Unifications: 10
Conjuncts: 17
Disjuncts: 15
-- out/evalalpha --
(struct){
issue3584: (struct){
reduced: (struct){
t1: (struct){
ref: (_|_){
// [incomplete] issue3584.reduced.t1.out: error in call to strings.SliceRunes: non-concrete value _:
// ./in.cue:9:7
}
trigger: (int){ |(*(int){ 1 }, (int){ 2 }) }
out: (_|_){
// [incomplete] issue3584.reduced.t1.out: error in call to strings.SliceRunes: non-concrete value _:
// ./in.cue:9:7
}
}
t2: (struct){
x: (_|_){
// [incomplete] issue3584.reduced.t2.x: error in call to math.Abs: non-concrete value _:
// ./in.cue:13:5
}
y: (int){ |(*(int){ 6 }, (int){ 5 }) }
}
}
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -2,12 +2,21 @@
issue3584: (struct){
reduced: (struct){
t1: (struct){
- ref: (string){ "A" }
+ ref: (_|_){
+ // [incomplete] issue3584.reduced.t1.out: error in call to strings.SliceRunes: non-concrete value _:
+ // ./in.cue:9:7
+ }
trigger: (int){ |(*(int){ 1 }, (int){ 2 }) }
- out: (string){ "A" }
+ out: (_|_){
+ // [incomplete] issue3584.reduced.t1.out: error in call to strings.SliceRunes: non-concrete value _:
+ // ./in.cue:9:7
+ }
}
t2: (struct){
- x: (int){ 6 }
+ x: (_|_){
+ // [incomplete] issue3584.reduced.t2.x: error in call to math.Abs: non-concrete value _:
+ // ./in.cue:13:5
+ }
y: (int){ |(*(int){ 6 }, (int){ 5 }) }
}
}
-- out/eval --
(struct){
issue3584: (struct){
Expand Down
8 changes: 8 additions & 0 deletions internal/core/adt/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,14 @@ func (x *CallExpr) evaluate(c *OpContext, state combinedFlags) Value {
expr = c.evalState(a, state)
} else {
cond |= fieldSetKnown | allAncestorsProcessed | concreteKnown
// Be sure to process disjunctions at the very least when
// finalizing. Requiring disjunctions earlier may lead to too eager
// evaluation.
//
// TODO: Ideally we would always add this flag regardless of mode.
if runMode == finalize {
cond |= disjunctionTask
}
state = combineMode(cond, runMode).withVertexStatus(state.vertexStatus())
expr = c.value(a, state)
}
Expand Down

0 comments on commit 3ee8b07

Please sign in to comment.