Skip to content

Commit

Permalink
feat: give access to the program result type definition (vectordotdev…
Browse files Browse the repository at this point in the history
  • Loading branch information
fuchsnj authored and itkovian committed Jun 1, 2023
1 parent 190cdf0 commit eafb04c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Tom.Kaitchuck@gmail.com>
aho-corasick,https://github.com/BurntSushi/aho-corasick,Unlicense OR MIT,Andrew Gallant <jamslam@gmail.com>
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 <nical@fastmail.com>
ansi_term,https://github.com/ogham/rust-ansi-term,MIT,"ogham@bsago.me, Ryan Scheel (Havvy) <ryan.havvy@gmail.com>, Josh Triplett <josh@joshtriplett.org>"
anstream,https://github.com/rust-cli/anstyle,MIT OR Apache-2.0,The anstream Authors
Expand Down
4 changes: 2 additions & 2 deletions lib/fuzz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {:?}",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn resolve(
}
};

*state = program.final_type_state();
*state = program.final_type_info().state;
execute(runtime, &program, target, timezone, vrl_runtime)
}

Expand Down
16 changes: 12 additions & 4 deletions src/compiler/expression/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,8 @@ mod test {
assert_eq!(
result
.program
.final_type_state()
.final_type_info()
.state
.external
.target()
.type_def
Expand All @@ -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()
);
}
Expand All @@ -814,7 +820,8 @@ mod test {
assert_eq!(
result
.program
.final_type_state()
.final_type_info()
.state
.local
.variable(&"foo".to_string().into())
.unwrap()
Expand All @@ -840,7 +847,8 @@ mod test {
assert_eq!(
result
.program
.final_type_state()
.final_type_info()
.state
.local
.variable(&"foo".to_string().into())
.unwrap()
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/program.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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
Expand Down

0 comments on commit eafb04c

Please sign in to comment.