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

fix small_number() patch #379

Merged
merged 1 commit into from
Feb 12, 2024
Merged

fix small_number() patch #379

merged 1 commit into from
Feb 12, 2024

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented Feb 12, 2024

The interpreter relies on being able to retrieve small atoms via small_number() even if they happen to be allocated on the heap, as normal atoms (but small).

…rieve small atoms via small_number() even if they happen to be allocated on the heap, as normal atoms (but small).
Copy link

Pull Request Test Coverage Report for Build 7870333649

Details

  • -3 of 31 (90.32%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 94.333%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/allocator.rs 27 30 90.0%
Totals Coverage Status
Change from base Build 7850857111: -0.03%
Covered Lines: 5776
Relevant Lines: 6123

💛 - Coveralls

@arvidn arvidn marked this pull request as ready for review February 12, 2024 10:35
@arvidn arvidn merged commit 1242062 into main Feb 12, 2024
27 checks passed
@arvidn arvidn deleted the fixup-small-int branch February 12, 2024 19:03
ObjectType::Bytes => {
let atom = self.atom_vec[node.index() as usize];
let buf = &self.u8_vec[atom.start as usize..atom.end as usize];
if buf.len() > 3 || !canonical_positive_integer(buf) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 3? Wouldn't it be okay to allow integers of size 4 that can still be represented by a u32?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait, I get it now. You're checking if it CAN be representable as a u32 first.

Copy link
Contributor Author

@arvidn arvidn Feb 13, 2024

Choose a reason for hiding this comment

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

you're right that it would be possible to represent half of all 4-byte buffers as u32. This rule, however, is consistent with whether it can be represented as a SmallAtom node. Which is 26 bits (i.e. 3 bytes + 2 bits, we're rounding that to 3 bytes here).

This is the check in other places too, such as fn new_atom(&[u8]) -> NodePtr. Perhaps it would make sense to factor out this check to make sure it's consistent everywhere, and maybe it would even make sense to make it exactly 26 bits (rather than 24).

For instance, it just occurred to me that the value 0x800000 would not be considered fitting in a SmallAtom, even though it would, just because the leading zero byte would bump it to 4.

Anyway, the two approaches I see are:

  1. factor out this logic, make it more precise (to cover more large numbers)
  2. make this logic special, since we don't technically need it to fit in a SmallAtom, we just need it to fit in a u32

I'm leaning towards (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.

I will propose a patch to improve this situation, aiming for (1). i.e. making this function behave consistently with whether an atom can be represented as a SmallAtom rather than whether it can be represented as a u32

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

None yet

3 participants