Skip to content

Commit

Permalink
Reduce calls to Crystal::Type#remove_indirection in module dispatch (
Browse files Browse the repository at this point in the history
…#14992)

Module types are expanded into unions during Crystal's codegen phase when the receiver of a call has a module type. This patch makes this expansion occur once for the entire call, instead of once for each including type.
  • Loading branch information
HertzDevil authored Sep 21, 2024
1 parent d184822 commit 5f018fc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/compiler/crystal/codegen/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ class Crystal::CodeGenVisitor

# Create self var if available
if node_obj
new_vars["%self"] = LLVMVar.new(@last, node_obj.type, true)
# call `#remove_indirection` here so that the downcast call in
# `#visit(Var)` doesn't spend time expanding module types again and again
# (it should be the only use site of `node_obj.type`)
new_vars["%self"] = LLVMVar.new(@last, node_obj.type.remove_indirection, true)
end

# Get type if of args and create arg vars
Expand All @@ -359,6 +362,10 @@ class Crystal::CodeGenVisitor

is_super = node.super?

# call `#remove_indirection` here so that the `match_type_id` below doesn't
# spend time expanding module types again and again
owner = owner.remove_indirection unless is_super

with_cloned_context do
context.vars = new_vars

Expand Down

0 comments on commit 5f018fc

Please sign in to comment.