Skip to content

Commit

Permalink
Remove nonlocal_ modality (#1452)
Browse files Browse the repository at this point in the history
* remove `nonlocal_` modality

* bootstrap

* address review comments
  • Loading branch information
riaqn authored Jun 12, 2023
1 parent b6f3fc7 commit 1aa0b8c
Show file tree
Hide file tree
Showing 28 changed files with 6,683 additions and 7,443 deletions.
13,194 changes: 6,425 additions & 6,769 deletions ocaml/boot/menhir/parser.ml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ocaml/boot/menhir/parser.mli
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type token =
| OF
| OBJECT
| NONREC
| NONLOCAL
| NEW
| MUTABLE
| MODULE
Expand Down
Binary file modified ocaml/boot/ocamlc
Binary file not shown.
Binary file modified ocaml/boot/ocamllex
Binary file not shown.
1 change: 0 additions & 1 deletion ocaml/parsing/asttypes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type closed_flag = Closed | Open

type global_flag =
| Global
| Nonlocal
| Nothing

(* constant layouts are parsed as layout annotations, and also used
Expand Down
4 changes: 0 additions & 4 deletions ocaml/parsing/builtin_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ let builtin_attrs =
; "local_opt"; "ocaml.local_opt"
; "curry"; "ocaml.curry"; "extension.curry"
; "global"; "ocaml.global"; "extension.global"
; "nonlocal"; "ocaml.nonlocal"; "extension.nonlocal"
; "local"; "ocaml.local"; "extension.local"
; "nontail"; "ocaml.nontail"; "extension.nontail"
; "tail"; "ocaml.tail"; "extension.tail"
Expand Down Expand Up @@ -634,9 +633,6 @@ let has_local attr =
let has_global attrs =
check_local ["extension.global"] ["ocaml.global"; "global"] attrs

let has_nonlocal attrs =
check_local ["extension.nonlocal"] ["ocaml.nonlocal"; "nonlocal"] attrs

let tailcall attr =
let has_nontail = has_attribute ["ocaml.nontail"; "nontail"] attr in
let tail_attrs = filter_attributes [["ocaml.tail";"tail"], true] attr in
Expand Down
1 change: 0 additions & 1 deletion ocaml/parsing/builtin_attributes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ val has_curry: Parsetree.attributes -> bool
are present despite the extension being disabled *)
val has_local: Parsetree.attributes -> (bool,unit) result
val has_global: Parsetree.attributes -> (bool,unit) result
val has_nonlocal: Parsetree.attributes -> (bool,unit) result
val tailcall : Parsetree.attributes ->
([`Tail|`Nontail|`Tail_if_possible] option, [`Conflict]) result

Expand Down
2 changes: 1 addition & 1 deletion ocaml/parsing/jane_syntax.mli
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ module Core_type : sig
end

(** Novel syntax in constructor arguments; this isn't a core AST type,
but captures where [global_] and [nonlocal_] live *)
but captures where [global_] lives *)
module Constructor_argument : sig
type t = |

Expand Down
1 change: 0 additions & 1 deletion ocaml/parsing/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ let keyword_table =
"module", MODULE;
"mutable", MUTABLE;
"new", NEW;
"nonlocal_", NONLOCAL;
"nonrec", NONREC;
"object", OBJECT;
"of", OF;
Expand Down
17 changes: 0 additions & 17 deletions ocaml/parsing/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,20 @@ let global_loc loc = mkloc "extension.global" loc
let global_attr loc =
mk_attr ~loc:loc (global_loc loc) (PStr [])

let nonlocal_loc loc = mkloc "extension.nonlocal" loc

let nonlocal_attr loc =
mk_attr ~loc:Location.none (nonlocal_loc loc) (PStr [])

let mkld_global ld loc =
{ ld with pld_attributes = global_attr loc :: ld.pld_attributes }

