Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions mypyc/irbuild/for_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Var,
)
from mypy.types import LiteralType, TupleType, get_proper_type, get_proper_types
from mypyc.common import IS_FREE_THREADED
from mypyc.ir.ops import (
ERR_NEVER,
BasicBlock,
Expand Down Expand Up @@ -81,7 +82,12 @@
)
from mypyc.primitives.exc_ops import no_err_occurred_op, propagate_if_error_op
from mypyc.primitives.generic_ops import aiter_op, anext_op, iter_op, next_op
from mypyc.primitives.list_ops import list_append_op, list_get_item_unsafe_op, new_list_set_item_op
from mypyc.primitives.list_ops import (
list_append_op,
list_get_item_int64_op,
list_get_item_unsafe_op,
new_list_set_item_op,
)
from mypyc.primitives.misc_ops import stop_async_iteration_op
from mypyc.primitives.registry import CFunctionDescription
from mypyc.primitives.set_ops import set_add_op
Expand Down Expand Up @@ -866,7 +872,10 @@ def unsafe_index(builder: IRBuilder, target: Value, index: Value, line: int) ->
# since we want to use __getitem__ if we don't have an unsafe version,
# so we just check manually.
if is_list_rprimitive(target.type):
return builder.primitive_op(list_get_item_unsafe_op, [target, index], line)
if not IS_FREE_THREADED:
return builder.primitive_op(list_get_item_unsafe_op, [target, index], line)
else:
return builder.primitive_op(list_get_item_int64_op, [target, index], line)
elif is_tuple_rprimitive(target.type):
return builder.call_c(tuple_get_item_unsafe_op, [target, index], line)
elif is_str_rprimitive(target.type):
Expand Down
6 changes: 3 additions & 3 deletions mypyc/test-data/irbuild-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ L0:
r5 = a.f(12, 6, r4)
return 1

[case testListComprehension]
[case testListComprehension_withgil]
from typing import List

def f() -> List[int]:
Expand Down Expand Up @@ -1931,7 +1931,7 @@ L7:
L8:
return r0

[case testDictComprehension]
[case testDictComprehension_withgil]
from typing import Dict
def f() -> Dict[int, int]:
return {x: x*x for x in [1,2,3] if x != 2 if x != 3}
Expand Down Expand Up @@ -1993,7 +1993,7 @@ L7:
L8:
return r0

[case testLoopsMultipleAssign]
[case testLoopsMultipleAssign_withgil]
from typing import List, Tuple
def f(l: List[Tuple[int, int, int]]) -> List[int]:
for x, y, z in l:
Expand Down
8 changes: 4 additions & 4 deletions mypyc/test-data/irbuild-lists.test
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ L0:
r2 = r1 >= 0 :: signed
return 1

[case testListBuiltFromGenerator]
[case testListBuiltFromGenerator_withgil]
from typing import List
def f(source: List[int]) -> None:
a = list(x + 1 for x in source)
Expand Down Expand Up @@ -448,7 +448,7 @@ L8:
b = r11
return 1

[case testGeneratorNext]
[case testGeneratorNext_withgil]
from typing import List, Optional

def test(x: List[int]) -> None:
Expand Down Expand Up @@ -489,7 +489,7 @@ L5:
res = r6
return 1

[case testSimplifyListUnion]
[case testSimplifyListUnion_withgil]
from typing import List, Union, Optional

def narrow(a: Union[List[str], List[bytes], int]) -> int:
Expand Down Expand Up @@ -923,7 +923,7 @@ L10:
a = r3
return 1

[case testListBuiltFromStars]
[case testListBuiltFromStars_withgil]
from typing import Final

abc: Final = "abc"
Expand Down
4 changes: 2 additions & 2 deletions mypyc/test-data/irbuild-set.test
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ L0:
r0 = PySet_New(l)
return r0

[case testNewSetFromIterable2]
[case testNewSetFromIterable2_withgil]
def f(x: int) -> int:
return x

Expand Down Expand Up @@ -273,7 +273,7 @@ L4:
e = r0
return 1

[case testNewSetFromIterable3]
[case testNewSetFromIterable3_withgil]
def f1(x: int) -> int:
return x

