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

Exhaustive case near and far #9656

Merged
merged 3 commits into from
Oct 30, 2020
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: 0 additions & 2 deletions samples/llvm/brainfuck.cr
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ class Program
open_count += 1
when ']'
open_count -= 1
else
# go on
end

if open_count == 0
Expand Down
6 changes: 0 additions & 6 deletions samples/sdl/fire.cr
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,6 @@ while true
speed_down[3] = true
when LibSDL::Key::L
turn_right[3] = true
else
# ignore
end
when LibSDL::KEYUP
case event.key.key_sym.sym
Expand Down Expand Up @@ -423,11 +421,7 @@ while true
speed_down[3] = false
when LibSDL::Key::L
turn_right[3] = false
else
# ignore
end
else
# ignore
end
end

Expand Down
54 changes: 24 additions & 30 deletions src/channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ class Channel(T)
@lock.lock

case send_internal(value)
when DeliveryState::Delivered
in .delivered?
@lock.unlock
when DeliveryState::Closed
in .closed?
@lock.unlock
raise ClosedError.new
else
in .none?
sender.fiber = Fiber.current
sender.data = value
@senders.push pointerof(sender)
Expand All @@ -234,11 +234,11 @@ class Channel(T)
Crystal::Scheduler.reschedule

case sender.state
when DeliveryState::Delivered
in .delivered?
# ignore
when DeliveryState::Closed
in .closed?
raise ClosedError.new
else
in .none?
raise "BUG: Fiber was awaken without channel delivery state set"
end
end
Expand Down Expand Up @@ -296,26 +296,26 @@ class Channel(T)
state, value = receive_internal

case state
when DeliveryState::Delivered
in .delivered?
@lock.unlock
raise "BUG: Unexpected UseDefault value for delivered receive" if value.is_a?(UseDefault)
value
when DeliveryState::Closed
in .closed?
@lock.unlock
yield
else
in .none?
receiver.fiber = Fiber.current
@receivers.push pointerof(receiver)
@lock.unlock

Crystal::Scheduler.reschedule

case receiver.state
when DeliveryState::Delivered
in .delivered?
receiver.data
when DeliveryState::Closed
in .closed?
yield
else
in .none?
raise "BUG: Fiber was awaken without channel delivery state set"
end
end
Expand Down Expand Up @@ -434,13 +434,13 @@ class Channel(T)
state = op.execute

case state
when DeliveryState::Delivered
in .delivered?
ops_locks.each &.unlock
return index, op.result
when DeliveryState::Closed
in .closed?
ops_locks.each &.unlock
return index, op.default_result
else
in .none?
# do nothing
end
end
Expand Down Expand Up @@ -520,14 +520,12 @@ class Channel(T)

def wait_result_impl(context : SelectContext(T))
case @receiver.state
when DeliveryState::Delivered
in .delivered?
context.action.result
when DeliveryState::Closed
in .closed?
raise ClosedError.new
when DeliveryState::None
in .none?
raise "BUG: StrictReceiveAction.wait_result_impl called with DeliveryState::None"
else
raise "unreachable"
end
end

Expand Down Expand Up @@ -584,14 +582,12 @@ class Channel(T)

def wait_result_impl(context : SelectContext(T))
case @receiver.state
when DeliveryState::Delivered
in .delivered?
context.action.result
when DeliveryState::Closed
in .closed?
nil
when DeliveryState::None
in .none?
raise "BUG: LooseReceiveAction.wait_result_impl called with DeliveryState::None"
else
raise "unreachable"
end
end

Expand Down Expand Up @@ -643,14 +639,12 @@ class Channel(T)

def wait_result_impl(context : SelectContext(Nil))
case @sender.state
when DeliveryState::Delivered
in .delivered?
context.action.result
when DeliveryState::Closed
in .closed?
raise ClosedError.new
when DeliveryState::None
in .none?
raise "BUG: SendAction.wait_result_impl called with DeliveryState::None"
else
raise "unreachable"
end
end

Expand Down
2 changes: 0 additions & 2 deletions src/char.cr
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,6 @@ struct Char
else # at the beginning of the set or escaped
return not_negated if self == char
end
else
# go on
end

if range && previous
Expand Down
14 changes: 6 additions & 8 deletions src/compiler/crystal/codegen/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ class Crystal::CodeGenVisitor

abi_arg_type = abi_info.arg_types[i]
case abi_arg_type.kind
when LLVM::ABI::ArgKind::Direct
in .direct?
call_arg = codegen_direct_abi_call(call_arg, abi_arg_type) unless arg.type.nil_type?
when LLVM::ABI::ArgKind::Indirect
in .indirect?
# Pass argument as is (will be passed byval)
when LLVM::ABI::ArgKind::Ignore
in .ignore?
# Ignore
next
end
Expand Down Expand Up @@ -522,7 +522,7 @@ class Crystal::CodeGenVisitor
else
abi_return = abi_info(external).return_type
case abi_return.kind
when LLVM::ABI::ArgKind::Direct
in .direct?
if cast = abi_return.cast
cast1 = alloca cast
store @last, cast1
Expand All @@ -535,9 +535,9 @@ class Crystal::CodeGenVisitor
memcpy(final_value_casted, cast2, size, align, int1(0))
@last = final_value
end
when LLVM::ABI::ArgKind::Indirect
in .indirect?
@last = @sret_value.not_nil!
when LLVM::ABI::ArgKind::Ignore
in .ignore?
# Nothing
end
end
Expand All @@ -553,8 +553,6 @@ class Crystal::CodeGenVisitor
else
@last = llvm_nil
end
else
# go on
end
end

