Skip to content

Commit 1412792

Browse files
committed
Move local allocations support behind '-extension local'
1 parent 6d8e42a commit 1412792

File tree

19 files changed

+42
-20
lines changed

19 files changed

+42
-20
lines changed

parsing/lexer.mll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ let keyword_table =
101101
"asr", INFIXOP4("asr")
102102
]
103103

104+
let lookup_keyword name =
105+
match Hashtbl.find keyword_table name with
106+
| LOCAL | NONLOCAL | GLOBAL
107+
when not (Clflags.Extension.is_enabled Local) ->
108+
LIDENT name
109+
| kw -> kw
110+
| exception Not_found ->
111+
LIDENT name
112+
104113
(* To buffer string literals *)
105114

106115
let string_buffer = Buffer.create 256
@@ -403,8 +412,7 @@ rule token = parse
403412
{ warn_latin1 lexbuf;
404413
OPTLABEL name }
405414
| lowercase identchar * as name
406-
{ try Hashtbl.find keyword_table name
407-
with Not_found -> LIDENT name }
415+
{ lookup_keyword name }
408416
| lowercase_latin1 identchar_latin1 * as name
409417
{ warn_latin1 lexbuf; LIDENT name }
410418
| uppercase identchar * as name

testsuite/tests/translprim/array_spec.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(* TEST
22
* setup-ocamlc.byte-build-env
33
** ocamlc.byte
4-
flags = "-dlambda -dno-unique-ids"
4+
flags = "-dlambda -dno-unique-ids -extension local"
55
*** flat-float-array
66
**** check-ocamlc.byte-output
77
compiler_reference =

testsuite/tests/translprim/comparison_table.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(* TEST
22
* setup-ocamlc.byte-build-env
33
** ocamlc.byte
4-
flags = "-dlambda -dno-unique-ids"
4+
flags = "-dlambda -dno-unique-ids -extension local"
55
*** check-ocamlc.byte-output
66
*)
77

testsuite/tests/translprim/ref_spec.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(* TEST
22
* setup-ocamlc.byte-build-env
33
** ocamlc.byte
4-
flags = "-dlambda -dno-unique-ids"
4+
flags = "-dlambda -dno-unique-ids -extension local"
55
*** check-ocamlc.byte-output
66
*)
77

testsuite/tests/typing-local/alloc.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(* TEST *)
1+
(* TEST
2+
flags += "-extension local" *)
23

34
type t = int
45

testsuite/tests/typing-local/aritybug.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(* TEST *)
1+
(* TEST
2+
flags += "-extension local" *)
23

34
let[@inline never] wat x =
45
let f ~a:_ ~b:_ ~c:_ () () = x in

testsuite/tests/typing-local/comballoc.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(* TEST *)
1+
(* TEST
2+
flags += "-extension local" *)
23
let glob = ref []
34

45
let[@inline never] f g n =

testsuite/tests/typing-local/curry.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(* TEST
2+
flags += "-extension local"
23
* bytecode
34
reference = "${test_source_directory}/curry.byte.reference"
45
* native

testsuite/tests/typing-local/exceptions.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(* TEST
2+
flags += "-extension local"
23
* native *)
34

45
external local_stack_offset : unit -> int = "caml_local_stack_offset"

testsuite/tests/typing-local/lifetime.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(* TEST *)
1+
(* TEST
2+
flags += "-extension local" *)
23

34
let final = ref false
45
let rtrue = ref true

testsuite/tests/typing-local/local.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(* TEST
2-
* expect
3-
*)
2+
flags += "-extension local"
3+
* expect *)
44

55
let leak n =
66
let r = local_ ref n in

testsuite/tests/typing-local/mutate.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(* TEST *)
1+
(* TEST
2+
flags += "-extension local" *)
23
let[@inline never] f (g : local_ _ -> unit) n =
34
let r = local_ { contents = ref 0 } in
45
g r;

testsuite/tests/typing-local/partial.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(* TEST
2-
flags += " -g " *)
2+
flags += " -g -extension local" *)
33

44
let f1 ~a ~b ~c ~d ~e = a + b + c + d + e
55
let f2 ~b ~c ~e = f1 ~b ~c ~e

testsuite/tests/typing-local/print_syntax.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
let () =
88
let fname = "example_syntax.ml" in
9+
Clflags.Extension.enable "local";
910
let ic = open_in fname in
1011
let lexbuf = Lexing.from_channel ic in
1112
Location.init lexbuf fname;

testsuite/tests/typing-local/regions.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(* TEST
2+
flags += "-extension local"
23
* native *)
34

45
external local_stack_offset : unit -> int = "caml_local_stack_offset"

testsuite/tests/typing-local/tailcalls.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(* TEST
2+
flags += "-extension local"
23
* native *)
34

45
open Printexc

typing/typecore.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,11 @@ let register_allocation (expected_mode : expected_mode) =
367367
(Value_mode.regional_to_global_alloc expected_mode.mode)
368368

369369
let optimise_allocations () =
370-
List.iter
371-
(fun mode -> ignore (Alloc_mode.constrain_upper mode))
372-
!allocations;
370+
if Clflags.Extension.is_enabled Local then begin
371+
List.iter
372+
(fun mode -> ignore (Alloc_mode.constrain_upper mode))
373+
!allocations
374+
end;
373375
reset_allocations ()
374376

375377
(* Typing of constants *)

utils/clflags.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,21 +376,23 @@ let set_dumped_pass s enabled =
376376
end
377377

378378
module Extension = struct
379-
type t = Comprehensions
379+
type t = Comprehensions | Local
380380

381-
let all = [ Comprehensions ]
381+
let all = [ Comprehensions; Local ]
382382

383383
let extensions = ref ([] : t list) (* -extension *)
384-
let equal Comprehensions Comprehensions = true
384+
let equal (a : t) (b : t) = (a = b)
385385

386386
let disable_all_extensions = ref false (* -disable-all-extensions *)
387387
let disable_all () = disable_all_extensions := true
388388

389389
let to_string = function
390390
| Comprehensions -> "comprehensions"
391+
| Local -> "local"
391392

392393
let of_string = function
393394
| "comprehensions" -> Comprehensions
395+
| "local" -> Local
394396
| extn -> raise (Arg.Bad(Printf.sprintf "Extension %s is not known" extn))
395397

396398
let enable extn =

utils/clflags.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ val set_dumped_pass : string -> bool -> unit
202202
val dump_into_file : bool ref
203203

204204
module Extension : sig
205-
type t = Comprehensions
205+
type t = Comprehensions | Local
206206
val enable : string -> unit
207207
val is_enabled : t -> bool
208208
val to_string : t -> string

0 commit comments

Comments
 (0)