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

Use type instead of is_a? in filters #10815

Merged
merged 3 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/cond.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Crystal::CodeGenVisitor

has_nil = union_types.any? &.nil_type?
has_bool = union_types.any? &.bool_type?
has_pointer = union_types.any? &.is_a?(PointerInstanceType)
has_pointer = union_types.any?(PointerInstanceType)

cond = llvm_true

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/llvm_id.cr
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module Crystal
end

private def subclasses_of(type)
type.subclasses.reject(&.is_a?(GenericInstanceType))
type.subclasses.reject(GenericInstanceType)
end
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module Crystal

class UnionType
def expand_union_types
if union_types.any?(&.is_a?(NonGenericModuleType))
if union_types.any?(NonGenericModuleType)
types = [] of Type
union_types.each &.append_to_expand_union_types(types)
types
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/cleanup_transformer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ module Crystal

def has_enum_type?(type)
if type.is_a?(UnionType)
type.union_types.any? &.is_a?(EnumType)
type.union_types.any?(EnumType)
else
type.is_a?(EnumType)
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/exhaustiveness_checker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct Crystal::ExhaustivenessChecker
# If we covered all types, we are done.
return if targets.empty?

if targets.all?(&.is_a?(TypeTarget)) && all_patterns_are_types
if targets.all?(TypeTarget) && all_patterns_are_types
node.raise <<-MSG
case is not exhaustive.

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/new.cr
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module Crystal
has_self_initialize_methods = !self_initialize_methods.empty?
if !has_self_initialize_methods
is_generic = type.is_a?(GenericClassType)
inherits_from_generic = type.ancestors.any?(&.is_a?(GenericClassInstanceType))
inherits_from_generic = type.ancestors.any?(GenericClassInstanceType)
if is_generic || inherits_from_generic
has_default_self_new = self_new_methods.any? do |a_def|
a_def.args.empty? && !a_def.yields
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/type_lookup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class Crystal::Type
end

begin
if instance_type.is_a?(GenericUnionType) && type_vars.any? &.is_a?(TypeSplat)
if instance_type.is_a?(GenericUnionType) && type_vars.any?(TypeSplat)
# In the case of `Union(*T)`, we don't need to instantiate the union right
# now because it will just return `*T`, but what we want to expand the
# union types only when the type is instantiated.
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/doc/type.cr
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class Crystal::Doc::Type
end

def type_to_html(type : Crystal::UnionType, io, text = nil, html : HTMLOption = :all)
has_type_splat = type.union_types.any? &.is_a?(TypeSplat)
has_type_splat = type.union_types.any?(TypeSplat)

if !has_type_splat && type.union_types.size == 2
if type.union_types[0].nil_type?
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/print_hierarchy.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module Crystal

compute_targets type.types, exp, false

subtypes = type.subclasses.select { |sub| !sub.is_a?(GenericClassInstanceType) }
subtypes = type.subclasses.reject(GenericClassInstanceType)
must_include |= compute_targets subtypes, exp, must_include
if must_include
@targets << type
Expand All @@ -75,7 +75,7 @@ module Crystal
compute_targets type.types, exp, false
compute_targets type.instantiated_types, exp, must_include

subtypes = type.subclasses.select { |sub| !sub.is_a?(GenericClassInstanceType) }
subtypes = type.subclasses.reject(GenericClassInstanceType)
must_include |= compute_targets subtypes, exp, must_include
if must_include
@targets << type
Expand Down
4 changes: 2 additions & 2 deletions src/indexable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ module Indexable(T)
{% if T == String %}
join_strings(separator)
{% elsif String < T %}
if all?(&.is_a?(String))
if all?(String)
join_strings(separator)
else
super(separator)
Expand All @@ -355,7 +355,7 @@ module Indexable(T)

each_with_index do |elem, i|
# elem is guaranteed to be a String, but the compiler doesn't know this
# if we enter via the all?(&.is_a?(String)) branch.
# if we enter via the all?(String) branch.
elem = elem.to_s

# Copy separator to buffer
Expand Down