Skip to content

Commit

Permalink
Style: Remove explicit returns from the codebase (#12637)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspiano authored Nov 12, 2022
1 parent 6edc9e3 commit 18fd4c3
Show file tree
Hide file tree
Showing 40 changed files with 77 additions and 82 deletions.
2 changes: 1 addition & 1 deletion samples/spectral-norm.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copied with little modifications from: https://github.com/wmoxam/Ruby-Benchmarks-Game/blob/master/benchmarks/spectral-norm.rb

def eval_A(i, j)
return 1.0_f64 / ((i + j) * (i + j + 1.0) / 2.0 + i + 1.0)
1.0_f64 / ((i + j) * (i + j + 1.0) / 2.0 + i + 1.0)
end

def eval_A_times_u(u)
Expand Down
2 changes: 1 addition & 1 deletion src/bit_array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct BitArray
# NOTE: If BitArray implements resizing, there may be more than 1 binary
# representation and their hashes for equivalent BitArrays after a downsize as the
# discarded bits may not have been zeroed.
return LibC.memcmp(@bits, other.@bits, bytesize) == 0
LibC.memcmp(@bits, other.@bits, bytesize) == 0
end

def unsafe_fetch(index : Int) : Bool
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ class Crystal::CodeGenVisitor

@last = self_type.passed_as_self? ? call_args.first : type_id(self_type)
inline_call_return_value target_def, body
return true
true
else
false
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/class_var.cr
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Crystal::CodeGenVisitor
global_name = class_var_global_name(class_var)
global = get_global global_name, class_var.type, class_var
global = ensure_class_var_in_this_module(global, class_var)
return global
global
end

def read_virtual_class_var_ptr(class_var, owner)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/match.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Crystal::CodeGenVisitor
match_fun_name = "~match<#{type}>"
func = @main_mod.functions[match_fun_name]? || create_match_fun(match_fun_name, type)
func = check_main_fun match_fun_name, func
return call func, [type_id] of LLVM::Value
call func, [type_id] of LLVM::Value
end

private def create_match_fun(name, type)
Expand Down
18 changes: 9 additions & 9 deletions src/compiler/crystal/codegen/primitives.cr
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ class Crystal::CodeGenVisitor

def codegen_binary_op(op, t1 : CharType, t2 : CharType, p1, p2)
case op
when "==" then return builder.icmp LLVM::IntPredicate::EQ, p1, p2
when "!=" then return builder.icmp LLVM::IntPredicate::NE, p1, p2
when "<" then return builder.icmp LLVM::IntPredicate::ULT, p1, p2
when "<=" then return builder.icmp LLVM::IntPredicate::ULE, p1, p2
when ">" then return builder.icmp LLVM::IntPredicate::UGT, p1, p2
when ">=" then return builder.icmp LLVM::IntPredicate::UGE, p1, p2
when "==" then builder.icmp LLVM::IntPredicate::EQ, p1, p2
when "!=" then builder.icmp LLVM::IntPredicate::NE, p1, p2
when "<" then builder.icmp LLVM::IntPredicate::ULT, p1, p2
when "<=" then builder.icmp LLVM::IntPredicate::ULE, p1, p2
when ">" then builder.icmp LLVM::IntPredicate::UGT, p1, p2
when ">=" then builder.icmp LLVM::IntPredicate::UGE, p1, p2
else raise "BUG: trying to codegen #{t1} #{op} #{t2}"
end
end

def codegen_binary_op(op, t1 : SymbolType, t2 : SymbolType, p1, p2)
case op
when "==" then return builder.icmp LLVM::IntPredicate::EQ, p1, p2
when "!=" then return builder.icmp LLVM::IntPredicate::NE, p1, p2
when "==" then builder.icmp LLVM::IntPredicate::EQ, p1, p2
when "!=" then builder.icmp LLVM::IntPredicate::NE, p1, p2
else raise "BUG: trying to codegen #{t1} #{op} #{t2}"
end
end
Expand Down Expand Up @@ -203,7 +203,7 @@ class Crystal::CodeGenVisitor
)
codegen_raise_overflow_cond overflow

return codegen_binary_op_with_overflow("*", t1, @program.int_type(false, t2.bytes), p1, p2)
codegen_binary_op_with_overflow("*", t1, @program.int_type(false, t2.bytes), p1, p2)
end

