diff --git a/Cargo.lock b/Cargo.lock index b3e84895a34c8..1ed68b3193b65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8564,6 +8564,7 @@ dependencies = [ "serde_json", "thiserror", "tracing 0.1.30", + "value", "vector_common", "vrl-diagnostic", "vrl-parser", diff --git a/lib/enrichment/src/find_enrichment_table_records.rs b/lib/enrichment/src/find_enrichment_table_records.rs index c751d5350fba7..5208f5779c8c2 100644 --- a/lib/enrichment/src/find_enrichment_table_records.rs +++ b/lib/enrichment/src/find_enrichment_table_records.rs @@ -129,7 +129,7 @@ impl Expression for FindEnrichmentTableRecordsFn { .collect::, _>>(), value => Err(value::Error::Expected { got: value.kind(), - expected: Kind::Array, + expected: Kind::array(Collection::any()), }), }) .transpose()?; @@ -164,9 +164,7 @@ impl Expression for FindEnrichmentTableRecordsFn { } fn type_def(&self, _: &state::Compiler) -> TypeDef { - TypeDef::new() - .fallible() - .array_mapped::<(), Kind>(map! { (): Kind::Object }) + TypeDef::array(Collection::from_unknown(Kind::object(Collection::any()))).fallible() } } diff --git a/lib/enrichment/src/get_enrichment_table_record.rs b/lib/enrichment/src/get_enrichment_table_record.rs index 97f459796efd7..cf1dab6da7ffb 100644 --- a/lib/enrichment/src/get_enrichment_table_record.rs +++ b/lib/enrichment/src/get_enrichment_table_record.rs @@ -125,7 +125,7 @@ impl Expression for GetEnrichmentTableRecordFn { .collect::, _>>(), value => Err(value::Error::Expected { got: value.kind(), - expected: Kind::Array, + expected: Kind::array(Collection::any()), }), }) .transpose()?; @@ -156,9 +156,7 @@ impl Expression for GetEnrichmentTableRecordFn { } fn type_def(&self, _: &state::Compiler) -> TypeDef { - TypeDef::new() - .fallible() - .add_object::<(), Kind>(map! { (): Kind::all() }) + TypeDef::object(Collection::any()).fallible() } } diff --git a/lib/lookup/Cargo.toml b/lib/lookup/Cargo.toml index d528458322dcb..5ba4ff8ab43b8 100644 --- a/lib/lookup/Cargo.toml +++ b/lib/lookup/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" publish = false [dependencies] -serde = { version = "1.0.136", default-features = false, features = ["derive"] } +serde = { version = "1.0.136", default-features = false, features = ["derive", "alloc"] } tracing = { version = "0.1", default-features = false, features = ["attributes"] } snafu = { version = "0.7", default-features = false } regex = { version = "1.5.4", default-features = false, features = ["std", "perf"] } diff --git a/lib/value/src/kind/collection.rs b/lib/value/src/kind/collection.rs index 3ee6f7ec96c19..04607a0884bd9 100644 --- a/lib/value/src/kind/collection.rs +++ b/lib/value/src/kind/collection.rs @@ -50,6 +50,15 @@ impl Collection { } } + /// Create a collection kind of which there are no known and no unknown kinds. + #[must_use] + pub fn empty() -> Self { + Self { + known: BTreeMap::default(), + unknown: None, + } + } + /// Create a collection kind of which the encapsulated values can be any kind. #[must_use] pub fn any() -> Self { diff --git a/lib/vector-vrl-functions/src/get_metadata_field.rs b/lib/vector-vrl-functions/src/get_metadata_field.rs index dbf7ecf8136f2..8ef2f56297402 100644 --- a/lib/vector-vrl-functions/src/get_metadata_field.rs +++ b/lib/vector-vrl-functions/src/get_metadata_field.rs @@ -55,6 +55,6 @@ impl Expression for GetMetadataFieldFn { } fn type_def(&self, _: &state::Compiler) -> TypeDef { - TypeDef::new().infallible().bytes().add_null() + TypeDef::bytes().add_null().infallible() } } diff --git a/lib/vector-vrl-functions/src/remove_metadata_field.rs b/lib/vector-vrl-functions/src/remove_metadata_field.rs index 9e5f9bd8f601f..4cc7ffc0bb19b 100644 --- a/lib/vector-vrl-functions/src/remove_metadata_field.rs +++ b/lib/vector-vrl-functions/src/remove_metadata_field.rs @@ -53,6 +53,6 @@ impl Expression for RemoveMetadataFieldFn { } fn type_def(&self, _: &state::Compiler) -> TypeDef { - TypeDef::new().infallible().null() + TypeDef::null().infallible() } } diff --git a/lib/vector-vrl-functions/src/set_metadata_field.rs b/lib/vector-vrl-functions/src/set_metadata_field.rs index bd1eebef4a676..4bcb45cd5539b 100644 --- a/lib/vector-vrl-functions/src/set_metadata_field.rs +++ b/lib/vector-vrl-functions/src/set_metadata_field.rs @@ -63,6 +63,6 @@ impl Expression for SetMetadataFieldFn { } fn type_def(&self, _: &state::Compiler) -> TypeDef { - TypeDef::new().infallible().null() + TypeDef::null().infallible() } } diff --git a/lib/vrl/compiler/Cargo.toml b/lib/vrl/compiler/Cargo.toml index 7c00919a59cf3..ab3957cbd9c90 100644 --- a/lib/vrl/compiler/Cargo.toml +++ b/lib/vrl/compiler/Cargo.toml @@ -10,6 +10,7 @@ diagnostic = { package = "vrl-diagnostic", path = "../diagnostic" } parser = { package = "vrl-parser", path = "../parser" } lookup = { path = "../../lookup" } vector_common = { path = "../../vector-common", default-features = false, features = ["conversion"] } +value = { path = "../../value" } bitflags = "1" bytes = "1.1.0" diff --git a/lib/vrl/compiler/benches/kind.rs b/lib/vrl/compiler/benches/kind.rs index a31d2d183faac..639b79b119dd9 100644 --- a/lib/vrl/compiler/benches/kind.rs +++ b/lib/vrl/compiler/benches/kind.rs @@ -1,17 +1,17 @@ use std::fmt; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use vrl_compiler::value::Kind; +use vrl_compiler::value::kind; struct Parameters { - basis: Kind, + basis: u16, } static PARAMETERS: [Parameters; 4] = [ - Parameters { basis: Kind::Bytes }, - Parameters { basis: Kind::Array }, - Parameters { basis: Kind::Regex }, - Parameters { basis: Kind::Null }, + Parameters { basis: kind::BYTES }, + Parameters { basis: kind::ARRAY }, + Parameters { basis: kind::REGEX }, + Parameters { basis: kind::NULL }, ]; impl fmt::Display for Parameters { @@ -23,8 +23,16 @@ impl fmt::Display for Parameters { fn benchmark_kind_display(c: &mut Criterion) { let mut group = c.benchmark_group("vrl_compiler/value::kind::display"); for param in &PARAMETERS { - group.bench_with_input(BenchmarkId::from_parameter(param), ¶m, |b, ¶m| { - b.iter(|| format!("{}", param.basis)) + let parameter = vrl_compiler::Parameter { + keyword: "", + kind: param.basis, + required: false, + }; + + let kind = parameter.kind(); + + group.bench_with_input(BenchmarkId::from_parameter(param), &kind, |b, kind| { + b.iter(|| format!("{}", kind)) }); } } diff --git a/lib/vrl/compiler/src/expression/abort.rs b/lib/vrl/compiler/src/expression/abort.rs index 5bd1267358196..440e28f6a257a 100644 --- a/lib/vrl/compiler/src/expression/abort.rs +++ b/lib/vrl/compiler/src/expression/abort.rs @@ -32,7 +32,7 @@ impl Abort { }) } else if !type_def.is_bytes() { Err(Error { - variant: ErrorVariant::NonString(type_def.kind()), + variant: ErrorVariant::NonString(type_def.into()), expr_span, }) } else { @@ -69,7 +69,7 @@ impl Expression for Abort { } fn type_def(&self, _: &State) -> TypeDef { - TypeDef::new().infallible().null() + TypeDef::null().infallible() } fn compile_to_vm(&self, vm: &mut crate::vm::Vm) -> Result<(), String> { @@ -138,7 +138,7 @@ impl DiagnosticError for Error { } fn labels(&self) -> Vec