Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
05f6781
[vec] Basic vec support
JukkaL Apr 9, 2021
398b483
Various fixes
JukkaL Sep 16, 2022
33c4167
Fix vec test case
JukkaL Sep 17, 2022
93d4deb
Fix vec comprehensions
JukkaL Sep 17, 2022
ad81180
Fix type applications
JukkaL Sep 17, 2022
f2be756
Support some borrowing with vecs
JukkaL Sep 17, 2022
5205ae7
Update a few test cases
JukkaL Apr 10, 2023
e7a79d7
Add TODO
JukkaL Apr 30, 2023
a77c41a
[WIP] Start work on new representation for vecs
JukkaL May 8, 2023
ee21534
Support vec[i64] remove()
JukkaL May 8, 2023
c3138ba
Support vec instances in attributes
JukkaL May 8, 2023
a3d6267
Support vec[i64] pop with new repr
JukkaL May 29, 2023
6421384
Some partial support for vec[t]
JukkaL May 29, 2023
1c30eda
Some partial support for vec[t | None]
JukkaL May 29, 2023
a70dbfe
Test updates
JukkaL May 29, 2023
466cc85
More vec[t] operations
JukkaL May 29, 2023
6bdadc7
Format code
JukkaL Jun 10, 2023
c22a744
[mypyc] Add SetElement op for initializing struct values
JukkaL Jun 10, 2023
2a902c5
Add initial nested vec support
JukkaL Jun 10, 2023
3da9b66
Add vec tests
JukkaL Jun 11, 2023
8be74b6
Fix compile errors during vec construction
JukkaL Jun 11, 2023
3724b5a
Update test case
JukkaL Jun 11, 2023
e2c04a6
Support vec get item in more cases
JukkaL Jun 11, 2023
a737f7c
Fix set item
JukkaL Jun 11, 2023
f866775
Fix serialization
JukkaL Jun 11, 2023
1f6fba9
Update tests
JukkaL Jun 11, 2023
3efe0d8
Update test case
JukkaL Jun 11, 2023
c58b49e
Add pop test case
JukkaL Jun 11, 2023
2aa90b9
Update test case
JukkaL Jun 11, 2023
4657d71
Fix refcounting of item type + update tests
JukkaL Jun 11, 2023
cfe392b
Refactor vec irbuild tests
JukkaL Jun 11, 2023
575b130
Add vec test case
JukkaL Jun 11, 2023
a54532e
Fix always defined attribute analysis
JukkaL Jun 11, 2023
0417298
WIP make benchmarks compile (not working)
JukkaL Jun 13, 2023
c9be612
Format code
JukkaL Jun 17, 2023
db880bf
Properly support vec error values
JukkaL Jun 17, 2023
158a609
Fix vec remove
JukkaL Jun 17, 2023
14f98ef
Fix nested vec get item
JukkaL Jun 18, 2023
ed24c70
Update some tests
JukkaL Jun 25, 2023
3028f66
Implement unboxing
JukkaL Jun 25, 2023
24764bf
Split vec tests into multiple files
JukkaL Jul 8, 2023
d165baa
Add comments to tests
JukkaL Jul 8, 2023
58a64ae
Fix set item + add some run tests
JukkaL Jul 8, 2023
2bcf03b
Add test cases
JukkaL Jul 8, 2023
0af2531
Add test cases
JukkaL Jul 8, 2023
1f8c36a
Test contains
JukkaL Jul 8, 2023
ca6025a
Add run tests
JukkaL Jul 8, 2023
6e13589
Refactor
JukkaL Jul 8, 2023
f9e14e8
Support construction from an arbitrary iterable
JukkaL Jul 8, 2023
a24fa35
Test remove
JukkaL Jul 8, 2023
542ed50
Add test case for pop
JukkaL Jul 8, 2023
2749467
Add initial vec[t] run tests
JukkaL Jul 8, 2023
bb4e022
Add test cases for optional items
JukkaL Jul 9, 2023
15e5610
Start adding nested vec test cases
JukkaL Jul 9, 2023
0d61437
Don't support vec[...] | None as item type, to match runtime
JukkaL Aug 19, 2023
e60aca1
Allow empty vec[t] and vec[t | None] to be represented with a NULL buf
JukkaL Aug 19, 2023
1c727f2
Use the latest alloc API that accepts capacity as well
JukkaL Aug 19, 2023
9312489
Make operator assignment faster
JukkaL Aug 19, 2023
d23195d
Add some checks for vec item types (incomplete)
JukkaL Aug 26, 2023
517975b
Check vec item types during construction
JukkaL Aug 26, 2023
f7b0791
Enable nested vec test cases
JukkaL Aug 26, 2023
ec4512c
Fix step size calculation for nested vecs
JukkaL Aug 26, 2023
d65bf6d
Enable test cases
JukkaL Aug 26, 2023
afffa93
Fix tests after rebase
JukkaL Sep 2, 2023
08b1826
Support nested vec pop
JukkaL Sep 2, 2023
8f5745b
Add tests for double nested vecs
JukkaL Sep 3, 2023
56b86a4
Test nested vec[i64]
JukkaL Sep 3, 2023
d00fb06
Add tests
JukkaL Sep 3, 2023
e897f29
Support negative indexes
JukkaL Sep 3, 2023
0099332
Update irbuild tests for negative indexing
JukkaL Dec 26, 2023
812ecc3
Detect additional invalid vec item types
JukkaL Dec 26, 2023
87d8f7d
Support final vec values
JukkaL Dec 26, 2023
588c5da
Test vec as default argument value
JukkaL Dec 26, 2023
b37ee5c
Test vec as tuple item
JukkaL Dec 26, 2023
ac8a09a
Fix wrapper functions
JukkaL Dec 26, 2023
cddaea6
Fix memory corruption bug
JukkaL Dec 26, 2023
d09b2d2
Fix vec argument type checking in wrapper functions
JukkaL Dec 26, 2023
fda4c6b
Update to work with the latest vec implementation
JukkaL Dec 27, 2023
39189ac
Only import vec capsule if needed
JukkaL Dec 27, 2023
85ec9ae
Fix self check
JukkaL Dec 27, 2023
58a0b6f
WIP add failing test
JukkaL Dec 27, 2023
4287e8b
Support fast list vec comprehensions (from list/tuple)
JukkaL Dec 27, 2023
ea8490f
Support fast comprehensions iterating over vecs
JukkaL Dec 27, 2023
269325b
Support additional item types in vec creation
JukkaL Jan 28, 2024
db6b555
Support append with additional item types
JukkaL Jan 28, 2024
e514bd2
Support pop with additional item types
JukkaL Jan 28, 2024
c300cd4
Support additional item types with remove
JukkaL Jan 28, 2024
eb8af92
Support slicing with additional item types
JukkaL Jan 28, 2024
5a3ab6c
Support construction of vec with misc item types from a list expression
JukkaL Jan 28, 2024
e388eca
Test for loop over vec[float]
JukkaL Jan 28, 2024
de27f6d
Fix vec item size calculation and update tests
JukkaL Jan 28, 2024
603ab44
Update tests
JukkaL Jan 28, 2024
504f1ac
Fix nested vecs and boxing vecs
JukkaL Jan 28, 2024
61b6931
Fix vec unboxing with additional item types
JukkaL Jan 28, 2024
6b2fd35
Fix vec remove
JukkaL Jan 28, 2024
e35763b
Minimal runtime support for new vec item types (no tests)
JukkaL Jan 28, 2024
ca07aab
Add a run test for additional item types
JukkaL Jan 28, 2024
b4f084b
Add run test case
JukkaL Jan 28, 2024
a26b5ba
Add run tests
JukkaL Jan 28, 2024
02d083a
Fixes to nested vecs with specialized item types
JukkaL Feb 10, 2024
262148d
Test unboxing
JukkaL Feb 10, 2024
45c4241
Test for loop
JukkaL Feb 10, 2024
8c074eb
Add comprehension tests
JukkaL Feb 10, 2024
a6503d1
Fix duplicate visit_set_element methods after rebase
JukkaL Jan 19, 2026
9d4adb1
Fix issues due to rebase
JukkaL Jan 19, 2026
260393e
Fix self check errors
JukkaL Jan 19, 2026
fda233c
Fix self check
JukkaL Jan 19, 2026
f8f7cd2
Update irbuild tests to pass
JukkaL Jan 19, 2026
a9edd69
Update some vec irbuild test outputs
JukkaL Jan 19, 2026
77f584a
Fix a few vec test failures
JukkaL Jan 19, 2026
d852e56
Update a few vec irbuild test outputs
JukkaL Jan 19, 2026
8da6403
Update a few vec tests
JukkaL Jan 19, 2026
bb9a4b7
WIP update symbolic link to vecs.h
JukkaL Jan 19, 2026
d051c75
Update vecs.h references to librt_vecs.h
JukkaL Jan 28, 2026
bfaf5d7
Remove temporary vecs.pyi
JukkaL Jan 28, 2026
55e7c20
Remove redundant vecs stub
JukkaL Jan 28, 2026
9ec2344
Update vecs references in mypy to librt.vecs
JukkaL Jan 28, 2026
8c500fa
Update vecs references in mypyc to librt.vecs
JukkaL Jan 28, 2026
1e0bf8e
Fix mypyc self check
JukkaL Jan 28, 2026
4419de8
Fix irbuild tests
JukkaL Jan 28, 2026
f1fb682
Fix vec capsule in generated code (WIP)
JukkaL Jan 28, 2026
4a5df85
Steal first arg of pop and remove
JukkaL Jan 28, 2026
1811d5f
Fix vec[i64] run tests using primitives
JukkaL Jan 28, 2026
9758bcc
Fix slicing that returns an empty vec
JukkaL Jan 28, 2026
e925a03
Fix additional vec run tests
JukkaL Jan 28, 2026
4ab4515
Fix nested vec run tests
JukkaL Jan 28, 2026
5b0c9fd
Fix more tests
JukkaL Jan 28, 2026
1016b2f
Fix more tests
JukkaL Jan 28, 2026
242ab7c
Rename some test files
JukkaL Jan 28, 2026
e892e72
Fix issues caused by rebase
JukkaL Jan 28, 2026
f889502
Revert test fixture change
JukkaL Jan 28, 2026
e730c32
Lint
JukkaL Jan 29, 2026
0859c40
Move to a more standard capsule mechanism
JukkaL Jan 29, 2026
2c9ddbc
Delete unused vecusage module and tests
JukkaL Jan 29, 2026
536591b
Fix attribute type capsule deps
JukkaL Jan 29, 2026
9d21735
WIP fix 32-bit
JukkaL Jan 29, 2026
c5fd68c
WIP
JukkaL Jan 29, 2026
f3ee70b
WIP
JukkaL Jan 29, 2026
a79ef03
ircheck: Allow pointer arithmetic even though it's unsigned + signed
JukkaL Jan 29, 2026
06f3133
Lint
JukkaL Jan 29, 2026
7c1fbc7
Add range check helper and int coercion to ssize_t
JukkaL Jan 29, 2026
d2a9420
Coerce set item index to ssize_t
JukkaL Jan 29, 2026
4bd4885
Remove temporary test case
JukkaL Jan 29, 2026
6e5c3a4
Also coerce on get item
JukkaL Jan 29, 2026
fb1d828
WIP
JukkaL Jan 30, 2026
025fc69
WIP
JukkaL Jan 30, 2026
830e510
WIP
JukkaL Jan 30, 2026
e189985
WIP
JukkaL Jan 30, 2026
4c93663
WIP
JukkaL Jan 30, 2026
91d92f5
WIP
JukkaL Jan 30, 2026
5548217
WIP attempt at fixing 32-bit issue
JukkaL Jan 30, 2026
4c26e03
WIP Fix 32-bit
JukkaL Jan 30, 2026
81b2356
[mypyc] Support isinstance with librt.vecs.vec objects
JukkaL Jan 30, 2026
d080171
Test unions with vec[i64]
JukkaL Jan 30, 2026
3723b4d
Remove unused 'struct_type' attr
JukkaL Jan 30, 2026
0d96118
Add primitive for isinstance(x, vec)
JukkaL Jan 30, 2026
86b17da
Minor cleanup
JukkaL Feb 2, 2026
9277ae5
Restore deleted tests due to bad merge
JukkaL Feb 2, 2026
bafca40
Minor clarifications
JukkaL Feb 2, 2026
7df1be7
Add missing librt_vercs_ops.py file
JukkaL Feb 2, 2026
77c0646
Fix primitive dep
JukkaL Feb 2, 2026
e999af2
Move function to extra ops header
JukkaL Feb 2, 2026
79455a5
Fix vec pop with optional item type
JukkaL Feb 2, 2026
d1ee773
Fix after rebase
JukkaL Feb 2, 2026
2893618
Lint
JukkaL Feb 2, 2026
68763a4
Remove commented out code
JukkaL Feb 2, 2026
fbaa99f
Remove unused param
JukkaL Feb 2, 2026
8484cf8
WIP temporarily delete vec run tests
JukkaL Feb 2, 2026
d20ca79
WIP temporarily delete various irbuild vec tests
JukkaL Feb 2, 2026
ff1e2d9
WIP delete tests from test runners
JukkaL Feb 2, 2026
bf0866f
WIP delete codegen related changes temporarily
JukkaL Feb 2, 2026
d9bbaf0
WIP temporarily revert changes to refcount.test
JukkaL Feb 2, 2026
5936862
Minor tweaks
JukkaL Feb 2, 2026
fe43e12
Fix typo
JukkaL Feb 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion mypyc/analysis/capsule_deps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