def codegen_mul_signed_unsigned_with_overflow(t1, t2, p1, p2)
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/crystal/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ module Crystal
if filename.is_a? VirtualFile
loc = filename.expanded_location
if loc
return true_filename loc.filename
true_filename loc.filename
else
return ""
""
end
else
if filename
return filename
filename
else
return ""
""
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/interpreter/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ class Crystal::Repl::Compiler < Crystal::Visitor
pop aligned_sizeof_type(node), node: nil
end

return false
false
end

private def create_compiled_def(node : Call, target_def : Def)
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/macros/methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ module Crystal

def to_string(context)
case self
when StringLiteral then return self.value
when SymbolLiteral then return self.value
when MacroId then return self.value
when StringLiteral then self.value
when SymbolLiteral then self.value
when MacroId then self.value
else
raise "expected #{context} to be a StringLiteral, SymbolLiteral or MacroId, not #{class_desc}"
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class Crystal::Call
if index || nilable
indexer_def = yield instance_type, (index || -1)
indexer_match = Match.new(indexer_def, arg_types, MatchContext.new(owner, owner))
return Matches.new(ZeroOneOrMany(Match).new(indexer_match), true)
Matches.new(ZeroOneOrMany(Match).new(indexer_match), true)
else
raise "missing key '#{name}' for named tuple #{owner}"
end
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/semantic/filters.cr
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ module Crystal

case other
when NilType
return nil
nil
when UnionType
return Type.merge(other.union_types.reject &.nil_type?)
Type.merge(other.union_types.reject &.nil_type?)
else
other
end
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,8 @@ module Crystal
expansion.accept self
node.expanded = expansion
node.bind_to(expanded)
return false

false
end

# If it's a super or previous_def call inside an initialize we treat
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/restrictions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ module Crystal

restricted = typedef.restrict(other, context)
if restricted == typedef
return self
self
elsif restricted.is_a?(UnionType)
program.type_merge(restricted.union_types.map { |t| t == typedef ? self : t })
else
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/type_intersect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module Crystal

restricted = common_descendent(type1.typedef, type2)
if restricted == type1.typedef
return type1
type1
elsif restricted.is_a?(UnionType)
type1.program.type_merge(restricted.union_types.map { |t| t == type1.typedef ? type1 : t })
else
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3446,7 +3446,7 @@ module Crystal
end

a_then, a_else = a_else, a_then if is_unless
return MacroIf.new(cond, a_then, a_else).at_end(token_end_location)
MacroIf.new(cond, a_then, a_else).at_end(token_end_location)
end

def parse_expression_inside_macro
Expand Down Expand Up @@ -4669,7 +4669,7 @@ module Crystal
else
skip_space
end
return CallArgs.new args, nil, nil, named_args, false, end_location, has_parentheses: allow_newline
CallArgs.new args, nil, nil, named_args, false, end_location, has_parentheses: allow_newline
end

def parse_named_args(location, first_name = nil, allow_newline = false)
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/tools/context.cr
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ module Crystal

if @contexts.empty?
if @found_untyped_def
return ContextResult.new("failed", "no context information found (methods which are never called don't have a context)")
ContextResult.new("failed", "no context information found (methods which are never called don't have a context)")
else
return ContextResult.new("failed", "no context information found")
ContextResult.new("failed", "no context information found")
end
else
res = ContextResult.new("ok", "#{@contexts.size} possible context#{@contexts.size > 1 ? "s" : ""} found")
res.contexts = @contexts
return res
res
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/expand.cr
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ module Crystal
result.node.accept(self)

if @found_nodes.empty?
return ExpandResult.new("failed", @message)
ExpandResult.new("failed", @message)
else
res = ExpandResult.new("ok", "#{@found_nodes.size} expansion#{@found_nodes.size > 1 ? "s" : ""} found")
res.expansions = @found_nodes.map { |node| ExpandResult::Expansion.build(node) }
return res
res
end
end

Expand Down
17 changes: 7 additions & 10 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ module Crystal
write_indent
write "end"
next_token
return false
false
end

def visit(node : MacroLiteral)
Expand Down Expand Up @@ -3479,18 +3479,15 @@ module Crystal
skip_semicolon_or_space_or_newline
check_end
write "; end"
next_token
return false
else
skip_space_or_newline
check_end
write_line
write_indent
write "end"
next_token
return false
end

next_token
false
end

Expand Down Expand Up @@ -4309,25 +4306,25 @@ module Crystal

def visit(node : Block)
# Handled in format_block
return false
false
end

