Skip to content

Commit be1a005

Browse files
authored
[mypyc] Try to fix mypy mac build failure on Python 3.5 on Travis (#9508)
We may be building a mixed 32/64-bit binary, so restrict the maximum integer literal to what's supported on a 32-bit platform, since the same C code needs to compile on both 32-bit and 64-bit architectures. This will make some slicing operations a bit slower in 32/64-bit mode (Python 3.5 on mac). Work on #9500.
1 parent 538d364 commit be1a005

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

mypyc/common.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
# Max short int we accept as a literal is based on 32-bit platforms,
2525
# so that we can just always emit the same code.
2626

27-
# Maximum value for a short tagged integer.
28-
#
29-
# Note: Assume that the compiled code uses the same bit width as mypyc.
30-
MAX_LITERAL_SHORT_INT = sys.maxsize >> 1 # type: Final
31-
3227
TOP_LEVEL_NAME = '__top_level__' # type: Final # Special function representing module top level
3328

3429
# Maximal number of subclasses for a class to trigger fast path in isinstance() checks.
@@ -38,6 +33,23 @@
3833

3934
PLATFORM_SIZE = 4 if IS_32_BIT_PLATFORM else 8
4035

36+
# Python 3.5 on macOS uses a hybrid 32/64-bit build that requires some workarounds.
37+
# The same generated C will be compiled in both 32 and 64 bit modes when building mypy
38+
# wheels (for an unknown reason).
39+
#
40+
# Note that we use "in ['darwin']" because of https://github.com/mypyc/mypyc/issues/761.
41+
IS_MIXED_32_64_BIT_BUILD = sys.platform in ['darwin'] and sys.version_info < (3, 6) # type: Final
42+
43+
# Maximum value for a short tagged integer.
44+
MAX_SHORT_INT = sys.maxsize >> 1 # type: Final
45+
46+
# Maximum value for a short tagged integer represented as a C integer literal.
47+
#
48+
# Note: Assume that the compiled code uses the same bit width as mypyc, except for
49+
# Python 3.5 on macOS.
50+
MAX_LITERAL_SHORT_INT = (sys.maxsize >> 1 if not IS_MIXED_32_64_BIT_BUILD
51+
else 2**30 - 1) # type: Final
52+
4153
# Runtime C library files
4254
RUNTIME_C_FILES = [
4355
'init.c',

mypyc/irbuild/expression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)
1616
from mypy.types import TupleType, get_proper_type, Instance
1717

18-
from mypyc.common import MAX_LITERAL_SHORT_INT
18+
from mypyc.common import MAX_SHORT_INT
1919
from mypyc.ir.ops import (
2020
Value, TupleGet, TupleSet, BasicBlock, Assign, LoadAddress
2121
)
@@ -373,7 +373,7 @@ def try_gen_slice_op(builder: IRBuilder, base: Value, index: SliceExpr) -> Optio
373373
else:
374374
# Replace missing end index with the largest short integer
375375
# (a sequence can't be longer).
376-
end = builder.load_static_int(MAX_LITERAL_SHORT_INT)
376+
end = builder.load_static_int(MAX_SHORT_INT)
377377
candidates = [list_slice_op, tuple_slice_op, str_slice_op]
378378
return builder.builder.matching_call_c(candidates, [base, begin, end], index.line)
379379

0 commit comments

Comments
 (0)