Expand Down
43 changes: 40 additions & 3 deletions mypyc/test-data/irbuild-statements.test
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ L5:
L6:
return 1

[case testForList]
[case testForList_withgil]
from typing import List

def f(ls: List[int]) -> int:
Expand Down Expand Up @@ -255,6 +255,43 @@ L3:
L4:
return y

[case testForList_nogil]
from typing import List

def f(ls: List[int]) -> int:
y = 0
for x in ls:
y = y + x
return y
[out]
def f(ls):
ls :: list
y :: int
r0, r1 :: native_int
r2 :: bit
r3 :: object
r4, x, r5 :: int
r6 :: native_int
L0:
y = 0
r0 = 0
L1:
r1 = var_object_size ls
r2 = r0 < r1 :: signed
if r2 goto L2 else goto L4 :: bool
L2:
r3 = CPyList_GetItemInt64(ls, r0)
r4 = unbox(int, r3)
x = r4
r5 = CPyTagged_Add(y, x)
y = r5
L3:
r6 = r0 + 1
r0 = r6
goto L1
L4:
return y

[case testForDictBasic]
from typing import Dict

Expand Down Expand Up @@ -899,7 +936,7 @@ L0:
r6 = r5 >= 0 :: signed
return 1

[case testForEnumerate]
[case testForEnumerate_withgil]
from typing import List, Iterable

def f(a: List[int]) -> None:
Expand Down Expand Up @@ -967,7 +1004,7 @@ L4:
L5:
return 1

[case testForZip]
[case testForZip_withgil]
from typing import List, Iterable, Sequence

def f(a: List[int], b: Sequence[bool]) -> None:
Expand Down
4 changes: 2 additions & 2 deletions mypyc/test-data/irbuild-tuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ L5:
L6:
return r6

[case testTupleBuiltFromList]
[case testTupleBuiltFromList_withgil]
def f(val: int) -> bool:
return val % 2 == 0

Expand Down Expand Up @@ -1018,7 +1018,7 @@ L5:
a = r42
return 1

[case testTupleBuiltFromStars]
[case testTupleBuiltFromStars_withgil]
from typing import Final

abc: Final = "abc"
Expand Down
4 changes: 2 additions & 2 deletions mypyc/test-data/irbuild-vec-i64.test
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ L3:
L4:
return r1

[case testVecI64FastComprehensionFromList]
[case testVecI64FastComprehensionFromList_nogil]
from librt.vecs import vec
from mypy_extensions import i64
from typing import List
Expand Down Expand Up @@ -364,7 +364,7 @@ L1:
r4 = r2 < r3 :: signed
if r4 goto L2 else goto L4 :: bool
L2:
r5 = list_get_item_unsafe l, r2
r5 = CPyList_GetItemInt64(l, r2)
r6 = unbox(i64, r5)
x = r6
r7 = x + 1
Expand Down
2 changes: 1 addition & 1 deletion mypyc/test-data/lowering-int.test
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ L4:
L5:
return 4

[case testLowerIntForLoop_64bit]
[case testLowerIntForLoop_withgil_64bit]
from __future__ import annotations

def f(l: list[int]) -> None:
Expand Down
8 changes: 7 additions & 1 deletion mypyc/test/test_lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mypy.errors import CompileError
from mypy.test.config import test_temp_dir
from mypy.test.data import DataDrivenTestCase
from mypyc.common import TOP_LEVEL_NAME
from mypyc.common import IS_FREE_THREADED, TOP_LEVEL_NAME
from mypyc.ir.pprint import format_func
from mypyc.options import CompilerOptions
from mypyc.test.testutil import (
Expand Down Expand Up @@ -36,6 +36,12 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
if options is None:
# Skipped test case
return
if "_withgil" in testcase.name and IS_FREE_THREADED:
# Test case should only run on a non-free-threaded build.
return
if "_nogil" in testcase.name and not IS_FREE_THREADED:
# Test case should only run on a free-threaded build.
return
with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
expected_output = remove_comment_lines(testcase.output)
expected_output = replace_word_size(expected_output)
Expand Down
Loading