From 2bbe6728fc0a9d0c20b6ee8634346bdbf28f78d8 Mon Sep 17 00:00:00 2001 From: Nathan Fox Date: Wed, 31 May 2023 14:26:41 -0400 Subject: [PATCH] feat: give access to the program result type definition (#262) --- CHANGELOG.md | 1 + LICENSE-3rdparty.csv | 1 + lib/fuzz/src/main.rs | 4 ++-- src/cli/repl.rs | 2 +- src/compiler/expression/assignment.rs | 16 ++++++++++++---- src/compiler/program.rs | 6 +++--- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca4cafbf23..f3ae098d5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - fixed a panic when arithmetic overflows. It now always wraps (only in debug builds). (https://github.com/vectordotdev/vrl/pull/252) - `ingress_upstreaminfo` log format has been added to `parse_nginx_log` function (https://github.com/vectordotdev/vrl/pull/193) - fixed type definitions for side-effects inside of queries (https://github.com/vectordotdev/vrl/pull/258) +- replaced `Program::final_type_state` with `Program::final_type_info` to give access to the type definitions of both the target and program result (https://github.com/vectordotdev/vrl/pull/262) ## `0.4.0` (2023-05-11) - consolidated all crates into the root `vrl` crate. The external API stayed the same, with the exception of macros, which are now all exported at the root of the `vrl` crate. diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 24e7ae6a01..35f6be2ac4 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -3,6 +3,7 @@ adler,https://github.com/jonas-schievink/adler,0BSD OR MIT OR Apache-2.0,Jonas S aes,https://github.com/RustCrypto/block-ciphers,MIT OR Apache-2.0,RustCrypto Developers ahash,https://github.com/tkaitchuck/ahash,MIT OR Apache-2.0,Tom Kaitchuck aho-corasick,https://github.com/BurntSushi/aho-corasick,Unlicense OR MIT,Andrew Gallant +android-tzdata,https://github.com/RumovZ/android-tzdata,MIT OR Apache-2.0,RumovZ android_system_properties,https://github.com/nical/android_system_properties,MIT OR Apache-2.0,Nicolas Silva ansi_term,https://github.com/ogham/rust-ansi-term,MIT,"ogham@bsago.me, Ryan Scheel (Havvy) , Josh Triplett " anstream,https://github.com/rust-cli/anstyle,MIT OR Apache-2.0,The anstream Authors diff --git a/lib/fuzz/src/main.rs b/lib/fuzz/src/main.rs index 8736f23733..7413a96b3b 100644 --- a/lib/fuzz/src/main.rs +++ b/lib/fuzz/src/main.rs @@ -44,8 +44,8 @@ fn fuzz(src: &str) { let timezone = TimeZone::default(); let mut ctx = Context::new(&mut target, &mut state, &timezone); if let Ok(_value) = result.program.resolve(&mut ctx) { - let type_state = result.program.final_type_state(); - let expected_kind = type_state.external.target_kind(); + let type_info = result.program.final_type_info(); + let expected_kind = type_info.state.external.target_kind(); let actual_kind = Kind::from(target.value); if let Err(path) = expected_kind.is_superset(&actual_kind) { panic!("Value doesn't match at path: '{}'\n\nType at path = {:?}\n\nDefinition at path = {:?}", diff --git a/src/cli/repl.rs b/src/cli/repl.rs index 68b97e8453..920b275b01 100644 --- a/src/cli/repl.rs +++ b/src/cli/repl.rs @@ -177,7 +177,7 @@ fn resolve( } }; - *state = program.final_type_state(); + *state = program.final_type_info().state; execute(runtime, &program, target, timezone, vrl_runtime) } diff --git a/src/compiler/expression/assignment.rs b/src/compiler/expression/assignment.rs index f40a52343a..9bf9a3e5e4 100644 --- a/src/compiler/expression/assignment.rs +++ b/src/compiler/expression/assignment.rs @@ -770,7 +770,8 @@ mod test { assert_eq!( result .program - .final_type_state() + .final_type_info() + .state .external .target() .type_def @@ -793,7 +794,12 @@ mod test { ) .unwrap(); assert_eq!( - result.program.final_type_state().external.metadata_kind(), + result + .program + .final_type_info() + .state + .external + .metadata_kind(), &Kind::integer() ); } @@ -814,7 +820,8 @@ mod test { assert_eq!( result .program - .final_type_state() + .final_type_info() + .state .local .variable(&"foo".to_string().into()) .unwrap() @@ -840,7 +847,8 @@ mod test { assert_eq!( result .program - .final_type_state() + .final_type_info() + .state .local .variable(&"foo".to_string().into()) .unwrap() diff --git a/src/compiler/program.rs b/src/compiler/program.rs index 4164587699..e101e53905 100644 --- a/src/compiler/program.rs +++ b/src/compiler/program.rs @@ -1,6 +1,6 @@ use crate::path::OwnedTargetPath; -use super::state::TypeState; +use super::state::{TypeInfo, TypeState}; use super::{expression::Block, Context, Expression, Resolved}; #[derive(Debug, Clone)] @@ -20,8 +20,8 @@ impl Program { /// Retrieves the state of the type system after the program runs. #[must_use] - pub fn final_type_state(&self) -> TypeState { - self.expressions.type_info(&self.initial_state).state + pub fn final_type_info(&self) -> TypeInfo { + self.expressions.type_info(&self.initial_state) } /// Get detailed information about the program, as collected by the VRL