Skip to content

Improve trimmability of string interpolation - #62844

Open
timholy wants to merge 1 commit into
masterfrom
teh/trim_safe_string
Open

Improve trimmability of string interpolation#62844
timholy wants to merge 1 commit into
masterfrom
teh/trim_safe_string

Conversation

@timholy

@timholy timholy commented Aug 21, 2026

Copy link
Copy Markdown
Member

The vararg methods print(io, xs...), print_to_string and string_with_env printed their arguments with for x in xs. That loop variable is a phi node merging the type of the first element with the union of the rest, and inference widens such a union to Any once it has more than three members, so every print(io, x) in the loop became a dynamic dispatch. Under juliac --trim=safe, which compiles these methods for their exact argument types, any interpolated string whose arguments spanned more than three distinct types was rejected as an unresolved call, e.g. "got $(r) vs $(i) with $(x) and $(s)".

Indexing the tuple instead (xs[i]) keeps the exact union of element types, which union-splits into statically resolved calls regardless of how many members it has.

This helps only for exact unions; Vararg{Any} is still not trimmable.

Assisted-by: Claude Code (Fable 5)

The vararg methods `print(io, xs...)`, `print_to_string` and
`string_with_env` printed their arguments with `for x in xs`. That loop
variable is a phi node merging the type of the first element with the
union of the rest, and inference widens such a union to `Any` once it
has more than three members, so every `print(io, x)` in the loop became
a dynamic dispatch. Under `juliac --trim=safe`, which compiles these
methods for their exact argument types, any interpolated string whose
arguments spanned more than three distinct types was rejected as an
unresolved call, e.g. `"got $(r) vs $(i) with $(x) and $(s)"`.

Indexing the tuple instead (`xs[i]`) keeps the exact union of element
types, which union-splits into statically resolved calls regardless of
how many members it has.

This helps only for exact unions; `Vararg{Any}` is still not trimmable.

Assisted-by: Claude Code (Fable 5)
@timholy timholy added compiler:inference Type inference trimming Issues with trimming functionality or PR's relevant to its performance/functionality backport 1.13 Change should be backported to release-1.13 labels Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.13 Change should be backported to release-1.13 compiler:inference Type inference trimming Issues with trimming functionality or PR's relevant to its performance/functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant