Skip to content

Commit

Permalink
Remove AliasType#types? and guardrails for cyclic hierarchies
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Oct 8, 2024
1 parent 786b951 commit 7f7a1cb
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 45 deletions.
2 changes: 0 additions & 2 deletions src/compiler/crystal/codegen/link.cr
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ module Crystal

private def add_link_annotations(types, annotations)
types.try &.each_value do |type|
next if type.is_a?(AliasType) || type.is_a?(TypeDefType)

if type.is_a?(LibType) && type.used? && (link_annotations = type.link_annotations)
annotations.concat link_annotations
end
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/crystal/semantic/abstract_def_checker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class Crystal::AbstractDefChecker
end

def check_single(type)
return if @all_checked.includes?(type)
if @all_checked.includes?(type)
::raise "AbstractDefChecker duplicate: #{type} (#{type.class})"
return
end
@all_checked << type

if type.abstract? || type.module?
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/crystal/semantic/new.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ module Crystal
end

def define_default_new(type)
return if type.is_a?(AliasType) || type.is_a?(TypeDefType)

type.types?.try &.each_value do |type|
define_default_new_single(type)
end
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/crystal/semantic/recursive_struct_checker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class Crystal::RecursiveStructChecker

def check_single(type)
has_not_been_checked = @all_checked.add?(type)
return unless has_not_been_checked
unless has_not_been_checked
raise "RecursiveStructChecker duplicate: #{type} (#{type.class})"
return
end

if struct?(type)
target = type
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/crystal/semantic/type_declaration_processor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,10 @@ struct Crystal::TypeDeclarationProcessor
end

private def remove_duplicate_instance_vars_declarations(type : Type, duplicates_checked : Set(Type))
return unless duplicates_checked.add?(type)
unless duplicates_checked.add?(type)
raise "remove_duplicate_instance_vars_declarations duplicate: #{type} (#{type.class})"
return
end

# If a class has an instance variable that already exists in a superclass, remove it.
# Ideally we should process instance variables in a top-down fashion, but it's tricky
Expand Down
7 changes: 0 additions & 7 deletions src/compiler/crystal/tools/doc/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,6 @@ class Crystal::Doc::Generator
def collect_subtypes(parent)
types = [] of Type

# AliasType has defined `types?` to be the types
# of the aliased type, but for docs we don't want
# to list the nested types for aliases.
if parent.is_a?(AliasType)
return types
end

parent.types?.try &.each_value do |type|
case type
when Const, LibType
Expand Down
9 changes: 0 additions & 9 deletions src/compiler/crystal/tools/typed_def_processor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ module Crystal::TypedDefProcessor
end

private def process_type(type : Type) : Nil
# Avoid visiting circular hierarchies. There's no use in processing
# alias types anyway.
# For example:
#
# struct Foo
# alias Bar = Foo
# end
return if type.is_a?(AliasType) || type.is_a?(TypeDefType)

if type.is_a?(NamedType) || type.is_a?(Program) || type.is_a?(FileModule)
type.types?.try &.each_value do |inner_type|
process_type inner_type
Expand Down
9 changes: 0 additions & 9 deletions src/compiler/crystal/tools/unreachable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ module Crystal
property excludes = [] of String

def process_type(type)
# Avoid visiting circular hierarchies. There's no use in processing
# alias types anyway.
# For example:
#
# struct Foo
# alias Bar = Foo
# end
return if type.is_a?(AliasType) || type.is_a?(TypeDefType)

if type.is_a?(ModuleType)
track_unused_defs type
end
Expand Down
13 changes: 0 additions & 13 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2760,19 +2760,6 @@ module Crystal
delegate lookup_defs, lookup_defs_with_modules, lookup_first_def,
lookup_macro, lookup_macros, to: aliased_type

def types?
process_value
if aliased_type = @aliased_type
aliased_type.types?
else
nil
end
end

def types
types?.not_nil!
end

def lookup_name(name)
process_value
@aliased_type.try(&.lookup_name(name))
Expand Down

0 comments on commit 7f7a1cb

Please sign in to comment.