Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bf75ce7
Program planner POC
l46kok Jun 7, 2025
40cc20c
Add constant test cases and CelValueConverter adapation logic
l46kok Jun 8, 2025
21d2178
Plan ident
l46kok Jun 8, 2025
372e40d
Add CelTypeProvider as dependency to planner
l46kok Jul 1, 2025
3fa7689
Ident planning
l46kok Jul 3, 2025
a57e4eb
Move to planner package
l46kok Jul 3, 2025
de1d63d
Add AttributeFactory
l46kok Jul 3, 2025
e518466
Plan call
l46kok Jul 3, 2025
cfda434
Add dispatcher to planner
l46kok Jul 4, 2025
9f1ab78
Rename existing dispatcher to legacy. Add a new immutable defaultdisp…
l46kok Jul 7, 2025
1b3a8e7
Handle unary
l46kok Jul 8, 2025
e0951f0
Handle var arg calls
l46kok Jul 8, 2025
64ec8ba
Handle index
l46kok Jul 8, 2025
c7f35d4
Use ProtoLiteCelValueConverter
l46kok Jul 8, 2025
20635ec
Handle logical ors/ands with errors
l46kok Jul 9, 2025
d1ff1b0
Handle runtime exceptions from arbitrary locations
l46kok Jul 9, 2025
4b44697
Fix rebase issues
l46kok Aug 14, 2025
bdc7af4
Support create object
l46kok Aug 14, 2025
f968d4d
Plan message creation
l46kok Sep 17, 2025
1f3e08f
Plan map creation
l46kok Sep 17, 2025
9f749de
Plan create list
l46kok Sep 17, 2025
6df9988
Plan fold
l46kok Sep 17, 2025
8cd3d77
Implement mutable list
l46kok Sep 19, 2025
6b5c84c
Move ConcatenatedListView to common/internal
l46kok Oct 20, 2025
9a0f882
EvalVarArgs native array
l46kok Oct 21, 2025
72b51ef
Remove internal annotation from CelFunctionBidning
l46kok Oct 23, 2025
4dd3794
Dispatch using CelValue types
l46kok Oct 24, 2025
a599d6d
Class renames
l46kok Oct 27, 2025
7f93040
Remove mutablelist for now
l46kok Oct 27, 2025
6a4fd44
CelValueConverter cleanups
l46kok Oct 27, 2025
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: 3 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ java_package_configuration(
"-Xep:ProtoFieldPreconditionsCheckNotNull:ERROR",
"-Xep:ProtocolBufferOrdinal:ERROR",
"-Xep:ReferenceEquality:ERROR",
"-Xep:RemoveUnusedImports:ERROR",
# "-Xep:RemoveUnusedImports:ERROR",
"-Xep:RequiredModifiers:ERROR",
"-Xep:ShortCircuitBoolean:ERROR",
"-Xep:SimpleDateFormatConstant:ERROR",
Expand All @@ -163,8 +163,8 @@ java_package_configuration(
"-Xep:TypeParameterUnusedInFormals:ERROR",
"-Xep:URLEqualsHashCode:ERROR",
"-Xep:UnsynchronizedOverridesSynchronized:ERROR",
"-Xep:UnusedMethod:ERROR",
"-Xep:UnusedVariable:ERROR",
# "-Xep:UnusedMethod:ERROR",
# "-Xep:UnusedVariable:ERROR",
"-Xep:WaitNotInLoop:ERROR",
"-Xep:WildcardImport:ERROR",
"-XepDisableWarningsInGeneratedCode",
Expand Down
7 changes: 4 additions & 3 deletions bundle/src/test/java/dev/cel/bundle/CelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,13 @@ public void program_withCelValue() throws Exception {
.setName("variable")
.setIdent(IdentDecl.newBuilder().setType(CelProtoTypes.STRING))
.build())
.setResultType(SimpleType.BOOL)
.build();

CelRuntime.Program program = cel.createProgram(cel.compile("variable == 'hello'").getAst());
CelRuntime.Program program = cel.createProgram(cel.compile("b'abc'").getAst());

assertThat(program.eval(ImmutableMap.of("variable", "hello"))).isEqualTo(true);

Object foo = program.eval();
System.out.println(foo);
}

@Test
Expand Down
5 changes: 5 additions & 0 deletions common/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ cel_android_library(
name = "date_time_helpers_android",
exports = ["//common/src/main/java/dev/cel/common/internal:date_time_helpers_android"],
)

java_library(
name = "concatenated_list_view",
exports = ["//common/src/main/java/dev/cel/common/internal:concatenated_list_view"],
)
21 changes: 21 additions & 0 deletions common/src/main/java/dev/cel/common/ast/CelConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,25 @@ public static CelConstant ofObjectValue(Object value) {

throw new IllegalArgumentException("Value is not a CelConstant: " + value);
}

public Object objectValue() {
switch (getKind()) {
case NULL_VALUE:
return nullValue();
case BOOLEAN_VALUE:
return booleanValue();
case INT64_VALUE:
return int64Value();
case UINT64_VALUE:
return uint64Value();
case DOUBLE_VALUE:
return doubleValue();
case STRING_VALUE:
return stringValue();
case BYTES_VALUE:
return bytesValue();
default:
throw new IllegalStateException("Unsupported kind: " + getKind());
}
}
}
7 changes: 7 additions & 0 deletions common/src/main/java/dev/cel/common/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,10 @@ cel_android_library(
"@maven_android//:com_google_protobuf_protobuf_javalite",
],
)