Expand Down
6 changes: 0 additions & 6 deletions src/compiler/crystal/codegen/cast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ class Crystal::CodeGenVisitor
value = upcast(value, compatible_type, value_type)
return assign(target_pointer, target_type, compatible_type, value)
end
else
# go on
end

value = to_rhs(value, value_type)
Expand Down Expand Up @@ -461,8 +459,6 @@ class Crystal::CodeGenVisitor
value = downcast(value, to_type, compatible_type, true)
return value
end
else
# go on
end

_, value_ptr = union_type_and_value_pointer(value, from_type)
Expand Down Expand Up @@ -677,8 +673,6 @@ class Crystal::CodeGenVisitor
value = upcast(value, compatible_type, from_type)
return upcast(value, to_type, compatible_type)
end
else
# go on
end

union_ptr = alloca(llvm_type(to_type))
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/crystal/codegen/class_var.cr
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ class Crystal::CodeGenVisitor
return read_virtual_class_var_ptr(class_var, owner)
when VirtualMetaclassType
return read_virtual_metaclass_class_var_ptr(class_var, owner)
else
# go on
end

initializer = class_var.initializer
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ module Crystal
@codegen.personality_name, GET_EXCEPTION_NAME, RAISE_OVERFLOW_NAME,
ONCE_INIT, ONCE
@codegen.accept node
else
# go on
end

false
Expand Down Expand Up @@ -1104,8 +1102,6 @@ module Crystal
when ClassVar
# This is the case of a class var initializer
initialize_class_var(var)
else
# go on
end

@last = llvm_nil
Expand Down
28 changes: 14 additions & 14 deletions src/compiler/crystal/codegen/fun.cr
Original file line number Diff line number Diff line change
Expand Up @@ -329,27 +329,27 @@ class Crystal::CodeGenVisitor
llvm_args_types = Array(LLVM::Type).new(abi_info.arg_types.size)
abi_info.arg_types.each do |arg_type|
case arg_type.kind
when LLVM::ABI::ArgKind::Direct
in .direct?
llvm_args_types << (arg_type.cast || arg_type.type)
when LLVM::ABI::ArgKind::Indirect
in .indirect?
llvm_args_types << arg_type.type.pointer
when LLVM::ABI::ArgKind::Ignore
in .ignore?
# ignore
end
end

ret_type = abi_info.return_type
case ret_type.kind
when LLVM::ABI::ArgKind::Direct
llvm_return_type = (ret_type.cast || ret_type.type)
when LLVM::ABI::ArgKind::Indirect
sret = true
offset += 1
llvm_args_types.insert 0, ret_type.type.pointer
llvm_return_type = llvm_context.void
else
llvm_return_type = llvm_context.void
end
llvm_return_type =
case ret_type.kind
in .direct?
ret_type.cast || ret_type.type
in .indirect?
offset += 1
llvm_args_types.insert 0, ret_type.type.pointer
llvm_context.void
in .ignore?
llvm_context.void
end

setup_context_fun(mangled_name, target_def, llvm_args_types, llvm_return_type)

Expand Down
8 changes: 3 additions & 5 deletions src/compiler/crystal/codegen/primitives.cr
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,11 @@ class Crystal::CodeGenVisitor
when ">=" then return codegen_binary_op_gte(t1, t2, p1, p2)
when "==" then return codegen_binary_op_eq(t1, t2, p1, p2)
when "!=" then return codegen_binary_op_ne(t1, t2, p1, p2)
else # go on
end

case op
when "+", "-", "*"
return codegen_binary_op_with_overflow(op, t1, t2, p1, p2)
else # go on
end

tmax, p1, p2 = codegen_binary_extend_int(t1, t2, p1, p2)
Expand Down Expand Up @@ -1032,19 +1030,19 @@ class Crystal::CodeGenVisitor

abi_arg_type = abi_info.arg_types[index]
case abi_arg_type.kind
when LLVM::ABI::ArgKind::Direct
in .direct?
call_arg = codegen_direct_abi_call(call_arg, abi_arg_type)
if cast = abi_arg_type.cast
null_fun_types << cast
else
null_fun_types << abi_arg_type.type
end
null_args << call_arg
when LLVM::ABI::ArgKind::Indirect
in .indirect?
# Pass argument as is (will be passed byval)
null_args << call_arg
null_fun_types << abi_arg_type.type.pointer
when LLVM::ABI::ArgKind::Ignore
in .ignore?
# Ignore
end
end
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/crystal/codegen/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,10 @@ module Crystal
when CharLiteral
@compile_time_value = value.value
else
case type = value.type?
case value.type?
when IntegerType, EnumType
interpreter = MathInterpreter.new(namespace, visitor)
@compile_time_value = interpreter.interpret(value) rescue nil
else
# go on
end
end
end
Expand Down
Loading