Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ _TESTS_TO_SKIP_PLANNER = [
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
# TODO: This is actually a user experience degradation.
# Not worth fixing until we see a concrete need.
"basic/functions/unbound_is_runtime_error",

# Skip until fixed.
"parse/receiver_function_names",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
Expand Down
38 changes: 26 additions & 12 deletions runtime/src/main/java/dev/cel/runtime/planner/ProgramPlanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package dev.cel.runtime.planner;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.auto.value.AutoValue;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -293,17 +295,24 @@ private PlannedInterpretable planCall(CelExpr expr, PlannerContext ctx) {
}

if (resolvedOverload == null) {
if (!lateBoundFunctionNames.contains(functionName)) {
boolean isLateBound = lateBoundFunctionNames.contains(functionName);
// For type-checked ASTs, functions that are not explicitly registered as late-bound
// must be resolved at plan time.
// For parsed-only ASTs or late-bound functions, defer overload resolution to runtime.
if (ctx.isChecked() && !isLateBound) {
CelReference reference = ctx.referenceMap().get(expr.id());
if (reference != null) {
if (reference != null && !reference.overloadIds().isEmpty()) {
throw new CelOverloadNotFoundException(functionName, reference.overloadIds());
} else {
throw new CelOverloadNotFoundException(functionName);
}
}

ImmutableList<String> overloadIds = ImmutableList.of();
if (resolvedFunction.overloadId().isPresent()) {
CelReference reference = ctx.referenceMap().get(expr.id());
if (reference != null && !reference.overloadIds().isEmpty()) {
overloadIds = reference.overloadIds();
} else if (resolvedFunction.overloadId().isPresent()) {
overloadIds = ImmutableList.of(resolvedFunction.overloadId().get());
}

Expand Down Expand Up @@ -628,16 +637,23 @@ private static Builder newBuilder() {
}

static final class PlannerContext {
private final ImmutableMap<Long, CelReference> referenceMap;
private final ImmutableMap<Long, CelType> typeMap;
private final CelAbstractSyntaxTree ast;
private final HashMap<String, Integer> localVars = new HashMap<>();

CelAbstractSyntaxTree ast() {
return ast;
}

ImmutableMap<Long, CelReference> referenceMap() {
return referenceMap;
return ast.getReferenceMap();
}

ImmutableMap<Long, CelType> typeMap() {
return typeMap;
return ast.getTypeMap();
}

boolean isChecked() {
return ast.isChecked();
}

private void pushLocalVars(String... names) {
Expand Down Expand Up @@ -670,14 +686,12 @@ private boolean isLocalVar(String name) {
return localVars.containsKey(name);
}

private PlannerContext(
ImmutableMap<Long, CelReference> referenceMap, ImmutableMap<Long, CelType> typeMap) {
this.referenceMap = referenceMap;
this.typeMap = typeMap;
private PlannerContext(CelAbstractSyntaxTree ast) {
this.ast = checkNotNull(ast);
}

static PlannerContext create(CelAbstractSyntaxTree ast) {
return new PlannerContext(ast.getReferenceMap(), ast.getTypeMap());
return new PlannerContext(ast);
}
}

Expand Down
Loading