Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: give access to the program result type definition #262

Merged
merged 5 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
- changed the return type of `Program::final_type_state` 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
2 changes: 1 addition & 1 deletion lib/fuzz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn fuzz(src: &str) {
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 expected_kind = type_state.state.external.target_kind();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking nit: another ...state.state call here that looks awkward.

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_state().state;
execute(runtime, &program, target, timezone, vrl_runtime)
}

Expand Down
10 changes: 9 additions & 1 deletion src/compiler/expression/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ mod test {
result
.program
.final_type_state()
.state
fuchsnj marked this conversation as resolved.
Show resolved Hide resolved
.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_state()
.state
.external
.metadata_kind(),
&Kind::integer()
);
}
Expand All @@ -815,6 +821,7 @@ mod test {
result
.program
.final_type_state()
.state
.local
.variable(&"foo".to_string().into())
.unwrap()
Expand All @@ -841,6 +848,7 @@ mod test {
result
.program
.final_type_state()
.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_state(&self) -> TypeInfo {
self.expressions.type_info(&self.initial_state)
}

/// Get detailed information about the program, as collected by the VRL
Expand Down