Skip to content

Conversation

@hanno-becker
Copy link
Contributor

Previously, scripts/check-magic would remember only the last explained magic constant, preventing, for example, the explanation of multiple magic constants ahead of a comment block referring to all of them.

Moreover, check-magic would only lazily evaluate a provided explanation when actually finding a magic value magic the LHS of the proposed explanation. In particular, a wrong explanation would only be caught if, in the rest of the file under consideration, some matching magic constant would be found.

This commit makes check-magic more general so that

  • it always checks magic value explanations when they are provided, regardless of whether they are needed or not; and,
  • it remembers all magic values explained so far.

Moreover, the round function is instrumented to fail if it is called on an odd multiple of 1/2 -- in this case, the rounding is ambiguous (do we want round-half-down or round-half-up?).

We also add support for intdiv(a,b) to an integer division which we want to assert to be without residue. This can be used instead of // to additionally check that the division is indeed integral.

@hanno-becker hanno-becker marked this pull request as ready for review November 11, 2025 17:00
@hanno-becker hanno-becker requested a review from a team as a code owner November 11, 2025 17:00
Previously, scripts/check-magic would remember only the last explained
magic constant, preventing, for example, the explanation of multiple
magic constants ahead of a comment block referring to all of them.

Moreover, check-magic would only lazily evaluate a provided explanation
when actually finding a magic value magic the LHS of the proposed
explanation. In particular, a _wrong_ explanation would only be caught
if, in the rest of the file under consideration, some matching magic
constant would be found.

This commit makes check-magic more general so that
- it always checks magic value explanations when they are provided,
  regardless of whether they are needed or not; and,
- it remembers all magic values explained so far.

Moreover, the `round` function is instrumented to fail if it is
called on an odd multiple of 1/2 -- in this case, the rounding
is ambiguous (do we want round-half-down or round-half-up?).

We also add support for `intdiv(a,b)` to an integer division which we
want to assert to be without residue. This can be used instead of `//`
to additionally check that the division is indeed integral.

Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
Copy link
Contributor

@mkannwischer mkannwischer left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @hanno-becker!

@mkannwischer mkannwischer merged commit 8a25f12 into main Nov 12, 2025
388 checks passed
@mkannwischer mkannwischer deleted the check-magic-fix branch November 12, 2025 08:55
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.

3 participants