let mkld_nonlocal ld loc =
{ ld with pld_attributes = nonlocal_attr loc :: ld.pld_attributes }

let mkld_global_maybe gbl ld loc =
match gbl with
| Global -> mkld_global ld loc
| Nonlocal -> mkld_nonlocal ld loc
| Nothing -> ld

let mkcty_global cty loc =
{ cty with ptyp_attributes = global_attr loc :: cty.ptyp_attributes }

let mkcty_nonlocal cty loc =
{ cty with ptyp_attributes = nonlocal_attr loc :: cty.ptyp_attributes }

let mkcty_global_maybe gbl cty loc =
match gbl with
| Global -> mkcty_global cty loc
| Nonlocal -> mkcty_nonlocal cty loc
| Nothing -> cty

(* TODO define an abstraction boundary between locations-as-pairs
Expand Down Expand Up @@ -935,7 +922,6 @@ let mkpat_jane_syntax
%token MODULE "module"
%token MUTABLE "mutable"
%token NEW "new"
%token NONLOCAL "nonlocal_"
%token NONREC "nonrec"
%token OBJECT "object"
%token OF "of"
Expand Down Expand Up @@ -4203,12 +4189,10 @@ mutable_or_global_flag:
/* empty */ { Immutable, Nothing }
| MUTABLE { Mutable, Nothing }
| GLOBAL { Immutable, Global }
| NONLOCAL { Immutable, Nonlocal }
;
%inline global_flag:
{ Nothing }
| GLOBAL { Global }
| NONLOCAL { Nonlocal }
;
virtual_flag:
/* empty */ { Concrete }
Expand Down Expand Up @@ -4289,7 +4273,6 @@ single_attr_id:
| FUN { "fun" }
| FUNCTION { "function" }
| FUNCTOR { "functor" }
| NONLOCAL { "nonlocal_" }
| IF { "if" }
| IN { "in" }
| INCLUDE { "include" }
Expand Down
3 changes: 1 addition & 2 deletions ocaml/parsing/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1673,14 +1673,13 @@ and record_declaration ctxt f lbls =
in
let field_flag f pld =
pp f "%a" mutable_flag pld.pld_mutable;
if has_attr pld "extension.nonlocal" then pp f "nonlocal_ ";
if has_attr pld "extension.global" then pp f "global_ "
in
let type_record_field f pld =
let pld_attributes =
List.filter (fun attr ->
match attr.attr_name.txt with
| "extension.nonlocal" | "extension.global" -> false
| "extension.global" -> false
| _ -> true) pld.pld_attributes
in
pp f "@[<2>%a%s:@;%a@;%a@]"
Expand Down
1 change: 0 additions & 1 deletion ocaml/testsuite/tests/typing-local/example_syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let f () =
local_ "asdfasdfasdfasdfasdfasdfasdf"
type 'a r = {
mutable a: 'a ;
nonlocal_ b: 'a ;
global_ c: 'a }
type ('a, 'b) cfn =
a:local_ 'a -> ?b:local_ b -> local_ 'a -> (int -> local_ 'b)
17 changes: 3 additions & 14 deletions ocaml/testsuite/tests/typing-local/exclave.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,17 @@ Line 3, characters 4-17:
Error: Exclave expression should only be in tail position of the current region
|}]

type t = { nonlocal_ x : int option }
type t = { x : int option }

let foo (local_ x) =
let __ = { x } in
let _ = { x } in
exclave_ x

[%%expect{|
type t = { nonlocal_ x : int option; }
type t = { x : int option; }
val foo : local_ int option -> local_ int option = <fun>
|}]

let foo (local_ x) =
let _ = { x } in
exclave_ { x }

[%%expect{|
Line 3, characters 13-14:
3 | exclave_ { x }
^
Error: This local value escapes its region
|}]

(* semantics tests *)

type data = {mutable a : string}
Expand Down
Loading

0 comments on commit 1aa0b8c

Please sign in to comment.