internal/core/adt: pass and use OpContext to functions using Schema
Builtins that have a pkg.Schema argument evaluate this
argument as an expression, possibly unifying it with
something else. This may result in a cycle.
In order to detect the cycle, the cycle information
obtained from using the argument must passed to
further evaluation. We do this by making the Schema
method call CallContext.Expr, which, in turn, uses
EvaluatedKeepState to accumulate cycle information
in the OpContext.
The functions that are passed the OpContext then
need to use adt.Unify instead of Value.Unify to be able to
detect cycles.
NOTE: this strongly hints that we need to change the
public API to also be centered around an operation
context. This has come up in various situations already.
This change requires pkg/gen.go to also pass an
OpContext for the generated stubs. We take a somewhat
unusual approach here: rather than changing the functions
to take an OpContext, we instead call a non-exported
function with the OpContext added as the first argument
whenever an Exported function with a pkg.Schema
argument is found.
The reason for this is that we currently piggyback on
godoc to generate documentation for the builtins.
Adding the OpContext in this signature would be
confusing for the the user, as it should not be
populated in CUE.
Note some counter error were introduced
by the new tests.
The error messages have some additional or longer
paths as a result of this change, which is either a
benign change or desirable.
Fixes #3649
(fixes derivative issues, was already closed)
Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I4b5a31aeb5501ec03915d069f8b92f56311124dd
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1208702
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>