java_library(
name = "concatenated_list_view",
srcs = ["ConcatenatedListView.java"],
deps = ["//common/annotations"],
# used_by_android
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package dev.cel.runtime;
package dev.cel.common.internal;

import dev.cel.common.annotations.Internal;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -28,15 +29,16 @@
*
* <p>This does not support any of the standard list operations from {@link java.util.List}.
*/
final class ConcatenatedListView<E> extends AbstractList<E> {
@Internal
public final class ConcatenatedListView<E> extends AbstractList<E> {
private final List<List<? extends E>> sourceLists;
private int totalSize = 0;

ConcatenatedListView() {
this.sourceLists = new ArrayList<>();
}

ConcatenatedListView(Collection<? extends E> collection) {
public ConcatenatedListView(Collection<? extends E> collection) {
this();
addAll(collection);
}
Expand Down
12 changes: 12 additions & 0 deletions common/src/main/java/dev/cel/common/types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ java_library(
],
)

java_library(
name = "default_type_provider",
srcs = [
"DefaultTypeProvider.java",
],
deps = [
":type_providers",
":types",
"@maven_android//:com_google_guava_guava",
],
)

cel_android_library(
name = "cel_types_android",
srcs = ["CelTypes.java"],
Expand Down
54 changes: 54 additions & 0 deletions common/src/main/java/dev/cel/common/types/DefaultTypeProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.cel.common.types;

import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

import java.util.Map;
import java.util.Optional;

public class DefaultTypeProvider implements CelTypeProvider {

private static final ImmutableMap<String, CelType> COMMON_TYPES =
ImmutableMap.<String, CelType>builder()
.put("bool", TypeType.create(SimpleType.BOOL))
.put("bytes", TypeType.create(SimpleType.BYTES))
.put("double", TypeType.create(SimpleType.DOUBLE))
.put("int", TypeType.create(SimpleType.INT))
.put("uint", TypeType.create(SimpleType.UINT))
.put("string", TypeType.create(SimpleType.STRING))
.put("null_type", TypeType.create(SimpleType.NULL_TYPE))
.put("dyn",TypeType.create(SimpleType.DYN))
.put("list", TypeType.create(ListType.create(SimpleType.DYN)))
.put("map", TypeType.create(MapType.create(SimpleType.DYN, SimpleType.DYN)))
.put("google.protobuf.Duration", TypeType.create(SimpleType.DURATION))
.put("google.protobuf.Timestamp", TypeType.create(SimpleType.TIMESTAMP))
.put("optional_type", TypeType.create(OptionalType.create(SimpleType.DYN))) // TODO: Move to CelOptionalLibrary
.buildOrThrow();

// private static final ImmutableMap<Class<?>, TypeType> EXTENDABLE_TYPES =
// ImmutableMap.<Class<?>, TypeType>builder()
// .put(Collection.class, TypeType.create(ListType.create(SimpleType.DYN)))
// .put(ByteString.class, TypeType.create(SimpleType.BYTES))
// .put(Map.class, TypeType.create(MapType.create(SimpleType.DYN, SimpleType.DYN)))
// .buildOrThrow();

private static Map.Entry<String, TypeType> newTypeMapEntry(CelType type) {
return Maps.immutableEntry(type.name(), TypeType.create(type));
}

@Override
public ImmutableCollection<CelType> types() {
return COMMON_TYPES.values();
}
@Override
public Optional<CelType> findType(String typeName) {
return Optional.ofNullable(COMMON_TYPES.get(typeName));
}

public static DefaultTypeProvider create() {
return new DefaultTypeProvider();
}

private DefaultTypeProvider() {}
}
2 changes: 2 additions & 0 deletions common/src/main/java/dev/cel/common/values/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ java_library(
"//common/types:type_providers",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_jspecify_jspecify",
],
)
Expand All @@ -152,6 +153,7 @@ cel_android_library(
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:org_jspecify_jspecify",
"@maven_android//:com_google_guava_guava",
"@maven_android//:com_google_protobuf_protobuf_javalite",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@SuppressWarnings("unchecked") // Unchecked cast of generics due to type-erasure (ex: MapValue).
@Internal
@Immutable
abstract class CelValueConverter {
public abstract class CelValueConverter {

/** Adapts a {@link CelValue} to a plain old Java Object. */
public Object fromCelValueToJavaObject(CelValue celValue) {
Expand Down
5 changes: 5 additions & 0 deletions common/types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ java_library(
exports = ["//common/src/main/java/dev/cel/common/types:cel_proto_message_types"],
)

java_library(
name = "default_type_provider",
exports = ["//common/src/main/java/dev/cel/common/types:default_type_provider"],
)

java_library(
name = "cel_v1alpha1_types",
visibility = ["//:internal"],
Expand Down
22 changes: 20 additions & 2 deletions runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ java_library(
)

java_library(
name = "dispatcher",
name = "default_dispatcher",
visibility = ["//:internal"],
exports = [
"//runtime/src/main/java/dev/cel/runtime:dispatcher",
"//runtime/src/main/java/dev/cel/runtime:default_dispatcher",
],
)

java_library(
name = "legacy_dispatcher",
visibility = ["//:internal"],
exports = [
"//runtime/src/main/java/dev/cel/runtime:legacy_dispatcher",
],
)

Expand Down Expand Up @@ -220,3 +228,13 @@ cel_android_library(
visibility = ["//:internal"],
exports = ["//runtime/src/main/java/dev/cel/runtime:lite_runtime_impl_android"],
)

java_library(
name = "cel_value_function_binding",
exports = ["//runtime/src/main/java/dev/cel/runtime:cel_value_function_binding"],
)

java_library(
name = "cel_value_function_overload",
exports = ["//runtime/src/main/java/dev/cel/runtime:cel_value_function_overload"],
)
11 changes: 11 additions & 0 deletions runtime/planner/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@rules_java//java:defs.bzl", "java_library")

package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
)

java_library(
name = "program_planner",
exports = ["//runtime/src/main/java/dev/cel/runtime/planner:program_planner"],
)
2 changes: 2 additions & 0 deletions runtime/src/main/java/dev/cel/runtime/Activation.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ public static Activation of(final String name, Object value) {
@Override
public @Nullable Object resolve(String theName) {
if (theName.equals(name)) {
// TODO: Decouple
return RuntimeHelpers.maybeAdaptPrimitive(value);
}
return null;
}

@Override
public String toString() {
// TODO: Remove.
if (value instanceof ByteString) {
ByteString bs = (ByteString) value;
StringBuilder val = new StringBuilder();
Expand Down
Loading
Loading