KEMBAR78
Use 1 byte per type/symbol tag by ilevkivskyi · Pull Request #19735 · python/mypy · GitHub
Skip to content

Conversation

ilevkivskyi
Copy link
Member

This is a small incremental improvement for fixed format cache. I am adding a dedicated write/read functions for tags (i.e. integers in 0-255 range). I propose to exclusively use these functions for type tags (hence the name), and still use regular write_int()/read_int() for integers that are "accidentally small" (like argument kinds etc). In a separate PR I will change regular int format to be more progressive (e.g. only use 1 byte if an integer happens to be small). I also change the terminology from "marker" to "tag", as this is a more common name for this concept.

Note we can probably use mypy_extensions.u8 for type tags. If there is a desire for this, I can switch to it (either in this or a separate PR).

@ilevkivskyi ilevkivskyi requested a review from JukkaL August 26, 2025 11:17
@github-actions

This comment has been minimized.

)

function_op(
name="native_internal.write_native_internal",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the name be ...write_tag, similar to the above ones?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, it looks like some Ctrl+R went wrong :-) Will fix it.

name="native_internal.write_native_internal",
arg_types=[object_rprimitive, int_rprimitive],
return_type=none_rprimitive,
c_function_name="write_native_internal_internal",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be write_tag_internal?

)

function_op(
name="native_internal.read_native_internal",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above.

name="native_internal.read_native_internal",
arg_types=[object_rprimitive],
return_type=int_rprimitive,
c_function_name="read_native_internal_internal",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above.

@github-actions
Copy link
Contributor

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

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 26, 2025

Note we can probably use mypy_extensions.u8 for type tags. If there is a desire for this, I can switch to it (either in this or a separate PR).

As discussed offline, I think that this is a good idea (if it doesn't cause any trouble). I think it's okay to do this in a follow-up PR, but it's up to you.

@ilevkivskyi
Copy link
Member Author

OK, I will make a separate PR for u8.

@ilevkivskyi ilevkivskyi merged commit dcb4d69 into python:master Aug 26, 2025
20 checks passed
@ilevkivskyi ilevkivskyi deleted the add-short-int branch August 26, 2025 20:10
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