def visit(node : When)
# Handled in format_when
return false
false
end

def visit(node : Rescue)
# Handled in visit(node : ExceptionHandler)
return false
false
end

def visit(node : MacroId)
return false
false
end

def visit(node : MetaVar)
return false
false
end

def visit(node : Asm)
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/crystal/tools/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module Crystal::Git
# Tries to run git command with args.
# Yields block if exec fails or process status is not success.
def self.git_command(args, output : Process::Stdio = Process::Redirect::Close)
status = Process.run(executable, args, output: output)
return status.success?
Process.run(executable, args, output: output).success?
rescue IO::Error
false
end
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/implementations.cr
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ module Crystal
result.node.accept(self)

if @locations.empty?
return ImplementationResult.new("failed", "no implementations or method call found")
ImplementationResult.new("failed", "no implementations or method call found")
else
res = ImplementationResult.new("ok", "#{@locations.size} implementation#{@locations.size > 1 ? "s" : ""} found")
res.implementations = @locations.map { |loc| ImplementationTrace.build(loc) }
return res
res
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/unix/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module Crystal::System::File
::File::Info.new(stat)
else
if Errno.value.in?(Errno::ENOENT, Errno::ENOTDIR)
return nil
nil
else
raise ::File::Error.from_errno("Unable to get file info", file: path)
end
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/unix/socket.cr
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module Crystal::System::Socket
end

if Errno.value == Errno::ENOPROTOOPT
return false
false
else
raise ::Socket::Error.from_errno("getsockopt")
end
Expand Down
8 changes: 4 additions & 4 deletions src/crystal/system/win32/dir.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ module Crystal::System::Dir
handle = LibC.FindFirstFileW(dir.query, out data)
if handle != LibC::INVALID_HANDLE_VALUE
dir.handle = handle
return data_to_entry(data)
data_to_entry(data)
else
error = WinError.value
if error == WinError::ERROR_FILE_NOT_FOUND
return nil
nil
else
raise ::File::Error.from_os_error("Error reading directory entries", error, file: path)
end
end
else
# Use FindNextFile
if LibC.FindNextFileW(dir.handle, out data_) != 0
return data_to_entry(data_)
data_to_entry(data_)
else
error = WinError.value
if error == WinError::ERROR_NO_MORE_FILES
return nil
nil
else
raise ::File::Error.from_os_error("Error reading directory entries", error, file: path)
end
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/win32/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module Crystal::System::File
private def self.check_not_found_error(message, path)
error = WinError.value
if NOT_FOUND_ERRORS.includes? error
return nil
nil
else
raise ::File::Error.from_os_error(message, error, file: path)
end
Expand Down
2 changes: 1 addition & 1 deletion src/env.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module ENV
# the *key* does not exist.
def self.fetch(key : String, &block : String -> T) : String | T forall T
if value = Crystal::System::Env.get(key)
return value
value
else
yield key
end
Expand Down
2 changes: 1 addition & 1 deletion src/float/printer/grisu3.cr
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module Float::Printer::Grisu3
# Since too_low = too_high - unsafe_interval this is equivalent to
# [too_high - unsafe_interval + 4 ulp; too_high - 2 ulp]
# Conceptually we have: rest ~= too_high - buffer
return (2 &* unit <= rest) && (rest <= unsafe_interval &- 4 &* unit)
(2 &* unit <= rest) && (rest <= unsafe_interval &- 4 &* unit)
end

# Generates the digits of input number *w*.
Expand Down
4 changes: 2 additions & 2 deletions src/float/printer/ieee.cr
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module Float::Printer::IEEE
{(w.frac << 1) - 1, w.exp - 1}
end
m_minus = DiyFP.new(f << (e - m_plus.exp), m_plus.exp)
return {minus: m_minus, plus: m_plus}
{minus: m_minus, plus: m_plus}
end

def normalized_boundaries(v : Float32) : {minus: DiyFP, plus: DiyFP}
Expand All @@ -137,7 +137,7 @@ module Float::Printer::IEEE
{(w.frac << 1) - 1, w.exp - 1}
end
m_minus = DiyFP.new(f << (e - m_plus.exp), m_plus.exp)
return {minus: m_minus, plus: m_plus}
{minus: m_minus, plus: m_plus}
end

def frac_and_exp(v : Float64) : {UInt64, Int32}
Expand Down
Loading

0 comments on commit 18fd4c3

Please sign in to comment.