Skip to content

Commit 1711a8b

Browse files
authored
chore(vrl): use new value crate for type checking in VRL (#11222)
1 parent 468d525 commit 1711a8b

File tree

167 files changed

+2518
-3836
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+2518
-3836
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/enrichment/src/find_enrichment_table_records.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl Expression for FindEnrichmentTableRecordsFn {
129129
.collect::<std::result::Result<Vec<_>, _>>(),
130130
value => Err(value::Error::Expected {
131131
got: value.kind(),
132-
expected: Kind::Array,
132+
expected: Kind::array(Collection::any()),
133133
}),
134134
})
135135
.transpose()?;
@@ -164,9 +164,7 @@ impl Expression for FindEnrichmentTableRecordsFn {
164164
}
165165

166166
fn type_def(&self, _: &state::Compiler) -> TypeDef {
167-
TypeDef::new()
168-
.fallible()
169-
.array_mapped::<(), Kind>(map! { (): Kind::Object })
167+
TypeDef::array(Collection::from_unknown(Kind::object(Collection::any()))).fallible()
170168
}
171169
}
172170

lib/enrichment/src/get_enrichment_table_record.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Expression for GetEnrichmentTableRecordFn {
125125
.collect::<std::result::Result<Vec<_>, _>>(),
126126
value => Err(value::Error::Expected {
127127
got: value.kind(),
128-
expected: Kind::Array,
128+
expected: Kind::array(Collection::any()),
129129
}),
130130
})
131131
.transpose()?;
@@ -156,9 +156,7 @@ impl Expression for GetEnrichmentTableRecordFn {
156156
}
157157

158158
fn type_def(&self, _: &state::Compiler) -> TypeDef {
159-
TypeDef::new()
160-
.fallible()
161-
.add_object::<(), Kind>(map! { (): Kind::all() })
159+
TypeDef::object(Collection::any()).fallible()
162160
}
163161
}
164162

lib/lookup/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
publish = false
77

88
[dependencies]
9-
serde = { version = "1.0.136", default-features = false, features = ["derive"] }
9+
serde = { version = "1.0.136", default-features = false, features = ["derive", "alloc"] }
1010
tracing = { version = "0.1", default-features = false, features = ["attributes"] }
1111
snafu = { version = "0.7", default-features = false }
1212
regex = { version = "1.5.4", default-features = false, features = ["std", "perf"] }

lib/value/src/kind/collection.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ impl<T: Ord> Collection<T> {
5050
}
5151
}
5252

53+
/// Create a collection kind of which there are no known and no unknown kinds.
54+
#[must_use]
55+
pub fn empty() -> Self {
56+
Self {
57+
known: BTreeMap::default(),
58+
unknown: None,
59+
}
60+
}
61+
5362
/// Create a collection kind of which the encapsulated values can be any kind.
5463
#[must_use]
5564
pub fn any() -> Self {

lib/vector-vrl-functions/src/get_metadata_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ impl Expression for GetMetadataFieldFn {
5555
}
5656

5757
fn type_def(&self, _: &state::Compiler) -> TypeDef {
58-
TypeDef::new().infallible().bytes().add_null()
58+
TypeDef::bytes().add_null().infallible()
5959
}
6060
}

lib/vector-vrl-functions/src/remove_metadata_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ impl Expression for RemoveMetadataFieldFn {
5353
}
5454

5555
fn type_def(&self, _: &state::Compiler) -> TypeDef {
56-
TypeDef::new().infallible().null()
56+
TypeDef::null().infallible()
5757
}
5858
}

lib/vector-vrl-functions/src/set_metadata_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ impl Expression for SetMetadataFieldFn {
6363
}
6464

6565
fn type_def(&self, _: &state::Compiler) -> TypeDef {
66-
TypeDef::new().infallible().null()
66+
TypeDef::null().infallible()
6767
}
6868
}

lib/vrl/compiler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ diagnostic = { package = "vrl-diagnostic", path = "../diagnostic" }
1010
parser = { package = "vrl-parser", path = "../parser" }
1111
lookup = { path = "../../lookup" }
1212
vector_common = { path = "../../vector-common", default-features = false, features = ["conversion"] }
13+
value = { path = "../../value" }
1314

1415
bitflags = "1"
1516
bytes = "1.1.0"

lib/vrl/compiler/benches/kind.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use std::fmt;
22

33
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
4-
use vrl_compiler::value::Kind;
4+
use vrl_compiler::value::kind;
55

66
struct Parameters {
7-
basis: Kind,
7+
basis: u16,
88
}
99

1010
static PARAMETERS: [Parameters; 4] = [
11-
Parameters { basis: Kind::Bytes },
12-
Parameters { basis: Kind::Array },
13-
Parameters { basis: Kind::Regex },
14-
Parameters { basis: Kind::Null },
11+
Parameters { basis: kind::BYTES },
12+
Parameters { basis: kind::ARRAY },
13+
Parameters { basis: kind::REGEX },
14+
Parameters { basis: kind::NULL },
1515
];
1616

1717
impl fmt::Display for Parameters {
@@ -23,8 +23,16 @@ impl fmt::Display for Parameters {
2323
fn benchmark_kind_display(c: &mut Criterion) {
2424
let mut group = c.benchmark_group("vrl_compiler/value::kind::display");
2525
for param in &PARAMETERS {
26-
group.bench_with_input(BenchmarkId::from_parameter(param), &param, |b, &param| {
27-
b.iter(|| format!("{}", param.basis))
26+
let parameter = vrl_compiler::Parameter {
27+
keyword: "",
28+
kind: param.basis,
29+
required: false,
30+
};
31+
32+
let kind = parameter.kind();
33+
34+
group.bench_with_input(BenchmarkId::from_parameter(param), &kind, |b, kind| {
35+
b.iter(|| format!("{}", kind))
2836
});
2937
}
3038
}

0 commit comments

Comments
 (0)