from mypyc.ir.class_ir import ClassIR
from mypyc.ir.deps import Dependency
from mypyc.ir.func_ir import FuncIR
from mypyc.ir.ops import Assign, CallC, PrimitiveOp
from mypyc.ir.rtypes import RStruct, RTuple, RType, RUnion
from mypyc.ir.rtypes import RStruct, RTuple, RType, RUnion, RVec


def find_implicit_op_dependencies(fn: FuncIR) -> set[Dependency] | None:
Expand Down Expand Up @@ -48,6 +49,15 @@ def find_type_dependencies(fn: FuncIR, deps: set[Dependency] | None) -> set[Depe
return deps


def find_class_dependencies(cl: ClassIR) -> set[Dependency] | None:
"""Find dependencies from class attribute types."""
deps: set[Dependency] | None = None
for base in cl.mro:
for attr_type in base.attributes.values():
deps = collect_type_deps(attr_type, deps)
return deps


def collect_type_deps(typ: RType, deps: set[Dependency] | None) -> set[Dependency] | None:
"""Collect dependencies from an RType, recursively checking compound types."""
if typ.dependencies is not None:
Expand All @@ -64,4 +74,6 @@ def collect_type_deps(typ: RType, deps: set[Dependency] | None) -> set[Dependenc
elif isinstance(typ, RStruct):
for item in typ.types:
deps = collect_type_deps(item, deps)
elif isinstance(typ, RVec):
deps = collect_type_deps(typ.item_type, deps)
return deps
6 changes: 6 additions & 0 deletions mypyc/analysis/dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ def visit_assign_multi(self, op: AssignMulti) -> GenAndKill[T]:
def visit_set_mem(self, op: SetMem) -> GenAndKill[T]:
raise NotImplementedError

def visit_inc_ref(self, op: IncRef) -> GenAndKill[T]:
return self.visit_register_op(op)

def visit_dec_ref(self, op: DecRef) -> GenAndKill[T]:
return self.visit_register_op(op)

def visit_call(self, op: Call) -> GenAndKill[T]:
return self.visit_register_op(op)

Expand Down
31 changes: 30 additions & 1 deletion mypyc/analysis/ircheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,17 @@
RPrimitive,
RType,
RUnion,
RVec,
bytes_rprimitive,
dict_rprimitive,
int_rprimitive,
is_c_py_ssize_t_rprimitive,
is_fixed_width_rtype,
is_float_rprimitive,
is_object_rprimitive,
is_pointer_rprimitive,
list_rprimitive,
pointer_rprimitive,
range_rprimitive,
set_rprimitive,
str_rprimitive,
Expand Down Expand Up @@ -200,7 +205,7 @@ def can_coerce_to(src: RType, dest: RType) -> bool:
if src.name in disjoint_types and dest.name in disjoint_types:
return src.name == dest.name
return src.size == dest.size
if isinstance(src, RInstance):
if isinstance(src, (RInstance, RVec)):
return is_object_rprimitive(dest)
if isinstance(src, RUnion):
# IR doesn't have the ability to narrow unions based on
Expand All @@ -211,6 +216,29 @@ def can_coerce_to(src: RType, dest: RType) -> bool:
return True


def is_valid_ptr_displacement_type(rtype: RType) -> bool:
"""Check if rtype is a valid displacement type for pointer arithmetic."""
if not (is_fixed_width_rtype(rtype) or is_c_py_ssize_t_rprimitive(rtype)):
return False
assert isinstance(rtype, RPrimitive)
return rtype.size == pointer_rprimitive.size


def is_pointer_arithmetic(op: IntOp) -> bool:
"""Check if op is add/subtract targeting pointer_rprimtive and integer of the same size."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""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."""

if op.op not in (IntOp.ADD, IntOp.SUB):
return False
if not is_pointer_rprimitive(op.type):
return False
left = op.lhs.type
right = op.rhs.type
if is_pointer_rprimitive(left):
return is_valid_ptr_displacement_type(right)
if is_pointer_rprimitive(right):
return is_valid_ptr_displacement_type(left)
return False


class OpChecker(OpVisitor[None]):
def __init__(self, parent_fn: FuncIR) -> None:
self.parent_fn = parent_fn
Expand Down Expand Up @@ -417,6 +445,7 @@ def visit_int_op(self, op: IntOp) -> None:
op_str in ("+", "-", "*", "/", "%")
or (op_str not in ("<<", ">>") and left.size != right.size)
)
and not is_pointer_arithmetic(op)
):
self.fail(op, f"Operand types have incompatible signs: {left}, {right}")

