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 read support for system eexps #869

Merged
merged 2 commits into from
Dec 4, 2024
Merged

Adds binary read support for system eexps #869

merged 2 commits into from
Dec 4, 2024

Conversation

zslayton
Copy link
Contributor

@zslayton zslayton commented Dec 4, 2024

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

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

Attention: Patch coverage is 85.07463% with 10 lines in your changes missing coverage. Please review.

Project coverage is 77.87%. Comparing base (81038b6) to head (890fd64).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/lazy/binary/raw/v1_1/immutable_buffer.rs 75.00% 5 Missing and 2 partials ⚠️
src/lazy/expanded/macro_evaluator.rs 92.30% 0 Missing and 2 partials ⚠️
src/lazy/binary/raw/v1_1/type_descriptor.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #869      +/-   ##
==========================================
+ Coverage   77.86%   77.87%   +0.01%     
==========================================
  Files         136      136              
  Lines       34273    34314      +41     
  Branches    34273    34314      +41     
==========================================
+ Hits        26685    26723      +38     
+ Misses       5631     5630       -1     
- Partials     1957     1961       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 🧭

@@ -141,7 +141,7 @@ impl<'top> RawEExpression<'top, v1_1::Binary> for &'top BinaryEExpression_1_1<'t
type ArgGroup = BinaryEExpArgGroup<'top>;

fn id(self) -> MacroIdRef<'top> {
MacroIdRef::LocalAddress(self.macro_ref.address())
self.macro_ref.id()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Throughout this patch, places using a "macro address" have been generalized to work with a "macro ID," allowing them to distinguish between an address in the application's macro table and one in the system table.

Comment on lines +866 to +870
let (macro_id, input_after_address) = match opcode.opcode_type {
EExpressionWith6BitAddress => (
MacroIdRef::LocalAddress(opcode.byte as usize),
self.consume(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.

🗺️ Each arm in this match now returns a MacroIdRef instead of a MacroAddress (usize).

}
// Length-prefixed is a special case.
EExpressionWithLengthPrefix => return self.read_eexp_with_length_prefix(opcode),
SystemEExpression => {
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 actual read logic for binary e-expressions. This is the only arm that returns something other than a MacroIdRef::LocalAddress—it returns a MacroIdRef::SystemAddress.

@@ -37,7 +37,7 @@ pub enum OpcodeType {
TypedNull, // 0xEB -
Nop, // 0xEC-0xED -
SystemSymbolAddress, // 0xEE
SystemMacroEExpression, // 0xEF -
SystemEExpression, // 0xEF -
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Renamed for consistency. *MacroEExpression was redundant anyway.

assert_eq_expected(&actual, expected)
}

fn bin_stream_eq(input: &[u8], expected: &str) -> IonResult<()> {
Copy link
Contributor Author

@zslayton zslayton Dec 4, 2024

Choose a reason for hiding this comment

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

🗺️ The unit test helper stream_eq was hardcoded to expect 1.1 text so each call site didn't have to repeat the 1.1 IVM. For this PR I needed to test reading binary streams, so I added an analogous bin_stream_eq.

Copy link
Contributor

Choose a reason for hiding this comment

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

The diff generated here is not ideal, and that made me wonder which diffing algorithm GitHub uses. Apparently it (like other review tools I'm familiar with) uses the Git default (Myers): https://stackoverflow.com/questions/61769668/whats-the-diff-algorithm-used-by-github

The Patience algorithm would do better here. Here's an analogous example: https://gist.github.com/roryokane/6f9061d3a60c1ba41237

Nothing to do here, I'm just pointing it out so that from now on you can also be slightly dissatisfied when you encounter odd diffs.

EDIT: One thing you can do is +1 this community discussion? https://github.com/orgs/community/discussions/16782

Comment on lines -147 to -151
pub fn id_text(&'top self) -> Cow<'top, str> {
self.name()
.map(Cow::from)
.unwrap_or_else(move || Cow::from(format!("{}", self.address())))
}
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 was unused.

@@ -125,13 +124,16 @@ pub enum MacroKind {

#[derive(Debug, Copy, Clone, PartialEq)]
pub struct MacroRef<'top> {
address: MacroAddress,
id: MacroIdRef<'top>,
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 allows us to track the ID used to look up the associated &'top Macro.

@zslayton zslayton marked this pull request as ready for review December 4, 2024 16:54
assert_eq_expected(&actual, expected)
}

fn bin_stream_eq(input: &[u8], expected: &str) -> IonResult<()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The diff generated here is not ideal, and that made me wonder which diffing algorithm GitHub uses. Apparently it (like other review tools I'm familiar with) uses the Git default (Myers): https://stackoverflow.com/questions/61769668/whats-the-diff-algorithm-used-by-github

The Patience algorithm would do better here. Here's an analogous example: https://gist.github.com/roryokane/6f9061d3a60c1ba41237

Nothing to do here, I'm just pointing it out so that from now on you can also be slightly dissatisfied when you encounter odd diffs.

EDIT: One thing you can do is +1 this community discussion? https://github.com/orgs/community/discussions/16782

@zslayton zslayton merged commit ed541e8 into main Dec 4, 2024
25 of 33 checks passed
@zslayton zslayton deleted the bin-sys-eexps branch December 4, 2024 17:14
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