feat(compiler): enforce array element-kind constraints at compile time#1861
Draft
pront wants to merge 10 commits into
Draft
feat(compiler): enforce array element-kind constraints at compile time#1861pront wants to merge 10 commits into
pront wants to merge 10 commits into
Conversation
Adds `Parameter::element_kind: u16` (with `with_element_kind` builder) so stdlib functions can declare what element type their array parameters expect. The compiler's existing arg-binder automatically uses this to mark calls fallible (unknown/mixed element types) or reject them as hard compile errors (provably disjoint element types). Separately, `Kind::intersects` and the new `Collection::intersects` now check element kinds when comparing array types, so a literal like `[1, 2]` passed to a `array<bytes>` parameter is a compile error even with `!` or `??` — it can never succeed. Updated functions: contains_all, tally, join, encode_key_value. Each loses its hand-rolled `type_def` element-kind check; the compiler enforces the constraint uniformly.
…ction::intersects
pront
force-pushed
the
pront/parameter-element-kind
branch
from
July 16, 2026 16:17
fe957e1 to
c66ae4f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #483.
VRL functions that take array arguments often require all elements to be a specific type (e.g.
joinrequiresarray<bytes>). Previously, each function had to hand-roll an element-kind check insidetype_def(), mixing return-type description with argument validation. Functions that forgot this check silently accepted wrong-typed arrays and produced runtime errors.This PR introduces two improvements:
1.
Parameter::with_element_kind(u16)— declarative element-type constraintsA new opt-in field on
Parameterlets stdlib functions declare what element kind their array parameter expects:The compiler's existing arg-binder already does superset/intersect/fallibility inference — it just needed element-type info to work with. Now:
!or??)Functions updated:
contains_all,tally,join,encode_key_value,ip_cidr_contains,parse_groks. Each loses its hand-rolledtype_defelement check; the compiler enforces it uniformly.2. Element-aware
Kind::intersectsfor arraysPreviously
intersectsfor two array types returnedtrueas long as both were arrays, ignoring element types. Now it delegates toCollection::intersects, which checks whether any known element on either side is provably disjoint from the other side's element kind.Effect: passing a literal like
[1, 2]to a function expectingarray<bytes>is now a hard compile error — not just fallible, but rejected outright, even with!or??.Test plan
cargo test -p vrl --lib— 1854 tests passcontains_all::compiler_flags_non_bytes_element_as_fallible— end-to-end test verifying string literals compile infallible, integer literals are hard compile errors even with??Kind::test_intersects_arrays— unit tests for all array intersection cases including empty arrays, disjoint known elements, mixed known elementsCollection::test_collection_intersects— unit tests for collection-level intersection logicjoin([1,2,3]),join!([1,2,3]),join([1,2,3]) ?? ""all produce compile errors;join(["a","b"])is infallible