Repository navigation
[mypyc] Report an error for vec item types i8, u16, u32 and u64 - #22482
Closed
Jahongir-Qurbonov wants to merge 1 commit into
Closed
Jahongir-Qurbonov wants to merge 1 commit into
Jahongir-Qurbonov wants to merge 1 commit into
Conversation
librt.vecs has specialized vec types only for the native int types i64,
i32, i16 and u8. Using another native int type as a vec item type passed
type checking, but mypyc then crashed with an internal error
("AssertionError: unsupported: vec[u64]") when compiling a vec
construction. In interpreted code, vec[u64]() created a generic vec that
couldn't hold any values (append raised "TypeError: invalid item type").
Now "Invalid item type for vec" is reported for these types, like for
vec[int].
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Collaborator
|
#22497 adds support for the new vec item types, so this won't be needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
librt.vecs has specialized vec types only for the native int types
i64,i32,i16andu8. The other native int types (i8,u16,u32andu64, the first and last added recently in #22447 and #22384) passed type checking as vec item types, but mypyc crashed when compiling a vec construction:(raised from
vec_createinmypyc/irbuild/vec.py). In interpreted code,vec[u64]()falls through to the generic vec path with theu64class as the item type, so the vec can't hold any values:append(v, 5)raisesTypeError: invalid item type.Now
check_vec_type_args()reportsInvalid item type for "vec"for these types, like it already does forvec[int], so the error is reported by type checking instead of an internal error during compilation. The docs mention that they aren't supported yet.Adding real support would need new specialized vec types in the C runtime (and a change to the librt.vecs C API), which seems like a separate, larger change that's better left for when it's wanted. If that's preferred instead, I'm happy to close this.
Tests:
vec[i8],vec[u16],vec[u32],vec[u64], a nestedvec[vec[u64]]andvec[u64 | None]incheck-vec.test, and a new irbuild error case inirbuild-vec-t.testthat also coversvec[u64]()in a function body.