Skip to content

Commit

Permalink
Do not load Path call receiver if known to be unused
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Feb 18, 2025
1 parent 9b7fd8d commit 42855f9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/compiler/crystal/codegen/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ class Crystal::CodeGenVisitor

obj = node.obj

# Always accept obj: even if it's not passed as self this might
# involve intermediate calls with side effects.
if obj
case obj
when Path
# Non-generic metaclasses and lib types do not need a self argument,
# reading them should not have side effects unless `obj` turns out to be
# a constant with an initializer (e.g. `A = (puts 1; Int32)` has a side
# effect).
if obj.type.passed_as_self? || obj.target_const
request_value(obj)
end
when ASTNode
# Always accept obj: even if it's not passed as self this might
# involve intermediate calls with side effects.
request_value(obj)
end

Expand Down

0 comments on commit 42855f9

Please sign in to comment.