Skip to content

Commit f31325c

Browse files
committed
ocaml#6203, ocaml#5935: variants of raise. 'reraise' is currently only inserted by the compiler when an handler does not catch the exception. The default 'raise' always start with a fresh backtrace. There is also 'raise_nostack' which does not trigger the stack trace recording. Bytecode only for now.
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/raise_variants@14223 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent 5dabafb commit f31325c

21 files changed

+65
-27
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ coldstart:
199199
if test -d stdlib/caml; then :; else \
200200
ln -s ../byterun stdlib/caml; fi
201201

202+
bootlib:
203+
cd stdlib; $(MAKE) all
204+
cd stdlib; cp $(LIBFILES) ../boot
205+
202206
# Build the core system: the minimum needed to make depend and bootstrap
203207
core:
204208
$(MAKE) coldstart
@@ -782,7 +786,7 @@ camlp4opt: ocamlopt otherlibrariesopt ocamlbuild-mixed-boot ocamlbuild.native
782786

783787
# Ocamlbuild
784788
#ifeq ($(OCAMLBUILD_NOBOOT),"yes")
785-
#ocamlbuild.byte: ocamlc
789+
#ocamlbuild.byte: ocamlc
786790
# $(MAKE) -C ocamlbuild -f Makefile.noboot
787791
#else
788792
ocamlbuild.byte: ocamlc ocamlbuild-mixed-boot

boot/myocamlbuild.boot

-412 Bytes
Binary file not shown.

boot/ocamlc

2.35 KB
Binary file not shown.

boot/ocamldep

479 Bytes
Binary file not shown.

boot/ocamllex

0 Bytes
Binary file not shown.

bytecomp/bytegen.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ let make_branch cont =
7474
match cont with
7575
(Kbranch _ as branch) :: _ -> (branch, cont)
7676
| (Kreturn _ as return) :: _ -> (return, cont)
77-
| Kraise :: _ -> (Kraise, cont)
77+
| Kraise k :: _ -> (Kraise k, cont)
7878
| Klabel lbl :: _ -> make_branch_2 (Some lbl) 0 cont cont
7979
| _ -> make_branch_2 (None) 0 cont cont
8080

@@ -108,7 +108,7 @@ let rec add_pop n cont =
108108
match cont with
109109
Kpop m :: cont -> add_pop (n + m) cont
110110
| Kreturn m :: cont -> Kreturn(n + m) :: cont
111-
| Kraise :: _ -> cont
111+
| Kraise _ :: _ -> cont
112112
| _ -> Kpop n :: cont
113113

114114
(* Add the constant "unit" in front of a continuation *)
@@ -584,8 +584,8 @@ let rec comp_expr env exp sz cont =
584584
comp_expr env exp1 sz (Kstrictbranchif lbl ::
585585
comp_expr env exp2 sz cont1)
586586
end
587-
| Lprim(Praise, [arg]) ->
588-
comp_expr env arg sz (Kraise :: discard_dead_code cont)
587+
| Lprim(Praise k, [arg]) ->
588+
comp_expr env arg sz (Kraise k :: discard_dead_code cont)
589589
| Lprim(Paddint, [arg; Lconst(Const_base(Const_int n))])
590590
when is_immed n ->
591591
comp_expr env arg sz (Koffsetint n :: cont)

bytecomp/emitcode.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ let emit_instr = function
243243
| Kboolnot -> out opBOOLNOT
244244
| Kpushtrap lbl -> out opPUSHTRAP; out_label lbl
245245
| Kpoptrap -> out opPOPTRAP
246-
| Kraise -> out opRAISE
246+
| Kraise Raise_regular -> out opRAISE
247+
| Kraise Raise_reraise -> out opRERAISE
248+
| Kraise Raise_nostack -> out opRAISE_NOSTACK
247249
| Kcheck_signals -> out opCHECK_SIGNALS
248250
| Kccall(name, n) ->
249251
if n <= 5

bytecomp/instruct.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type instruction =
8585
| Kboolnot
8686
| Kpushtrap of label
8787
| Kpoptrap
88-
| Kraise
88+
| Kraise of raise_kind
8989
| Kcheck_signals
9090
| Kccall of string * int
9191
| Knegint | Kaddint | Ksubint | Kmulint | Kdivint | Kmodint

bytecomp/instruct.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type instruction =
105105
| Kboolnot
106106
| Kpushtrap of label
107107
| Kpoptrap
108-
| Kraise
108+
| Kraise of raise_kind
109109
| Kcheck_signals
110110
| Kccall of string * int
111111
| Knegint | Kaddint | Ksubint | Kmulint | Kdivint | Kmodint

bytecomp/lambda.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type primitive =
4141
(* External call *)
4242
| Pccall of Primitive.description
4343
(* Exceptions *)
44-
| Praise
44+
| Praise of raise_kind
4545
(* Boolean operations *)
4646
| Psequand | Psequor | Pnot
4747
(* Integer operations *)
@@ -137,6 +137,11 @@ and bigarray_layout =
137137
| Pbigarray_c_layout
138138
| Pbigarray_fortran_layout
139139

140+
and raise_kind =
141+
| Raise_regular
142+
| Raise_reraise
143+
| Raise_nostack
144+
140145
type structured_constant =
141146
Const_base of constant
142147
| Const_pointer of int

bytecomp/lambda.mli

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type primitive =
4141
(* External call *)
4242
| Pccall of Primitive.description
4343
(* Exceptions *)
44-
| Praise
44+
| Praise of raise_kind
4545
(* Boolean operations *)
4646
| Psequand | Psequor | Pnot
4747
(* Integer operations *)
@@ -137,6 +137,11 @@ and bigarray_layout =
137137
| Pbigarray_c_layout
138138
| Pbigarray_fortran_layout
139139

140+
and raise_kind =
141+
| Raise_regular
142+
| Raise_reraise
143+
| Raise_nostack
144+
140145
type structured_constant =
141146
Const_base of constant
142147
| Const_pointer of int

bytecomp/matching.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ let rec do_tests_nofail tst arg = function
16781678

16791679
let make_test_sequence fail tst lt_tst arg const_lambda_list =
16801680
let rec make_test_sequence const_lambda_list =
1681-
if List.length const_lambda_list >= 4 && lt_tst <> Praise then
1681+
if List.length const_lambda_list >= 4 && lt_tst <> Pignore then
16821682
split_sequence const_lambda_list
16831683
else match fail with
16841684
| None -> do_tests_nofail tst arg const_lambda_list
@@ -2098,7 +2098,7 @@ let combine_constant arg cst partial ctx def
20982098
fail arg 0 255 int_lambda_list
20992099
| Const_string _ ->
21002100
make_test_sequence
2101-
fail prim_string_notequal Praise arg const_lambda_list
2101+
fail prim_string_notequal Pignore arg const_lambda_list
21022102
| Const_float _ ->
21032103
make_test_sequence
21042104
fail
@@ -2728,7 +2728,7 @@ let compile_matching loc repr handler_fun arg pat_act_list partial =
27282728
let partial_function loc () =
27292729
(* [Location.get_pos_info] is too expensive *)
27302730
let (fname, line, char) = Location.get_pos_info loc.Location.loc_start in
2731-
Lprim(Praise, [Lprim(Pmakeblock(0, Immutable),
2731+
Lprim(Praise Raise_regular, [Lprim(Pmakeblock(0, Immutable),
27322732
[transl_path Predef.path_match_failure;
27332733
Lconst(Const_block(0,
27342734
[Const_base(Const_string (fname, None));
@@ -2740,7 +2740,8 @@ let for_function loc repr param pat_act_list partial =
27402740

27412741
(* In the following two cases, exhaustiveness info is not available! *)
27422742
let for_trywith param pat_act_list =
2743-
compile_matching Location.none None (fun () -> Lprim(Praise, [param]))
2743+
compile_matching Location.none None
2744+
(fun () -> Lprim(Praise Raise_reraise, [param]))
27442745
param pat_act_list Partial
27452746

27462747
let for_let loc param pat body =

bytecomp/printinstr.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ let instruction ppf = function
6767
| Kboolnot -> fprintf ppf "\tboolnot"
6868
| Kpushtrap lbl -> fprintf ppf "\tpushtrap L%i" lbl
6969
| Kpoptrap -> fprintf ppf "\tpoptrap"
70-
| Kraise -> fprintf ppf "\traise"
70+
| Kraise Raise_regular-> fprintf ppf "\traise"
71+
| Kraise Raise_reraise-> fprintf ppf "\treraise"
72+
| Kraise Raise_nostack-> fprintf ppf "\traise_nostack"
7173
| Kcheck_signals -> fprintf ppf "\tcheck_signals"
7274
| Kccall(s, n) ->
7375
fprintf ppf "\tccall %s, %i" s n

bytecomp/printlambda.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ let primitive ppf = function
105105
| Pduprecord (rep, size) -> fprintf ppf "duprecord %a %i" record_rep rep size
106106
| Plazyforce -> fprintf ppf "force"
107107
| Pccall p -> fprintf ppf "%s" p.prim_name
108-
| Praise -> fprintf ppf "raise"
108+
| Praise Raise_regular -> fprintf ppf "raise"
109+
| Praise Raise_reraise -> fprintf ppf "re-raise"
110+
| Praise Raise_nostack -> fprintf ppf "raise-no-stack"
109111
| Psequand -> fprintf ppf "&&"
110112
| Psequor -> fprintf ppf "||"
111113
| Pnot -> fprintf ppf "not"

bytecomp/translcore.ml

+6-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ let primitives_table = create_hashtable 57 [
146146
"%setfield0", Psetfield(0, true);
147147
"%makeblock", Pmakeblock(0, Immutable);
148148
"%makemutable", Pmakeblock(0, Mutable);
149-
"%raise", Praise;
149+
"%raise", Praise Raise_regular;
150+
"%reraise", Praise Raise_reraise;
151+
"%raise_nostack", Praise Raise_nostack;
150152
"%sequand", Psequand;
151153
"%sequor", Psequor;
152154
"%boolnot", Pnot;
@@ -585,7 +587,7 @@ let primitive_is_ccall = function
585587
let assert_failed exp =
586588
let (fname, line, char) =
587589
Location.get_pos_info exp.exp_loc.Location.loc_start in
588-
Lprim(Praise, [event_after exp
590+
Lprim(Praise Raise_regular, [event_after exp
589591
(Lprim(Pmakeblock(0, Immutable),
590592
[transl_path Predef.path_assert_failure;
591593
Lconst(Const_block(0,
@@ -679,8 +681,8 @@ and transl_exp0 e =
679681
(Warnings.Deprecated "operator (or); you should use (||) instead");
680682
let prim = transl_prim e.exp_loc p args in
681683
match (prim, args) with
682-
(Praise, [arg1]) ->
683-
wrap0 (Lprim(Praise, [event_after arg1 (List.hd argl)]))
684+
(Praise k, [arg1]) ->
685+
wrap0 (Lprim(Praise k, [event_after arg1 (List.hd argl)]))
684686
| (_, _) ->
685687
begin match (prim, argl) with
686688
| (Plazyforce, [a]) ->

byterun/backtrace.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ CAMLprim value caml_backtrace_status(value vunit)
9393
/* Store the return addresses contained in the given stack fragment
9494
into the backtrace array */
9595

96-
void caml_stash_backtrace(value exn, code_t pc, value * sp)
96+
void caml_stash_backtrace(value exn, code_t pc, value * sp, int reraise)
9797
{
9898
code_t end_code = (code_t) ((char *) caml_start_code + caml_code_size);
9999
if (pc != NULL) pc = pc - 1;
100-
if (exn != caml_backtrace_last_exn) {
100+
if (exn != caml_backtrace_last_exn || !reraise) {
101101
caml_backtrace_pos = 0;
102102
caml_backtrace_last_exn = exn;
103103
}

byterun/backtrace.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ CAMLextern char * caml_cds_file;
2424

2525
CAMLprim value caml_record_backtrace(value vflag);
2626
#ifndef NATIVE_CODE
27-
extern void caml_stash_backtrace(value exn, code_t pc, value * sp);
27+
extern void caml_stash_backtrace(value exn, code_t pc, value * sp, int reraise);
2828
#endif
2929
CAMLextern void caml_print_exception_backtrace(void);
3030

byterun/exec.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct exec_trailer {
5454

5555
/* Magic number for this release */
5656

57-
#define EXEC_MAGIC "Caml1999X008"
57+
#define EXEC_MAGIC "Caml1999X009"
5858

5959

6060
#endif /* CAML_EXEC_H */

byterun/instruct.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ enum instructions {
3939
VECTLENGTH, GETVECTITEM, SETVECTITEM,
4040
GETSTRINGCHAR, SETSTRINGCHAR,
4141
BRANCH, BRANCHIF, BRANCHIFNOT, SWITCH, BOOLNOT,
42-
PUSHTRAP, POPTRAP, RAISE, CHECK_SIGNALS,
42+
PUSHTRAP, POPTRAP, RAISE,
43+
RERAISE, RAISE_NOSTACK,
44+
CHECK_SIGNALS,
4345
C_CALL1, C_CALL2, C_CALL3, C_CALL4, C_CALL5, C_CALLN,
4446
CONST0, CONST1, CONST2, CONST3, CONSTINT,
4547
PUSHCONST0, PUSHCONST1, PUSHCONST2, PUSHCONST3, PUSHCONSTINT,

byterun/interp.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,23 @@ value caml_interprete(code_t prog, asize_t prog_size)
820820
sp += 4;
821821
Next;
822822

823+
Instruct(RAISE_NOSTACK):
824+
/*printf("raise_nostack\n"); fflush(stdout);*/
825+
if (caml_trapsp >= caml_trap_barrier) caml_debugger(TRAP_BARRIER);
826+
goto raise_nostack;
827+
828+
Instruct(RERAISE):
829+
/*printf("reraise\n"); fflush(stdout);*/
830+
if (caml_trapsp >= caml_trap_barrier) caml_debugger(TRAP_BARRIER);
831+
if (caml_backtrace_active) caml_stash_backtrace(accu, pc, sp, 1);
832+
goto raise_nostack;
833+
823834
Instruct(RAISE):
835+
/*printf("raise\n"); fflush(stdout);*/
824836
raise_exception:
825837
if (caml_trapsp >= caml_trap_barrier) caml_debugger(TRAP_BARRIER);
826-
if (caml_backtrace_active) caml_stash_backtrace(accu, pc, sp);
838+
if (caml_backtrace_active) caml_stash_backtrace(accu, pc, sp, 0);
839+
raise_nostack:
827840
if ((char *) caml_trapsp
828841
>= (char *) caml_stack_high - initial_sp_offset) {
829842
caml_external_raise = initial_external_raise;

utils/config.mlp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let mkdll = "%%MKDLL%%"
4848
let mkexe = "%%MKEXE%%"
4949
let mkmaindll = "%%MKMAINDLL%%"
5050

51-
let exec_magic_number = "Caml1999X008"
51+
let exec_magic_number = "Caml1999X009"
5252
and cmi_magic_number = "Caml1999I015"
5353
and cmo_magic_number = "Caml1999O007"
5454
and cma_magic_number = "Caml1999A008"

0 commit comments

Comments
 (0)