Skip to content

Commit

Permalink
Remove useless assignments throughout the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Oct 23, 2022
1 parent ac2cad9 commit 2002461
Show file tree
Hide file tree
Showing 46 changed files with 53 additions and 98 deletions.
1 change: 0 additions & 1 deletion samples/binary-trees.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ stretch_depth = max_depth + 1
stretch_tree = bottom_up_tree(0, stretch_depth)

puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
stretch_tree = nil

long_lived_tree = bottom_up_tree(0, max_depth)

Expand Down
2 changes: 1 addition & 1 deletion samples/mt_gc_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Context
@threads_state.set(State::Wait)

# spin wait for threads to finish the round
while (c = @threads_reached.get) < @threads
while @threads_reached.get < @threads
end
log "All threads_reached!"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/parser/warnings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "../../support/syntax"
private def assert_parser_warning(source, message, *, file = __FILE__, line = __LINE__)
parser = Parser.new(source)
parser.filename = "/foo/bar/baz.cr"
node = parser.parse
parser.parse

warnings = parser.warnings.infos
warnings.size.should eq(1), file: file, line: line
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/semantic/class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe "Semantic: class" do
end

it "types generic of generic type" do
result = assert_type("
assert_type("
class Foo(T)
def set
@coco = 2
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/instance_var_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4367,7 +4367,7 @@ describe "Semantic: instance var" do
end

it "declares instance var of generic class" do
result = assert_type("
assert_type("
class Foo(T)
@x : T
Expand All @@ -4385,7 +4385,7 @@ describe "Semantic: instance var" do
end

it "declares instance var of generic class after reopen" do
result = assert_type("
assert_type("
class Foo(T)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/virtual_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ describe "Semantic: virtual" do
end

it "uses virtual type as generic type if class is abstract" do
result = assert_type("
assert_type("
abstract class Foo
end
Expand All @@ -619,7 +619,7 @@ describe "Semantic: virtual" do
end

it "uses virtual type as generic type if class is abstract even in union" do
result = assert_type("
assert_type("
abstract class Foo
end
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/warnings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe "Semantic: warnings" do
compiler.warnings.level = :all
compiler.warnings.exclude_lib_path = true
compiler.prelude = "empty"
result = compiler.compile Compiler::Source.new(main_filename, File.read(main_filename)), output_filename
compiler.compile Compiler::Source.new(main_filename, File.read(main_filename)), output_filename

compiler.warnings.infos.size.should eq(1)
end
Expand Down Expand Up @@ -399,7 +399,7 @@ describe "Semantic: warnings" do
compiler.warnings.level = :all
compiler.warnings.exclude_lib_path = true
compiler.prelude = "empty"
result = compiler.compile Compiler::Source.new(main_filename, File.read(main_filename)), output_filename
compiler.compile Compiler::Source.new(main_filename, File.read(main_filename)), output_filename

compiler.warnings.infos.size.should eq(1)
end
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ end
def assert_normalize(from, to, flags = nil, *, file = __FILE__, line = __LINE__)
program = new_program
program.flags.concat(flags.split) if flags
normalizer = Normalizer.new(program)
from_nodes = Parser.parse(from)
to_nodes = program.normalize(from_nodes)
to_nodes.to_s.strip.should eq(to.strip), file: file, line: line
Expand Down
4 changes: 2 additions & 2 deletions spec/std/hash_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ describe "Hash" do
it { {"a" => 2, "b" => 3}.reject(["b", "a"]).should eq({} of String => Int32) }
it "does not change current hash" do
h = {"a" => 3, "b" => 6, "c" => 9}
h2 = h.reject("b", "c")
h.reject("b", "c")
h.should eq({"a" => 3, "b" => 6, "c" => 9})
end
end
Expand All @@ -1282,7 +1282,7 @@ describe "Hash" do
it { {"a" => 2, "b" => 3}.select(Set{"b", "a"}).should eq({"a" => 2, "b" => 3}) }
it "does not change current hash" do
h = {"a" => 3, "b" => 6, "c" => 9}
h2 = h.select("b", "c")
h.select("b", "c")
h.should eq({"a" => 3, "b" => 6, "c" => 9})
end
end
Expand Down
2 changes: 0 additions & 2 deletions spec/std/http/client/client_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ module HTTP

it "will not retry when closed (non-block) (#12464)" do
requests = 0
server_channel = Channel(Nil).new

client = HTTP::Client.new("127.0.0.1", 0)
client.before_request do
Expand All @@ -256,7 +255,6 @@ module HTTP

it "will not retry when closed (block) (#12464)" do
requests = 0
server_channel = Channel(Nil).new

client = HTTP::Client.new("127.0.0.1", 0)
client.before_request do
Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/headers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe HTTP::Headers do

it "raises an error if header value contains invalid character" do
expect_raises ArgumentError do
headers = HTTP::Headers{"invalid-header" => "\r\nLocation: http://example.com"}
HTTP::Headers{"invalid-header" => "\r\nLocation: http://example.com"}
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/std/log/context_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe Log do
Log.context.set a: 1
done = Channel(Nil).new

f = spawn do
spawn do
Log.context.metadata.should eq(Log::Metadata.new)
Log.context.set b: 2
Log.context.metadata.should eq(m({b: 2}))
Expand Down
10 changes: 5 additions & 5 deletions spec/std/log/dispatch_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Log
it "dispatches entry" do
backend = Log::MemoryBackend.new
backend.dispatcher = DirectDispatcher
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.entries.size.should eq(1)
end
end
Expand All @@ -24,7 +24,7 @@ class Log
it "dispatches entry" do
backend = Log::MemoryBackend.new
backend.dispatcher = SyncDispatcher.new
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.entries.size.should eq(1)
end
end
Expand All @@ -33,22 +33,22 @@ class Log
it "dispatches entry" do
backend = Log::MemoryBackend.new
backend.dispatcher = AsyncDispatcher.new
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
retry { backend.entries.size.should eq(1) }
end

it "wait for entries to flush before closing" do
backend = Log::MemoryBackend.new
backend.dispatcher = AsyncDispatcher.new
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.close
backend.entries.size.should eq(1)
end

it "can be closed twice" do
backend = Log::MemoryBackend.new
backend.dispatcher = AsyncDispatcher.new
backend.dispatch entry = Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.dispatch Entry.new("source", :info, "message", Log::Metadata.empty, nil)
backend.close
backend.close
backend.entries.size.should eq(1)
Expand Down
4 changes: 2 additions & 2 deletions spec/std/oauth2/session_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module OAuth2
typeof(begin
client = Client.new "localhost", "client_id", "client_secret", redirect_uri: "uri", authorize_uri: "/baz"
token = OAuth2::AccessToken::Bearer.new("token", 3600)
session = Session.new(client, token) { |s| }
session = Session.new(client, token, Time.utc) { |s| }
session = Session.new(client, token) { |_| }
session = Session.new(client, token, Time.utc) { |_| }
session.authenticate(HTTP::Client.new("localhost"))
end)
end
2 changes: 0 additions & 2 deletions spec/std/proc_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ describe "Proc" do
end

it "does to_s" do
str = IO::Memory.new
f = ->(x : Int32) { x.to_f }
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}>")
end

it "does to_s when closured" do
str = IO::Memory.new
a = 1.5
f = ->(x : Int32) { x + a }
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}:closure>")
Expand Down
2 changes: 1 addition & 1 deletion spec/std/socket/tcp_socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe TCPSocket, tags: "network" do

TCPServer.open("localhost", port) do |server|
TCPSocket.open("localhost", port) do |client|
sock = server.accept
server.accept
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ describe "String" do
end

it "subs char with string" do
replaced = "foobar".sub do |char|
"foobar".sub do |char|
char.should eq 'f'
"some"
end.should eq("someoobar")
Expand Down
1 change: 0 additions & 1 deletion src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,6 @@ module Crystal
end

# First accept all yield expressions and assign them to block vars
i = 0
unless node.exps.empty?
exp_values = Array({LLVM::Value, Type}).new(node.exps.size)

Expand Down
3 changes: 0 additions & 3 deletions src/compiler/crystal/codegen/fun.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class Crystal::CodeGenVisitor
func.varargs?
)

p2 = new_fun.params.to_a

func.params.to_a.each_with_index do |p1, index|
attrs = new_fun.attributes(index + 1)
new_fun.add_attribute(attrs, index + 1) unless attrs.value == 0
Expand Down Expand Up @@ -125,7 +123,6 @@ class Crystal::CodeGenVisitor

if @debug.variables? && !target_def.naked?
in_alloca_block do
args_offset = !is_fun_literal && self_type.passed_as_self? ? 2 : 1
location = target_def.location
context.vars.each do |name, var|
next if var.debug_variable_created
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Crystal::Command

output_filename = Crystal.temp_executable(config.output_filename)

result = config.compile output_filename
config.compile output_filename

unless config.compiler.no_codegen?
report_warnings
Expand Down
15 changes: 7 additions & 8 deletions src/compiler/crystal/command/cursor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,30 @@
class Crystal::Command
private def implementations
cursor_command("tool implementations") do |location, config, result|
result = ImplementationsVisitor.new(location).process(result)
ImplementationsVisitor.new(location).process(result)
end
end

private def context
cursor_command("tool context") do |location, config, result|
result = ContextVisitor.new(location).process(result)
ContextVisitor.new(location).process(result)
end
end

private def expand
cursor_command("tool expand", no_cleanup: true, wants_doc: true) do |location, config, result|
result = ExpandVisitor.new(location).process(result)
ExpandVisitor.new(location).process(result)
end
end

private def cursor_command(command, no_cleanup = false, wants_doc = false)
config, result = compile_no_codegen command, cursor_command: true, no_cleanup: no_cleanup, wants_doc: wants_doc
config, result = compile_no_codegen command,
cursor_command: true,
no_cleanup: no_cleanup,
wants_doc: wants_doc

format = config.output_format

file = ""
line = ""
col = ""

loc = config.cursor_location.not_nil!.split(':')
if loc.size != 3
error "cursor location must be file:line:column"
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/command/repl.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Crystal::Command
private def repl
repl = Repl.new

option_parser = parse_with_crystal_opts do |opts|
parse_with_crystal_opts do |opts|
opts.banner = "Usage: crystal i [options] [programfile] [arguments]\n\nOptions:"

opts.on("-D FLAG", "--define FLAG", "Define a compile-time flag") do |flag|
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/command/spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Crystal::Command
output_filename = Crystal.temp_executable "spec"

ENV["CRYSTAL_SPEC_COMPILER_BIN"] ||= Process.executable_path
result = compiler.compile sources, output_filename
compiler.compile sources, output_filename
report_warnings
execute output_filename, options, compiler, error_on_exit: warnings_fail_on_exit?
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ module Crystal
source_slice = source.lines[from_index...to_index]
source_slice, spaces_removed = minimize_indentation(source_slice)

io << Crystal.with_line_numbers(source_slice, line_number, @color, line_number_start = from_index + 1)
io << Crystal.with_line_numbers(source_slice, line_number, @color, from_index + 1)
offset = OFFSET_FROM_LINE_NUMBER_DECORATOR + line_number.to_s.chars.size - spaces_removed
append_error_indicator(io, offset, @column_number, @size)
end
Expand Down
10 changes: 2 additions & 8 deletions src/compiler/crystal/interpreter/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ class Crystal::Repl::Compiler < Crystal::Visitor
end

private def read_closured_var_pointer(closured_var : ClosuredVar, *, node : ASTNode?)
indexes, type = closured_var.indexes, closured_var.type
indexes = closured_var.indexes

# First load the closure pointer
closure_var_index = get_closure_var_index
Expand Down Expand Up @@ -2474,9 +2474,6 @@ class Crystal::Repl::Compiler < Crystal::Visitor
# We don't want pointer.value to return a copy of something
# if we are calling through it
call_obj = call_obj.not_nil!

element_type = call_obj.type.as(PointerInstanceType).element_type

request_value(call_obj)
return
end
Expand Down Expand Up @@ -2687,8 +2684,7 @@ class Crystal::Repl::Compiler < Crystal::Visitor
local_var = lookup_local_var_or_closured_var(exp.name)
case local_var
in LocalVar
index, type = local_var.index, local_var.type
pointerof_var(index, node: node)
pointerof_var(local_var.index, node: node)
in ClosuredVar
node.raise "BUG: missing interpreter out closured var"
end
Expand Down Expand Up @@ -2754,8 +2750,6 @@ class Crystal::Repl::Compiler < Crystal::Visitor
compiled_def.local_vars.declare(arg.name, var_type)
end

a_def = @def

needs_closure_context = (target_def.vars.try &.any? { |name, var| var.type? && var.closure_in?(target_def) })

# Declare the closure context arg and var, if any
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/macros/methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,7 @@ private def interpret_array_or_tuple_method(object, klass, method, args, named_a
case arg = from
when Crystal::NumberLiteral
index = arg.to_number.to_i
value = object.elements[index]? || Crystal::NilLiteral.new
object.elements[index]? || Crystal::NilLiteral.new
when Crystal::RangeLiteral
range = arg.interpret_to_nilable_range(interpreter)
begin
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/program.cr
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ module Crystal

types["NoReturn"] = @no_return = NoReturnType.new self, self, "NoReturn"
types["Void"] = @void = VoidType.new self, self, "Void"
types["Nil"] = nil_t = @nil = NilType.new self, self, "Nil", value, 1
types["Nil"] = @nil = NilType.new self, self, "Nil", value, 1
types["Bool"] = @bool = BoolType.new self, self, "Bool", value, 1
types["Char"] = @char = CharType.new self, self, "Char", value, 4

Expand Down
1 change: 0 additions & 1 deletion src/compiler/crystal/semantic/ast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ module Crystal
# bind all previously related local vars to it so that
# they get all types assigned to it.
local_vars.each &.bind_to self
local_vars = nil
end

# True if this variable belongs to the given context
Expand Down
Loading

0 comments on commit 2002461

Please sign in to comment.