diff --git a/native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_a_linked_process_does_not_exit_normal_the_process_exits_too/init.erl b/native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_a_linked_process_does_not_exit_normal_the_process_exits_too/init.erl index 1ad5e1ebf..1ce9d4417 100644 --- a/native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_a_linked_process_does_not_exit_normal_the_process_exits_too/init.erl +++ b/native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_a_linked_process_does_not_exit_normal_the_process_exits_too/init.erl @@ -20,8 +20,7 @@ start() -> end end), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ParentMonitorReference, process, _, {exit, Reason}} -> + {'DOWN', ParentMonitorReference, process, _, Reason} -> display({parent, exited, Reason}); 10 -> display({parent, alive, is_process_alive(ParentPid)}) diff --git a/native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_the_process_does_not_exit_normal_linked_processes_exit_too/init.erl b/native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_the_process_does_not_exit_normal_linked_processes_exit_too/init.erl index e77bb08a3..8fa93fef5 100644 --- a/native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_the_process_does_not_exit_normal_linked_processes_exit_too/init.erl +++ b/native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_the_process_does_not_exit_normal_linked_processes_exit_too/init.erl @@ -20,15 +20,13 @@ start() -> ChildMonitorReference = monitor(process, ChildPid), shutdown(ParentPid), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} -> + {'DOWN', ParentMonitorReference, process, _, Reason1} -> display({parent, exited, Reason1}) after 10 -> display({parent, alive, is_process_alive(ParentPid)}) end, receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} -> + {'DOWN', ChildMonitorReference, process, _, Reason2} -> display({child, exited, Reason2}) after 10 -> display({child, alive, is_process_alive(ChildPid)}) diff --git a/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag.rs b/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag.rs index 2e66b7adc..033183893 100644 --- a/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag.rs +++ b/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag.rs @@ -6,11 +6,11 @@ test_stdout!( ); test_stdout!( with_true_value_with_linked_and_does_not_exit_when_linked_process_exits_normal, - "{trap_exit, true}\n{parent, alive, true}\n{child, alive, false}\n" + "{trap_exit, true}\n{parent, alive, true}\n{child, exited, normal}\n" ); test_stdout!( with_true_value_with_linked_receive_exit_message_and_does_not_exit_when_linked_process_does_not_exit_normal, - "{trap_exit, true}\n{parent, sees, child, exit, due, to, abnormal}\n{parent, alive, true}\n{child, exited, abnormal}\n" + "{trap_exit, true}\n{parent, alive, true}\n{child, exited, abnormal}\n{parent, sees, child, alive, false}\n" ); test_stdout!( with_true_value_then_false_value_exits_when_linked_process_does_not_exit_normal, diff --git a/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_then_false_value_exits_when_linked_process_does_not_exit_normal/init.erl b/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_then_false_value_exits_when_linked_process_does_not_exit_normal/init.erl index c36006fad..dac14bbb4 100644 --- a/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_then_false_value_exits_when_linked_process_does_not_exit_normal/init.erl +++ b/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_then_false_value_exits_when_linked_process_does_not_exit_normal/init.erl @@ -25,15 +25,13 @@ end), ChildMonitorReference = monitor(process, ChildPid), shutdown(ParentPid), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} -> + {'DOWN', ParentMonitorReference, process, _, Reason1} -> display({parent, exited, Reason1}) after 10 -> display({parent, alive, is_process_alive(ParentPid)}) end, receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} -> + {'DOWN', ChildMonitorReference, process, _, Reason2} -> display({child, exited, Reason2}) after 10 -> display({child, alive, is_process_alive(ChildPid)}) diff --git a/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_with_linked_and_does_not_exit_when_linked_process_exits_normal/init.erl b/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_with_linked_and_does_not_exit_when_linked_process_exits_normal/init.erl index ab90352b2..2a3ad3393 100644 --- a/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_with_linked_and_does_not_exit_when_linked_process_exits_normal/init.erl +++ b/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_with_linked_and_does_not_exit_when_linked_process_exits_normal/init.erl @@ -22,15 +22,13 @@ start() -> ChildMonitorReference = monitor(process, ChildPid), shutdown_child(ParentPid), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} -> + {'DOWN', ParentMonitorReference, process, _, Reason1} -> display({parent, exited, Reason1}) after 10 -> display({parent, alive, is_process_alive(ParentPid)}) end, receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} -> + {'DOWN', ChildMonitorReference, process, _, Reason2} -> display({child, exited, Reason2}) after 10 -> display({child, alive, is_process_alive(ChildPid)}) diff --git a/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_with_linked_receive_exit_message_and_does_not_exit_when_linked_process_does_not_exit_normal/init.erl b/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_with_linked_receive_exit_message_and_does_not_exit_when_linked_process_does_not_exit_normal/init.erl index 388876776..bdd8c7b2b 100644 --- a/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_with_linked_receive_exit_message_and_does_not_exit_when_linked_process_does_not_exit_normal/init.erl +++ b/native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag/with_true_value_with_linked_receive_exit_message_and_does_not_exit_when_linked_process_does_not_exit_normal/init.erl @@ -29,15 +29,13 @@ start() -> ChildMonitorReference = monitor(process, ChildPid), shutdown_child(ParentPid), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} -> + {'DOWN', ParentMonitorReference, process, _, Reason1} -> display({parent, exited, Reason1}) after 10 -> display({parent, alive, is_process_alive(ParentPid)}) end, receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} -> + {'DOWN', ChildMonitorReference, process, _, Reason2} -> display({child, exited, Reason2}) after 10 -> display({child, alive, is_process_alive(ChildPid)}) diff --git a/native_implemented/otp/tests/lib/erlang/spawn_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity/init.erl b/native_implemented/otp/tests/lib/erlang/spawn_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity/init.erl index ceb8203da..63db36e13 100644 --- a/native_implemented/otp/tests/lib/erlang/spawn_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity/init.erl +++ b/native_implemented/otp/tests/lib/erlang/spawn_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity/init.erl @@ -12,7 +12,8 @@ start() -> receive {'DOWN', MonitorRef, process, _, Info} -> case Info of - {error, {Reason, _Stacktrace}} -> display(Reason); + %% FIXME https://github.com/lumen/lumen/issues/548 + {Reason, FunArgs} -> display(Reason); Other -> display(Other) end after 20 -> diff --git a/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/with_arity_zero/with_environment/without_normal_exit_in_child_process_exits_linked_parent_process/init.erl b/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/with_arity_zero/with_environment/without_normal_exit_in_child_process_exits_linked_parent_process/init.erl index b7860eb13..7a7ca26f1 100644 --- a/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/with_arity_zero/with_environment/without_normal_exit_in_child_process_exits_linked_parent_process/init.erl +++ b/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/with_arity_zero/with_environment/without_normal_exit_in_child_process_exits_linked_parent_process/init.erl @@ -23,8 +23,7 @@ start() -> ok end), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ParentMonitorReference, process, _, {exit, Reason}} -> + {'DOWN', ParentMonitorReference, process, _, Reason} -> display({parent, Reason}) after 100 -> diff --git a/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/with_arity_zero/without_environment/without_normal_exit_in_child_process_exits_linked_parent_process/init.erl b/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/with_arity_zero/without_environment/without_normal_exit_in_child_process_exits_linked_parent_process/init.erl index 61d8b34ab..f4b96ebda 100644 --- a/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/with_arity_zero/without_environment/without_normal_exit_in_child_process_exits_linked_parent_process/init.erl +++ b/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/with_arity_zero/without_environment/without_normal_exit_in_child_process_exits_linked_parent_process/init.erl @@ -22,8 +22,7 @@ start() -> ok end), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ParentMonitorReference, process, _, {exit, Reason}} -> + {'DOWN', ParentMonitorReference, process, _, Reason} -> display({parent, Reason}) after 100 -> diff --git a/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_which_exits_linked_parent/init.erl b/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_which_exits_linked_parent/init.erl index d7a4d4cef..c04621a25 100644 --- a/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_which_exits_linked_parent/init.erl +++ b/native_implemented/otp/tests/lib/erlang/spawn_link_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_which_exits_linked_parent/init.erl @@ -22,8 +22,7 @@ start() -> ok end), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ParentMonitorReference, process, _, {error, Info}} -> + {'DOWN', ParentMonitorReference, process, _, Info} -> case Info of {badarity = Reason, FunArgs} -> display({parent, Reason}); diff --git a/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/with_environment/with_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl b/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/with_environment/with_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl index 3fe47c94f..57ec3c17f 100644 --- a/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/with_environment/with_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl +++ b/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/with_environment/with_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl @@ -10,8 +10,7 @@ start() -> exit(Environment) end), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ChildMonitorReference, process, _, {exit, Reason}} -> + {'DOWN', ChildMonitorReference, process, _, Reason} -> display({child, exited, Reason}) after 10 -> display(timeout) diff --git a/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/with_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl b/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/with_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl index 0478a7140..57e756f27 100644 --- a/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/with_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl +++ b/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/with_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl @@ -10,8 +10,7 @@ start() -> exit(Environment) end), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ChildMonitorReference, process, _, {exit, Reason}} -> + {'DOWN', ChildMonitorReference, process, _, Reason} -> display({child, exited, Reason}) after 10 -> display(timeout) diff --git a/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/without_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl b/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/without_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl index 3802afd05..7925f8b15 100644 --- a/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/without_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl +++ b/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/with_arity_zero/without_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent/init.erl @@ -9,8 +9,7 @@ start() -> exit(abnormal) end), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ChildMonitorReference, process, _, {exit, Reason}} -> + {'DOWN', ChildMonitorReference, process, _, Reason} -> display({child, exited, Reason}) after 10 -> display(timeout) diff --git a/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_and_sends_exit_message_to_parent/init.erl b/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_and_sends_exit_message_to_parent/init.erl index e8d8d07be..af24e5763 100644 --- a/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_and_sends_exit_message_to_parent/init.erl +++ b/native_implemented/otp/tests/lib/erlang/spawn_monitor_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_and_sends_exit_message_to_parent/init.erl @@ -9,8 +9,7 @@ start() -> display(A) end), receive - %% FIXME https://github.com/lumen/lumen/issues/546 - {'DOWN', ChildMonitorReference, process, _, {error, {Reason, Details}}} -> + {'DOWN', ChildMonitorReference, process, _, {Reason, Details}} -> display({child, exited, Reason}) after 10 -> display(timeout) diff --git a/runtimes/minimal/src/scheduler.rs b/runtimes/minimal/src/scheduler.rs index ba0c8f9a4..886131f63 100644 --- a/runtimes/minimal/src/scheduler.rs +++ b/runtimes/minimal/src/scheduler.rs @@ -75,12 +75,40 @@ pub unsafe extern "C" fn process_exit(reason: Term) { .as_any() .downcast_ref::() .unwrap(); + // FIXME https://github.com/lumen/lumen/issues/546 + let exit_reason = work_around546(reason); + scheduler .current - .exit(reason, anyhow!("process exit").into()); + .exit(exit_reason, anyhow!("process exit").into()); scheduler.process_yield(); } +// Work-around: Unwrap `{class, reason}`, but it means that processes can't exit with a reason +// that looks like `{class, reason}. +fn work_around546(reason: Term) -> Term { + match reason.decode().unwrap() { + TypedTerm::Tuple(boxed_tuple) => { + let elements = boxed_tuple.elements(); + + if elements.len() == 2 { + let class = elements[0]; + + match class.decode().unwrap() { + TypedTerm::Atom(class_atom) => match class_atom.name() { + "error" | "exit" => elements[1], + _ => reason, + }, + _ => reason, + } + } else { + reason + } + } + _ => reason, + } +} + #[naked] #[inline(never)] #[cfg(all(unix, target_arch = "x86_64"))]