Repository navigation
fix: resolve container-qualified bindings for unchecked parsed eval - #196
detail-app[bot] wants to merge 6 commits into
Conversation
| import org.junit.Test; | ||
|
|
||
| /** Runtime container-qualified binding resolution for unchecked/parsed evaluation. */ | ||
| public final class ContainerResolutionTest { |
There was a problem hiding this comment.
Addressed in edc1165: dropped the added @TruffleBoundary from rootBinding so the compiled root-resolution fast path matches the pre-PR allocation profile (restores the benchmarks:compiled budget); the new container-walk helpers stay @TruffleBoundary. Also added NullMarked to ContainerResolutionTest (+ @maven//:org_jspecify_jspecify dep) to satisfy RequireExplicitNullMarking.
There was a problem hiding this comment.
Follow-up in 0a257a0: reverted the NullMarked addition. It can't land cleanly here — strict deps requires a direct @maven//:org_jspecify_jspecify dep, but Gazelle auto-removes that dep as transitively-satisfied, so the two checks conflict. The RequireExplicitNullMarking finding is WARN-level (code-scanning), not a CI failure (trufflecheck passed without the annotation), so a human can decide later whether to adopt NullMarked package-wide.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Drop @TruffleBoundary from rootBinding so the compiled fast path for container-less root resolution matches the pre-PR allocation profile (benchmarks:compiled budget). The new container-walk helpers stay behind @TruffleBoundary. Add @NullMarked to ContainerResolutionTest to satisfy RequireExplicitNullMarking.
Gazelle resolves org.jspecify.annotations transitively via //:trufflecel (-> truffledata-core -> jspecify), so the explicit @maven dep on containerResolution is unused and fails the gazelle check. @NullMarked remains on the test class to satisfy RequireExplicitNullMarking.
The @NullMarked annotation conflicts with the repo's Gazelle config (strict deps require a direct @maven//:org_jspecify_jspecify dep, but Gazelle auto-removes it as redundant). The RequireExplicitNullMarking finding is WARN-level code-scanning, not a CI failure, and trufflecheck passed without it.
The boundary-annotated container walk in rootBinding was invoked on every root resolution, including programs with the default empty container. That added per-evaluation allocation and pushed the compiled benchmark x * 2 + 1 > 100 from 64 to 80 bytes/evaluation, exceeding its budget. Gate the walk behind environment.container.isEmpty() so compiled code takes the original inline single.equals / lookup fast path when no container prefixes exist. The boundary helpers run only when a container is actually present, preserving the container-qualified resolution semantics for unchecked parsed eval.
The container-qualified root-resolution fast paths added to EvalContext.rootBinding (String-single Object[] path and Scoped single-name path) only exercised the matching case in singleEntryActivationResolvesContainerQualifiedKey. The no-match branch (matchesRoot returns false -> null -> UNDECLARED) was uncovered, which dropped production branch coverage to 99.78%, under the 99.8% gate. Add singleEntryActivationMissingIdentifierErrorsAfterContainerWalk which evaluates a parsed 'y' with container 'x' against a single Activation.snapshot binding 'z' that matches neither 'x.y' nor 'y', exercising both the Object[] fast path (no-options evaluate) and the Scoped single-name path (options-driven evaluate), each expected to raise UNDECLARED after walking the container.
Detail bug report: View on Detail
Change
Closes #173
For parsed (unchecked)
EvalRequests — which carry notype_env, so free identifiers are not pre-resolved at plan time —EvalContext.rootBindingresolved root identifiers by a single exact-key lookup against the activation and ignoredEvalRequest.container. As a result:Parse "y"thenEval(parsed_expr, container="x", bindings={"x.y": bool true, "y": string "false"}), the server returnedstring "false"(bareyshadowedx.y); the cel-spec corpus casesself_eval_container_lookup/self_eval_container_lookup_uncheckedrequirebool true.{"x.y": true}bound, evaluation errored withno value for variable: ybecause the container-qualified key was never tried.The container-prefix walk existed only at plan time in
Environment.resolve, and only over declared names — but a parsedEvalRequesthas no declarations, so the walk never ran. This silenced the intent ofEvalRequest.containerand affected any dynamic caller that imports a canonicalParsedExprAST (introduced in the genesis commit9af3c5c). Per the CEL spec, the container scopes must be tried, innermost first, before the bare name.Fix
In
EvalContext, runtime root-identifier resolution now walksenvironment.containerprefixes innermost-first (e.g.x.y, thenyfor containerx) against the activation before falling back to the bare name, mirroring the existing plan-timeEnvironment.resolvesemantics:getRoot/rootBinding(String, boolean)carry anabsoluteflag so absolute references (.y) skip the walk.@TruffleBoundary-annotated helpersresolveRoot(map-backed activation path) andmatchesRoot(single-bindingScoped/Object[]fast paths) perform the walk.@TruffleBoundaryannotation matches the existing slow-path idiom (absoluteName,getLocal,undeclared,lookupare already boundary-annotated) and keeps the walk's string concatenation out of JIT-compiled ASTs. Without it, Graal inlined the walk into the compiledMatchesNodeand bailed out withPermanentBailoutException: Too deep inlining, regressing:noRe2jConsumer.The checked-expr path is unchanged: the checker still rewrites identifiers to qualified names at plan time, and the runtime walk does not alter already-resolved names.
Validation
New regression tests (committed):
src/test/java/dev/trufflecel/ContainerResolutionTest.java(engine-level): container-qualified wins over bare; qualified-only resolves; bare-only still resolves; genuinely missing identifier still throwsUNDECLARED(after walking the container); nested containera.bwalks innermost-first; multiple roots each resolve through the container; absolute.yskips the walk; checked path unchanged; empty container falls back to the bare name;Activation.snapshotsingle-entry fast path resolves qualified keys.tools/conformance/ConformanceServerTest.evalParsedExprResolvesContainerQualifiedBindings(gRPC end-to-end, in-process server): both-present, qualified-only, and bare-only cases againstConformanceServer.evalwith aparsed_exprwire form andcontainer="x".Both new tests fail on the unpatched tree (bare
"false"wins / spuriousundeclared) and pass with the fix.Routine checks:
bazel build --config=local //:trufflecel //:trufflecel-protobuf //:trufflecel-json //:trufflecel-processor,bazel run --config=local //tools:format -- --check, andbazel run --config=local //bazel/gazelle:checkall pass.Suite verification: the full 2,771-case cel-spec conformance corpus (including the exact
namespace/self_eval_container_lookup/_uncheckedcases), the negative matrix, runtime, checker, canonical-ast, borrowed-bindings, partial-evaluation, policy (compiler + conformance), extensions, function-overload, lazy-binding, validation, CSE, ast-interchange, activation, environment-controls, pojo, pojo-processor, protobuf-integration, prepared-field, data-integration, interop, library-policy, late-function, map-snapshot, optional-value, nullable-typing, diagnostics, cost-estimator, custom-validator, boundary, foreign-ordinal-bug, polyglot-error-type-repro, ast-location, ast-macro, ast-validation, error-location, evaluation-controls, environment-yaml, parser-recovery, parser, encoder, re2-nested-pattern-repro, regex-acceleration, truffle-regex-only, andtools/fuzz:regression/evaluation_regression/smokeall pass.JIT gate:
:noRe2jConsumer(forcesengine.CompilationFailureAction=Throw+compiler.TreatPerformanceWarningsAsErrors=alland hot-loops a regex match) initially regressed with the naive fix — Graal bailed outToo deep inliningon the inlined container walk. Adding@TruffleBoundaryto the new helpers restored it; confirmed passing 3× with--runs_per_test=3 --flaky_test_attempts=3, and the baseline also passes identically.:traceAsyncand:instrumentationpass as well.Limitations / env notes:
:traceAsync,:instrumentation,:noRe2jConsumer) require a writable polyglot cache inside the Bazel sandbox; locally they need--test_env=POLYGLOT_USER_CACHE=<dir> --sandbox_writable_path=<dir>with the directory pre-created andchmod 777. Without it they fail withthe resource cache folder /root/.cache/org.graalvm.polyglot is not a readable and writable directory. This is an environment requirement, not affected by the change.bazel test //benchmarks:jit_smoke) were not exercised in this sandbox; per CONTRIBUTING.md the JVM pass alone does not establish Native Image compatibility.Automatic Fixes PRs can be configured here.