Skip to content

[mypyc] Support the u32 native integer type - #22373

Merged
JukkaL merged 2 commits into
masterfrom
mypyc-u32
Nov 5, 2026
Merged

JukkaL merged 2 commits into
masterfrom
mypyc-u32

Conversation

@JukkaL

@JukkaL JukkaL commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

u32 is an unsigned 32-bit integer. The implementation mostly follows u16 (#22368).

Major differences:

  • Boxing uses PyLong_FromUnsignedLong.
  • On 32-bit platforms a u32 may not fit in a short tagged int, so converting to int checks the range and calls CPyTagged_FromUInt32 for large values, and converting from a long int uses CPyLong_AsUInt32.

Work on mypyc/mypyc#1226.

u32 is an unsigned 32-bit integer. The implementation mostly follows u16
(#22368).

Major differences:
- Boxing uses PyLong_FromUnsignedLong.
- On 32-bit platforms a u32 may not fit in a short tagged int, so
  converting to int checks the range and calls CPyTagged_FromUInt32
  for large values, and converting from a long int uses CPyLong_AsUInt32.

Work on mypyc/mypyc#1226.
@github-actions

This comment has been minimized.

Comment thread mypyc/lib-rt/CPy.h Outdated
Comment on lines +473 to +474
if (x < 0x40000000)
return x;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the digits are at most 30 bits so the check is redundant. we could return immediately to match CPyLong_AsInt32.

Comment thread mypyc/lib-rt/CPy.h Outdated
Comment on lines +484 to +485
if (x < 65536)
return x;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here

A single digit is at most 30 bits, so it always fits in uint32_t.
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL
JukkaL merged commit 94fc15b into master Nov 5, 2026
26 checks passed
@JukkaL
JukkaL deleted the mypyc-u32 branch November 5, 2026 16:49
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