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

Adds support for Ion 1.1 to inspect #139

Merged
merged 7 commits into from
Aug 24, 2024
Merged

Adds support for Ion 1.1 to inspect #139

merged 7 commits into from
Aug 24, 2024

Conversation

zslayton
Copy link
Contributor

  • Upgrades the ion-cli's dependency on ion-rs to v1.0.0-rc.7.
  • Ion 1.1 value literals are recognized and their encodings displayed in the expected fashion.
  • Ion 1.1 macro invocations (e-expressions) at the top level have their encodings displayed; the ephemeral values they produce follow them in a dimmed font.
  • E-expression arguments have comments showing which macro parameter they correspond to
  • Ephemeral values use the binary encoding column to indicate which parameter variable was backing the corresponding application value.
  • This implementation does not yet support displaying e-expressions nested inside containers.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

* Ion 1.1 value literals are recognized and their encodings
  displayed in the expected fashion.
* Ion 1.1 macro invocations (e-expressions) at the top level
  have their encodings displayed; the ephemeral values
  they produce follow them in a dimmed font.
* This implementation does not yet support displaying e-expressions
  nested inside containers.
Copy link
Contributor Author

@zslayton zslayton left a comment

Choose a reason for hiding this comment

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

🗺️ PR Tour 🧭

@@ -157,11 +157,6 @@ impl WithIonCliArgument for ClapCommand {
)
}

/// All commands automatically have the "unstable" opt-in flag. This makes it visible.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ This impl was moved so the method order would align with the trait's method order.

@@ -18,6 +18,14 @@ use crate::output::CommandOutput;
pub struct InspectCommand;

impl IonCliCommand for InspectCommand {
fn is_stable(&self) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ These methods were moved to align their order with that of the trait.

Comment on lines -221 to -226
let item = reader.next_item()?;
let is_last_item = matches!(item, SystemStreamItem::EndOfStream(_));
item.raw_stream_item()
.map(|i| self.confirm_encoding_is_supported(i.encoding()))
.unwrap_or(Ok(()))?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Prior to version rc.7, ion-rust didn't have a way to get the next encoded item in the stream AND the values to which it expanded. You could only get one or the other. This meant that you couldn't display the encoding of an e-expression because the reader would only surface its expanded values. The code snippet that follows uses reader.next_expanded_item(), which returns an enum of either values (literal or ephemeral) or e-expressions.

match self.select_action(
TOP_LEVEL_DEPTH,
&mut has_printed_skip_message,
&item.raw_stream_item(),
&maybe_raw_item,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ If this stream item isn't ephemeral, see if it's in the requested range of bytes to inspect.

SystemStreamItem::SymbolTable(lazy_struct) => {
match expr {
EExp(eexp) => {
self.inspect_eexp(0, eexp)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ We now display e-expressions found at the top level. Some more work is needed in ion-rust to make it possible to get an 'expanded' view of lists and structs, allowing us to inspect both the encoded expressions and the values/fields they produce.

self.confirm_encoding_is_supported(marker.encoding())?;
self.inspect_ivm(marker)?;
}
SystemStreamItem::EndOfStream(_) => {
EndOfStream(end) => {
self.inspect_end_of_stream(end.range().start)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ The end of the stream now gets a row with an // End of stream comment and (more importantly) the offset where the end occurs.

Comment on lines +415 to +419
vec![
// TODO: Add methods to EExpression that allow nuanced access to its encoded spans
// TODO: Length-prefixed and multibyte e-expression addresses
IonBytes::new(BytesKind::MacroId, &eexp.span().bytes()[0..1]),
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ For now we assume that the e-expression's ID is just the first byte of the encoding. We need to add a method here to get the correct byte slice more reliably.

Comment on lines +508 to +512
Binary_1_0(bin_val) => {
self.inspect_literal_scalar(depth, delimiter, value, bin_val, comment_fn)
}
Binary_1_1(bin_val) => {
self.inspect_literal_scalar(depth, delimiter, value, bin_val, comment_fn)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ The inspect_literal_scalar method is generic over the encoding of the binary value, so these two method calls look identical but they're different.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that worth a code comment, or is it obvious at a glance to people more experienced with Rust and/or this code base than me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's more obvious in an IDE, but I though it might raise an eyebrow in the context of the diff.

@zslayton zslayton marked this pull request as ready for review August 23, 2024 19:48
@zslayton zslayton requested review from jobarr-amzn and tgregg August 23, 2024 19:48
@zslayton zslayton changed the title Adds support for Ion 1.1 Adds support for Ion 1.1 to inspect Aug 23, 2024
Comment on lines +508 to +512
Binary_1_0(bin_val) => {
self.inspect_literal_scalar(depth, delimiter, value, bin_val, comment_fn)
}
Binary_1_1(bin_val) => {
self.inspect_literal_scalar(depth, delimiter, value, bin_val, comment_fn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that worth a code comment, or is it obvious at a glance to people more experienced with Rust and/or this code base than me?

@zslayton zslayton merged commit a852e28 into master Aug 24, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants