Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 45435a1

Browse files
committed
Work-around for #546
If the `reason` passed to `__lumen_builtin_error` is a 2-tuple of `{Class, Reason}` where `Class` is `error` or `exit`, exit the process with just `Reason`.
1 parent 2b9fc68 commit 45435a1

File tree

15 files changed

+49
-36
lines changed
  • 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
        • with_true_value_with_linked_and_does_not_exit_when_linked_process_exits_normal
        • with_true_value_with_linked_receive_exit_message_and_does_not_exit_when_linked_process_does_not_exit_normal
    • spawn_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity
    • spawn_monitor_1/with_function
      • with_arity_zero
        • with_environment
          • with_normal_exit_in_child_process_sends_exit_message_to_parent
          • without_normal_exit_in_child_process_sends_exit_message_to_parent
        • without_environment/without_normal_exit_in_child_process_sends_exit_message_to_parent
      • without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity_and_sends_exit_message_to_parent
  • runtimes/minimal/src

15 files changed

+49
-36
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ start() ->
2020
end
2121
end),
2222
receive
23-
%% FIXME https://github.com/lumen/lumen/issues/546
24-
{'DOWN', ParentMonitorReference, process, _, {exit, Reason}} ->
23+
{'DOWN', ParentMonitorReference, process, _, Reason} ->
2524
display({parent, exited, Reason});
2625
10 ->
2726
display({parent, alive, is_process_alive(ParentPid)})

native_implemented/otp/tests/lib/erlang/link_1/with_local_pid/when_the_process_does_not_exit_normal_linked_processes_exit_too/init.erl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ start() ->
2020
ChildMonitorReference = monitor(process, ChildPid),
2121
shutdown(ParentPid),
2222
receive
23-
%% FIXME https://github.com/lumen/lumen/issues/546
24-
{'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} ->
23+
{'DOWN', ParentMonitorReference, process, _, Reason1} ->
2524
display({parent, exited, Reason1})
2625
after 10 ->
2726
display({parent, alive, is_process_alive(ParentPid)})
2827
end,
2928
receive
30-
%% FIXME https://github.com/lumen/lumen/issues/546
31-
{'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} ->
29+
{'DOWN', ChildMonitorReference, process, _, Reason2} ->
3230
display({child, exited, Reason2})
3331
after 10 ->
3432
display({child, alive, is_process_alive(ChildPid)})

native_implemented/otp/tests/lib/erlang/process_flag_2/with_atom_flag/with_trap_exit_flag.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ test_stdout!(
66
);
77
test_stdout!(
88
with_true_value_with_linked_and_does_not_exit_when_linked_process_exits_normal,
9-
"{trap_exit, true}\n{parent, alive, true}\n{child, alive, false}\n"
9+
"{trap_exit, true}\n{parent, alive, true}\n{child, exited, normal}\n"
1010
);
1111
test_stdout!(
1212
with_true_value_with_linked_receive_exit_message_and_does_not_exit_when_linked_process_does_not_exit_normal,
13-
"{trap_exit, true}\n{parent, sees, child, exit, due, to, abnormal}\n{parent, alive, true}\n{child, exited, abnormal}\n"
13+
"{trap_exit, true}\n{parent, alive, true}\n{child, exited, abnormal}\n{parent, sees, child, alive, false}\n"
1414
);
1515
test_stdout!(
1616
with_true_value_then_false_value_exits_when_linked_process_does_not_exit_normal,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ end),
2525
ChildMonitorReference = monitor(process, ChildPid),
2626
shutdown(ParentPid),
2727
receive
28-
%% FIXME https://github.com/lumen/lumen/issues/546
29-
{'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} ->
28+
{'DOWN', ParentMonitorReference, process, _, Reason1} ->
3029
display({parent, exited, Reason1})
3130
after 10 ->
3231
display({parent, alive, is_process_alive(ParentPid)})
3332
end,
3433
receive
35-
%% FIXME https://github.com/lumen/lumen/issues/546
36-
{'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} ->
34+
{'DOWN', ChildMonitorReference, process, _, Reason2} ->
3735
display({child, exited, Reason2})
3836
after 10 ->
3937
display({child, alive, is_process_alive(ChildPid)})

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ start() ->
2222
ChildMonitorReference = monitor(process, ChildPid),
2323
shutdown_child(ParentPid),
2424
receive
25-
%% FIXME https://github.com/lumen/lumen/issues/546
26-
{'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} ->
25+
{'DOWN', ParentMonitorReference, process, _, Reason1} ->
2726
display({parent, exited, Reason1})
2827
after 10 ->
2928
display({parent, alive, is_process_alive(ParentPid)})
3029
end,
3130
receive
32-
%% FIXME https://github.com/lumen/lumen/issues/546
33-
{'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} ->
31+
{'DOWN', ChildMonitorReference, process, _, Reason2} ->
3432
display({child, exited, Reason2})
3533
after 10 ->
3634
display({child, alive, is_process_alive(ChildPid)})

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ start() ->
2929
ChildMonitorReference = monitor(process, ChildPid),
3030
shutdown_child(ParentPid),
3131
receive
32-
%% FIXME https://github.com/lumen/lumen/issues/546
33-
{'DOWN', ParentMonitorReference, process, _, {exit, Reason1}} ->
32+
{'DOWN', ParentMonitorReference, process, _, Reason1} ->
3433
display({parent, exited, Reason1})
3534
after 10 ->
3635
display({parent, alive, is_process_alive(ParentPid)})
3736
end,
3837
receive
39-
%% FIXME https://github.com/lumen/lumen/issues/546
40-
{'DOWN', ChildMonitorReference, process, _, {exit, Reason2}} ->
38+
{'DOWN', ChildMonitorReference, process, _, Reason2} ->
4139
display({child, exited, Reason2})
4240
after 10 ->
4341
display({child, alive, is_process_alive(ChildPid)})

native_implemented/otp/tests/lib/erlang/spawn_1/with_function/without_arity_zero_returns_pid_to_parent_and_child_process_exits_badarity/init.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ start() ->
1212
receive
1313
{'DOWN', MonitorRef, process, _, Info} ->
1414
case Info of
15-
{error, {Reason, _Stacktrace}} -> display(Reason);
15+
%% FIXME https://github.com/lumen/lumen/issues/548
16+
{Reason, FunArgs} -> display(Reason);
1617
Other -> display(Other)
1718
end
1819
after 20 ->

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ start() ->
2323
ok
2424
end),
2525
receive
26-
%% FIXME https://github.com/lumen/lumen/issues/546
27-
{'DOWN', ParentMonitorReference, process, _, {exit, Reason}} ->
26+
{'DOWN', ParentMonitorReference, process, _, Reason} ->
2827
display({parent, Reason})
2928
after
3029
100 ->

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ start() ->
2222
ok
2323
end),
2424
receive
25-
%% FIXME https://github.com/lumen/lumen/issues/546
26-
{'DOWN', ParentMonitorReference, process, _, {exit, Reason}} ->
25+
{'DOWN', ParentMonitorReference, process, _, Reason} ->
2726
display({parent, Reason})
2827
after
2928
100 ->

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ start() ->
2222
ok
2323
end),
2424
receive
25-
%% FIXME https://github.com/lumen/lumen/issues/546
26-
{'DOWN', ParentMonitorReference, process, _, {error, Info}} ->
25+
{'DOWN', ParentMonitorReference, process, _, Info} ->
2726
case Info of
2827
{badarity = Reason, FunArgs} ->
2928
display({parent, Reason});

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ start() ->
1010
exit(Environment)
1111
end),
1212
receive
13-
%% FIXME https://github.com/lumen/lumen/issues/546
14-
{'DOWN', ChildMonitorReference, process, _, {exit, Reason}} ->
13+
{'DOWN', ChildMonitorReference, process, _, Reason} ->
1514
display({child, exited, Reason})
1615
after 10 ->
1716
display(timeout)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ start() ->
1010
exit(Environment)
1111
end),
1212
receive
13-
%% FIXME https://github.com/lumen/lumen/issues/546
14-
{'DOWN', ChildMonitorReference, process, _, {exit, Reason}} ->
13+
{'DOWN', ChildMonitorReference, process, _, Reason} ->
1514
display({child, exited, Reason})
1615
after 10 ->
1716
display(timeout)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ start() ->
99
exit(abnormal)
1010
end),
1111
receive
12-
%% FIXME https://github.com/lumen/lumen/issues/546
13-
{'DOWN', ChildMonitorReference, process, _, {exit, Reason}} ->
12+
{'DOWN', ChildMonitorReference, process, _, Reason} ->
1413
display({child, exited, Reason})
1514
after 10 ->
1615
display(timeout)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ start() ->
99
display(A)
1010
end),
1111
receive
12-
%% FIXME https://github.com/lumen/lumen/issues/546
13-
{'DOWN', ChildMonitorReference, process, _, {error, {Reason, Details}}} ->
12+
{'DOWN', ChildMonitorReference, process, _, {Reason, Details}} ->
1413
display({child, exited, Reason})
1514
after 10 ->
1615
display(timeout)

runtimes/minimal/src/scheduler.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,40 @@ pub unsafe extern "C" fn process_exit(reason: Term) {
7575
.as_any()
7676
.downcast_ref::<Scheduler>()
7777
.unwrap();
78+
// FIXME https://github.com/lumen/lumen/issues/546
79+
let exit_reason = work_around546(reason);
80+
7881
scheduler
7982
.current
80-
.exit(reason, anyhow!("process exit").into());
83+
.exit(exit_reason, anyhow!("process exit").into());
8184
scheduler.process_yield();
8285
}
8386

87+
// Work-around: Unwrap `{class, reason}`, but it means that processes can't exit with a reason
88+
// that looks like `{class, reason}.
89+
fn work_around546(reason: Term) -> Term {
90+
match reason.decode().unwrap() {
91+
TypedTerm::Tuple(boxed_tuple) => {
92+
let elements = boxed_tuple.elements();
93+
94+
if elements.len() == 2 {
95+
let class = elements[0];
96+
97+
match class.decode().unwrap() {
98+
TypedTerm::Atom(class_atom) => match class_atom.name() {
99+
"error" | "exit" => elements[1],
100+
_ => reason,
101+
},
102+
_ => reason,
103+
}
104+
} else {
105+
reason
106+
}
107+
}
108+
_ => reason,
109+
}
110+
}
111+
84112
#[naked]
85113
#[inline(never)]
86114
#[cfg(all(unix, target_arch = "x86_64"))]

0 commit comments

Comments
 (0)