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 binary 1.1 read support for symbol address annotations #814

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

zslayton
Copy link
Contributor

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

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

self.read_value(opcode)
.map(|(v, after)| (Some(v), after))
self.read_value(opcode).map(|(v, after)| (Some(v), after))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ cargo fmt re-flowed some things in this file even though they hadn't changed in this commit. You can ignore this and the one below (lines 630-654).

Comment on lines -731 to -735
// TODO: This implementation actively reads the annotations, which isn't necessary.
// At this phase of parsing we can just identify the buffer slice that contains
// the annotations and remember their encoding; later on, the annotations iterator
// can actually do the reading. That optimization would be impactful for FlexSyms
// that represent inline text.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ I did this optimization for skipping FlexUInt symbol addresses, but doing it for FlexSym would be much more involved. I introduced two methods below to encapsulate that logic:

  • consume_flex_uint (skips without reading)
  • consume_flex_sym (skips by reading)

Comment on lines -739 to -747
let sequence = EncodedAnnotations {
encoding: AnnotationsEncoding::FlexSym,
header_length: 1, // 0xE7
sequence_length: u16::try_from(flex_sym.size_in_bytes()).map_err(|_| {
IonError::decoding_error(
"the maximum supported annotations sequence length is 65KB.",
)
})?,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Previously I was constructing an EncodedAnnotations struct in each match arm. I lifted out out to the end of the method, which I think helped readability.

Comment on lines +777 to +781
let sequence = EncodedAnnotations {
encoding: AnnotationsEncoding::FlexSym,
header_length,
sequence_length,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Here's the instantiation of the EncodedAnnotations.

// TODO: As an optimization, see if we can avoid actually reading the flex_sym.
let (flex_sym, remaining) = self.read_flex_sym()?;
if let FlexSymValue::Opcode(opcode) = flex_sym.value() {
todo!("FlexSym escapes in annotation sequences; opcode: {opcode:?}");
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 skipper doesn't (yet) attempt to interpret the opcode and skip whatever it indicates.

}

/// Skips beyond a `FlexUInt` at the head of the buffer, returning the remaining slice.
fn consume_flex_uint(self) -> IonResult<Self> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Skips a FlexUInt without actually reading it.

@zslayton zslayton marked this pull request as ready for review August 15, 2024 20:06
@zslayton zslayton merged commit fa0f83f into main Aug 15, 2024
29 of 32 checks passed
@zslayton zslayton deleted the symbol-address-annotations branch August 15, 2024 20:48
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