Skip to content
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ae85fd0
[mypyc] feat: support constant folding in `translate_index_expr`
BobTheBuidler Oct 2, 2025
621f95d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2025
c672af6
reject negatives
BobTheBuidler Oct 2, 2025
8f72b22
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2025
b7a1f41
Merge branch 'master' into constant-fold-translate-index
BobTheBuidler Oct 2, 2025
be7a4e9
length check for safety
BobTheBuidler Oct 2, 2025
37f39e7
support negative index
BobTheBuidler Oct 2, 2025
b5a2d1a
support negative index in TupleGet
BobTheBuidler Oct 2, 2025
fb5c2f4
Update ops.py
BobTheBuidler Oct 2, 2025
fad9daa
Update ops.py
BobTheBuidler Oct 2, 2025
7cdb1be
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2025
b231fb7
Update ops.py
BobTheBuidler Oct 2, 2025
d670522
Update ops.py
BobTheBuidler Oct 2, 2025
850484f
Update ops.py
BobTheBuidler Oct 2, 2025
0dae00f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2025
ada6dfb
Update expression.py
BobTheBuidler Oct 2, 2025
527f1e4
Merge branch 'master' into constant-fold-translate-index
BobTheBuidler Oct 2, 2025
d3c94af
Update run-strings.test
BobTheBuidler Oct 2, 2025
52837bb
Update run-strings.test
BobTheBuidler Oct 2, 2025
99b17cf
Merge branch 'master' into constant-fold-translate-index
BobTheBuidler Oct 4, 2025
d18c94b
Merge branch 'master' into constant-fold-translate-index
BobTheBuidler Oct 6, 2025
6216d42
Merge branch 'master' into constant-fold-translate-index
BobTheBuidler Oct 7, 2025
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
8 changes: 6 additions & 2 deletions mypyc/irbuild/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,12 @@ def transform_index_expr(builder: IRBuilder, expr: IndexExpr) -> Value:

base = builder.accept(expr.base, can_borrow=can_borrow_base)

if isinstance(base.type, RTuple) and isinstance(index, IntExpr):
return builder.add(TupleGet(base, index.value, expr.line))
if isinstance(base.type, RTuple):
folded_index = constant_fold_expr(builder, index)
if isinstance(folded_index, int):
length = len(base.type.types)
if -length <= folded_index <= length - 1:
return builder.add(TupleGet(base, folded_index, expr.line))

if isinstance(index, SliceExpr):
value = try_gen_slice_op(builder, base, index)
Expand Down