Skip to content

Commit adae39f

Browse files
Update expression.py
1 parent 377b31e commit adae39f

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed

mypyc/irbuild/expression.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
)
8484
from mypyc.irbuild.ast_helpers import is_borrow_friendly_expr, process_conditional
8585
from mypyc.irbuild.builder import IRBuilder, int_borrow_friendly_op
86-
from mypyc.irbuild.constant_fold import constant_fold_expr
86+
from mypyc.irbuild.constant_fold import constant_fold_expr, folding_candidate, try_constant_fold
8787
from mypyc.irbuild.for_helpers import (
8888
comprehension_helper,
8989
raise_error_if_contains_unreachable_names,
@@ -113,9 +113,6 @@
113113
from mypyc.primitives.str_ops import str_slice_op
114114
from mypyc.primitives.tuple_ops import list_tuple_op, tuple_slice_op
115115

116-
TransformFunc = Callable[[IRBuilder, Expression], Value | None]
117-
118-
119116
# Name and attribute references
120117

121118

@@ -605,30 +602,6 @@ def transform_index_expr(builder: IRBuilder, expr: IndexExpr) -> Value:
605602
)
606603

607604

608-
def try_constant_fold(builder: IRBuilder, expr: Expression) -> Value | None:
609-
"""Return the constant value of an expression if possible.
610-
611-
Return None otherwise.
612-
"""
613-
value = constant_fold_expr(builder, expr)
614-
if value is not None:
615-
return builder.load_literal_value(value)
616-
return None
617-
618-
619-
def folding_candidate(transform: TransformFunc) -> TransformFunc:
620-
"""Mark a transform function as a candidate for constant folding.
621-
622-
Candidate functions will attempt to short-circuit the transformation
623-
by constant folding the expression and will only proceed to transform
624-
the expression if folding is not possible.
625-
"""
626-
def constant_fold_wrap(builder: IRBuilder, expr: Expression) -> Value | None:
627-
folded = try_constant_fold(builder, expr)
628-
return folded if folded is not None else transform(builder, expr)
629-
return constant_fold_wrap
630-
631-
632605
def try_gen_slice_op(builder: IRBuilder, base: Value, index: SliceExpr) -> Value | None:
633606
"""Generate specialized slice op for some index expressions.
634607

0 commit comments

Comments
 (0)