-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[mypyc] Add irbuild support for vec types #20724
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
base: master
Are you sure you want to change the base?
Conversation
Some vec[i64] features are supported at the moment, but things are still very incomplete.
Also add Undef value type that can currently only used as the operand for SetElement to signify that we are creating a new value instead of modifying an existing value.
Use a common base class 'vec' for isinstance support. The base class is currently only used for isinstance, but we could add some other basic functionality there in the future.
|
|
||
|
|
||
| def is_pointer_arithmetic(op: IntOp) -> bool: | ||
| """Check if op is add/subtract targeting pointer_rprimtive and integer of the same size.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Check if op is add/subtract targeting pointer_rprimtive and integer of the same size.""" | |
| """Check if op is add/subtract targeting pointer_rprimitive and integer of the same size.""" |
| "object_ptr", is_unboxed=False, is_refcounted=False, ctype="PyObject **" | ||
| ) | ||
|
|
||
| # Similar to object_primitive, but doesn not use automatic reference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Similar to object_primitive, but doesn not use automatic reference | |
| # Similar to object_primitive, but does not use automatic reference |
| return RVec(deserialize_type(data["item_type"], ctx)) | ||
|
|
||
|
|
||
| def vec_depth(t: RVec) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as RVec.depth()
| names=["ob_base", "len", "items"], | ||
| types=[PyVarObject, int64_rprimitive], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
items is missing a type here and in the other buf objects for primitives.
mypyc/ir/rtypes.py
Outdated
| bool_rprimitive: "VecBoolApi", | ||
| } | ||
|
|
||
| # These are special type item type contants used in nested vecs to represent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # These are special type item type contants used in nested vecs to represent | |
| # These are special item type constants used in nested vecs to represent |
| item_addr = vec_item_ptr(builder, base, index) | ||
| result = builder.load_mem(item_addr, vtype.item_type, borrow=can_borrow) | ||
| builder.keep_alives.append(base) | ||
| return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aside from the index check this is very similar to the unsafe function, could it be called here?
| elif vec_depth(vec_type) == 0 and not isinstance(item_type, RUnion): | ||
| name = "VecTApi.remove" | ||
| else: | ||
| coerced_item = convert_to_t_ext_item(builder, coerced_item) | ||
| name = "VecNestedApi.remove" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean that for vecs with optional types we use the API for nested vecs? i thought it would be vecT. same pattern in vec_slice but not in other functions.
| r0 = VecI64Api.alloc(0, 0) | ||
| r1 = r0 | ||
| r2 = 0 | ||
| x = r2 | ||
| L1: | ||
| r3 = r2 < 5 :: signed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it probably won't matter much, but if we can tell that there will be 5 elements, we should be able to pre-allocate the vector.
| r0 = VecI64Api.alloc(0, 0) | ||
| r1 = r0 | ||
| r2 = 0 | ||
| r3 = r2 >> 1 | ||
| ___tmp_5 = r3 | ||
| L1: | ||
| r4 = int_lt r2, 14 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same in this case
Add basic irbuild support for
vec[t]. The runtime representation ofvec[t]is a C struct. This is similar to how fixed-length tuples are represented. Multiple different structs are used, depending on the item type (VecI32forvec[i32] and so on).The C extension
librt.vecthat defines thevectype was added in #20653 and #20656. These PRs also explain the implementation in more detail.Add RType subclass RVec that is used for vecs. We need a new RType class, since primitives types can't be generic and they can't be struct types.
This is based on an old branch, so it mostly uses old-style primitives. I am planning to modernize some of the primitives in follow-up PRs.
This doesn't include codegen support, and irbuild test cases are only included for
vec[i64]. I will create follow-up PRs that add the remaining irbuild tests, codegen support and run tests. All these tests are are passing on my local full branch.Related issue: mypyc/mypyc#840