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.
|
|
||
|
|
||
| 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.
| """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.
| # 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: |
| names=["ob_base", "len", "items"], | ||
| types=[PyVarObject, int64_rprimitive], |
There was a problem hiding this comment.
items is missing a type here and in the other buf objects for primitives.
There was a problem hiding this comment.
The IR can't represent the items field, since it's a variable-length array. That's why the type is not included. I will add a comment about this.
| bool_rprimitive: "VecBoolApi", | ||
| } | ||
|
|
||
| # These are special type item type contants used in nested vecs to represent |
There was a problem hiding this comment.
| # 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.
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.
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.
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.
There was a problem hiding this comment.
A good idea, I will add a TODO comment about this.
| 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.
I will add a TODO comment.
| elif vec_type.depth() == 0 and not isinstance(item_type, RUnion): | ||
| name = "VecTApi.slice" | ||
| else: | ||
| name = "VecNestedApi.slice" |
There was a problem hiding this comment.
one more case where the handling for vecs with optional items should be updated, i think.
…0732) Follow-up to #20724. This wasn't included in the original PR to keep it smaller. This includes irbuild tests for item types other than `i64`. Related issue: mypyc/mypyc#840
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