Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler refactor: extract type_from_dependencies #12437

Merged
merged 2 commits into from
Sep 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/compiler/crystal/semantic/bindings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,19 @@ module Crystal
@type
end

def bind_to(node : ASTNode)
def bind_to(node : ASTNode) : Nil
bind(node) do |dependencies|
dependencies.push node
node.add_observer self
node
end
end

def bind_to(nodes : Indexable)
def bind_to(nodes : Indexable) : Nil
return if nodes.empty?

bind do |dependencies|
dependencies.concat nodes
nodes.each &.add_observer self
nodes.first
end
end

Expand All @@ -134,13 +132,9 @@ module Crystal

dependencies = @dependencies ||= [] of ASTNode

node = yield dependencies
yield dependencies

if dependencies.size == 1
new_type = node.type?
else
new_type = Type.merge dependencies
end
new_type = type_from_dependencies
new_type = map_type(new_type) if new_type

if new_type && (freeze_type = self.freeze_type)
Expand All @@ -155,6 +149,10 @@ module Crystal
propagate
end

def type_from_dependencies : Type?
Type.merge dependencies
end

def unbind_from(nodes : Nil)
# Nothing to do
end
Expand Down Expand Up @@ -206,7 +204,7 @@ module Crystal
def update(from = nil)
return if @type && @type.same? from.try &.type?

new_type = Type.merge dependencies
new_type = type_from_dependencies
new_type = map_type(new_type) if new_type

if new_type && (freeze_type = self.freeze_type)
Expand Down