Skip to content

Commit 4335273

Browse files
committed
feat: propagate length of final strings
1 parent 71cda45 commit 4335273

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mypyc/irbuild/for_helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
StrExpr,
2727
TupleExpr,
2828
TypeAlias,
29+
Var,
2930
)
3031
from mypyc.ir.ops import (
3132
ERR_NEVER,
@@ -1202,6 +1203,14 @@ def get_expr_length(expr: Expression) -> int | None:
12021203
elif isinstance(expr, StarExpr):
12031204
# star expression needs some extra logic but that can come later, this is good for now
12041205
return get_expr_length(expr.expr)
1206+
elif (
1207+
isinstance(expr, RefExpr)
1208+
and isinstance(expr.node, Var)
1209+
and expr.node.is_final
1210+
and isinstance(expr.node.final_value, str)
1211+
and expr.node.has_explicit_value
1212+
):
1213+
return len(expr.node.final_value)
12051214
# TODO: extend this, unrolling should come with a good performance boost
12061215
return None
12071216

0 commit comments

Comments
 (0)