Expand Down
8 changes: 8 additions & 0 deletions mypyc/analysis/selfleaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CallC,
Cast,
ComparisonOp,
DecRef,
Extend,
FloatComparisonOp,
FloatNeg,
Expand All @@ -19,6 +20,7 @@
GetElement,
GetElementPtr,
Goto,
IncRef,
InitStatic,
IntOp,
KeepAlive,
Expand Down Expand Up @@ -90,6 +92,12 @@ def visit_assign_multi(self, op: AssignMulti) -> GenAndKill:
def visit_set_mem(self, op: SetMem) -> GenAndKill:
return CLEAN

def visit_inc_ref(self, op: IncRef) -> GenAndKill:
return CLEAN

def visit_dec_ref(self, op: DecRef) -> GenAndKill:
return CLEAN

def visit_call(self, op: Call) -> GenAndKill:
fn = op.fn
if fn.class_name and fn.name == "__init__":
Expand Down
1 change: 1 addition & 0 deletions mypyc/ir/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ def get_header(self) -> str:
STRING_WRITER_EXTRA_OPS: Final = SourceDep("stringwriter_extra_ops.c")
BYTEARRAY_EXTRA_OPS: Final = SourceDep("bytearray_extra_ops.c")
STR_EXTRA_OPS: Final = SourceDep("str_extra_ops.c")
VECS_EXTRA_OPS: Final = SourceDep("vecs_extra_ops.c")
7 changes: 4 additions & 3 deletions mypyc/ir/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class to enable the new behavior. Sometimes adding a new abstract
RTuple,
RType,
RUnion,
RVec,
RVoid,
bit_rprimitive,
bool_rprimitive,
Expand Down Expand Up @@ -1690,7 +1691,7 @@ class GetElement(RegisterOp):

def __init__(self, src: Value, field: str, line: int = -1) -> None:
super().__init__(line)
assert isinstance(src.type, RStruct)
assert isinstance(src.type, (RStruct, RVec))
self.type = src.type.field_type(field)
self.src = src
self.src_type = src.type
Expand Down Expand Up @@ -1720,7 +1721,7 @@ class GetElementPtr(RegisterOp):

def __init__(self, src: Value, src_type: RType, field: str, line: int = -1) -> None:
super().__init__(line)
assert not isinstance(src.type, RStruct)
assert not isinstance(src.type, (RStruct, RVec))
self.type = pointer_rprimitive
self.src = src
self.src_type = src_type
Expand Down Expand Up @@ -1750,7 +1751,7 @@ class SetElement(RegisterOp):

def __init__(self, src: Value, field: str, item: Value, line: int = -1) -> None:
super().__init__(line)
assert isinstance(src.type, RStruct), src.type
assert isinstance(src.type, (RStruct, RVec)), src.type
self.type = src.type
self.src = src
self.item = item
Expand Down
Loading