Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reroute legacy immediate support for jkinds #1907

Merged
merged 46 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
65c6399
Change parsetree layouts to strings
ncik-roberts Sep 29, 2023
5f1e6c3
make depend
ncik-roberts Oct 3, 2023
e454d29
Striate jkind annotations from attributes
ncik-roberts Oct 3, 2023
993cb2f
Restore check and add test that `type t : unboxed` isn't allowed
ncik-roberts Oct 3, 2023
42113b1
Fix build
ncik-roberts Oct 5, 2023
aaac3aa
Main changes
ncik-roberts Oct 4, 2023
0bf4f76
Restore a similar behavior to [legacy_immediate]
ncik-roberts Oct 4, 2023
45330e6
Change tests to not use `[@@void]`, `[@@value]`, etc.
ncik-roberts Oct 4, 2023
80fa08f
Change tests to use new error message
ncik-roberts Oct 4, 2023
a8d5366
Disallow multiple sources of jkind
ncik-roberts Oct 4, 2023
99e48fd
Rename `legacy_immediate` to `is_type_decl`
ncik-roberts Oct 4, 2023
e069ab0
`make bootstrap`
ncik-roberts Oct 5, 2023
8bd58ec
Minor changes suggested in review
ncik-roberts Nov 2, 2023
257142d
More minor changes suggested in review
ncik-roberts Nov 2, 2023
27a6a97
More minor changes suggested in review
ncik-roberts Nov 2, 2023
1a6554e
Update ocaml/typing/jkind.ml
ncik-roberts Nov 2, 2023
8d878af
Revert change that I can't explain
ncik-roberts Nov 2, 2023
b0c3e92
Merge remote-tracking branch 'origin/nroberts/layouts-are-strings-in-…
ncik-roberts Nov 2, 2023
b70b61f
Store both typed/untyped jkind annotation in typedtree, and delete `c…
ncik-roberts Nov 2, 2023
9f9809c
Remove misleading comment
ncik-roberts Nov 2, 2023
dac6448
Add CRs for doubling-down on backward-incompatible change
ncik-roberts Nov 2, 2023
48ff923
Update ocaml/typing/types.mli
ncik-roberts Nov 2, 2023
18811e1
Make predefs less confusing if printed
ncik-roberts Nov 2, 2023
88cb0bf
Merge branch 'nroberts/layouts-are-strings-in-parsetree' into nrobert…
ncik-roberts Nov 2, 2023
6cb081e
Resolve merge conflicts and fix build
ncik-roberts Nov 2, 2023
5febf29
Remove obviated module
ncik-roberts Nov 2, 2023
2cf3307
Add missing case to comment
ncik-roberts Nov 2, 2023
9513267
Drop the needless is_type_decl param
ncik-roberts Nov 2, 2023
9ccf2a8
Split Location argument into its components
ncik-roberts Nov 3, 2023
2b55486
Remove no-longer-necessary builtin attrs
ncik-roberts Nov 3, 2023
ff20c84
make depend
ncik-roberts Nov 3, 2023
f80a089
Layout annotations in untypeast
ncik-roberts Nov 3, 2023
ad661f0
Merge remote-tracking branch 'origin/main' into nroberts/layouts-are-…
ncik-roberts Nov 3, 2023
64711b5
Resolve merge conflicts and update whitespace in tests
ncik-roberts Nov 3, 2023
6966628
Merge branch 'nroberts/layouts-are-strings-in-parsetree' into nrobert…
ncik-roberts Nov 3, 2023
783b618
Fix merge conflicts
ncik-roberts Nov 6, 2023
42c9c53
make {depend,boot,parser}
ncik-roberts Nov 7, 2023
9dc1246
Merge branch 'main' into nroberts/jane-syntax-for-layouts
ncik-roberts Nov 7, 2023
f1d53a8
Resolve merge conflicts due to squash+merge
ncik-roberts Nov 8, 2023
4e928f7
Fix tests broken by error message change
ncik-roberts Nov 8, 2023
d28f3c1
Resolve merge conflicts in typing-layouts-float64
ncik-roberts Nov 8, 2023
0a6697c
make fmt
ncik-roberts Nov 8, 2023
7501070
Remove test unintentionally added back in the merge
ncik-roberts Nov 8, 2023
5b2bd0c
Collapse *_beta versions of layouts tests with their stable versions …
ncik-roberts Nov 8, 2023
5b4f845
git rm files that I intended to remove in 5b2bd0c2
ncik-roberts Nov 8, 2023
d160a95
Suggestion from review
ncik-roberts Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Change parsetree layouts to strings
  • Loading branch information
ncik-roberts committed Oct 3, 2023
commit 65c63992355841f32c3b25e050af72c2218d6662
16,467 changes: 8,214 additions & 8,253 deletions ocaml/boot/menhir/parser.ml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ocaml/compilerlibs/Makefile.compilerlibs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ PARSING = \
parsing/printast.cmo \
parsing/syntaxerr.cmo \
parsing/ast_helper.cmo \
parsing/jane_asttypes.cmo \
parsing/jane_syntax_parsing.cmo parsing/jane_syntax.cmo \
parsing/pprintast.cmo \
parsing/ast_iterator.cmo \
Expand All @@ -77,7 +78,6 @@ PARSING = \
parsing/depend.cmo
PARSING_CMI = \
parsing/asttypes.cmi \
parsing/jane_asttypes.cmi \
parsing/parsetree.cmi

TYPING = \
Expand Down
2 changes: 1 addition & 1 deletion ocaml/dune
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
(ocamlopt_flags (:include %{project_root}/ocamlopt_flags.sexp))
(library_flags -linkall)
(modules_without_implementation
annot asttypes jane_asttypes cmo_format outcometree parsetree debug_event)
annot asttypes cmo_format outcometree parsetree debug_event)
(modules
;; UTILS
config build_path_prefix_map misc identifiable numbers arg_helper clflags
Expand Down
2 changes: 1 addition & 1 deletion ocaml/otherlibs/dynlink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ NATOBJS=dynlink_compilerlibs.cmx dynlink_types.cmx \
# .mli files from compilerlibs that don't have a corresponding .ml file.
COMPILERLIBS_INTFS=\
parsing/asttypes.mli \
parsing/jane_asttypes.mli \
parsing/parsetree.mli \
typing/outcometree.mli \
file_formats/cmo_format.mli \
Expand Down Expand Up @@ -102,6 +101,7 @@ COMPILERLIBS_SOURCES=\
parsing/printast.ml \
parsing/syntaxerr.ml \
parsing/ast_helper.ml \
parsing/jane_asttypes.ml \
parsing/jane_syntax_parsing.ml \
parsing/jane_syntax.ml \
parsing/ast_iterator.ml \
Expand Down
8 changes: 5 additions & 3 deletions ocaml/otherlibs/dynlink/dune
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
docstrings
printast
syntaxerr
jane_asttypes
jane_syntax_parsing
jane_syntax
ast_iterator
Expand Down Expand Up @@ -77,7 +78,6 @@
meta
symtable
asttypes
jane_asttypes
parsetree
outcometree
cmo_format
Expand All @@ -89,7 +89,6 @@
linkage_name)
(modules_without_implementation
asttypes
jane_asttypes
parsetree
outcometree
cmo_format
Expand Down Expand Up @@ -134,6 +133,7 @@
(copy_files ../../parsing/docstrings.ml)
(copy_files ../../parsing/printast.ml)
(copy_files ../../parsing/syntaxerr.ml)
(copy_files ../../parsing/jane_asttypes.ml)
(copy_files ../../parsing/jane_syntax_parsing.ml)
(copy_files ../../parsing/jane_syntax.ml)
(copy_files ../../parsing/ast_iterator.ml)
Expand Down Expand Up @@ -194,6 +194,7 @@
(copy_files ../../parsing/docstrings.mli)
(copy_files ../../parsing/printast.mli)
(copy_files ../../parsing/syntaxerr.mli)
(copy_files ../../parsing/jane_asttypes.mli)
(copy_files ../../parsing/jane_syntax_parsing.mli)
(copy_files ../../parsing/jane_syntax.mli)
(copy_files ../../parsing/ast_iterator.mli)
Expand Down Expand Up @@ -228,7 +229,6 @@

; .mli-only:
(copy_files ../../parsing/asttypes.mli)
(copy_files ../../parsing/jane_asttypes.mli)
(copy_files ../../parsing/parsetree.mli)
(copy_files ../../typing/outcometree.mli)
(copy_files ../../file_formats/cmo_format.mli)
Expand Down Expand Up @@ -295,6 +295,7 @@
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Syntaxerr.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Lazy_backtrack.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Ast_helper.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Jane_asttypes.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Jane_syntax_parsing.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Jane_syntax.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Ast_iterator.cmo
Expand Down Expand Up @@ -370,6 +371,7 @@
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Printast.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Syntaxerr.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Ast_helper.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jane_asttypes.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jane_syntax_parsing.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jane_syntax.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Load_path.cmx
Expand Down
1 change: 1 addition & 0 deletions ocaml/parsing/.ocamlformat-enable
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ jane_syntax.ml
jane_syntax.mli
jane_syntax_parsing.ml
jane_syntax_parsing.mli
jane_asttypes.ml
jane_asttypes.mli
45 changes: 35 additions & 10 deletions ocaml/parsing/builtin_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
(**************************************************************************)

open Asttypes
open Jane_asttypes
open Parsetree
open Ast_helper

Expand Down Expand Up @@ -453,19 +452,45 @@ let warn_on_literal_pattern attrs =
let explicit_arity attrs =
has_attribute ["ocaml.explicit_arity"; "explicit_arity"] attrs

type jkind_annotation =
| Any
| Value
| Void
| Immediate64
| Immediate
| Float64

let jkind_of_string = function
| "ocaml.any" | "any" -> Some Any
| "ocaml.value" | "value" -> Some Value
| "ocaml.void" | "void" -> Some Void
| "ocaml.immediate64" | "immediate64" -> Some Immediate64
| "ocaml.immediate" | "immediate" -> Some Immediate
| "ocaml.float64" | "float64" -> Some Float64
| _ -> None

let jkind_to_string = function
| Any -> "any"
| Value -> "value"
| Void -> "void"
| Immediate64 -> "immediate64"
| Immediate -> "immediate"
| Float64 -> "float64"

let jkind_of_parsetree x =
jkind_of_string (Jane_asttypes.jkind_to_string x)

let jkind_to_parsetree x =
Jane_asttypes.jkind_of_string (jkind_to_string x)

let jkind ~legacy_immediate attrs =
let jkind =
List.find_map
(fun a ->
match a.attr_name.txt with
| "ocaml.void"|"void" -> Some (a, Void)
| "ocaml.value"|"value" -> Some (a, Value)
| "ocaml.any"|"any" -> Some (a, Any)
| "ocaml.immediate"|"immediate" -> Some (a, Immediate)
| "ocaml.immediate64"|"immediate64" -> Some (a, Immediate64)
| "ocaml.float64"|"float64" -> Some (a, Float64)
| _ -> None
) attrs
match jkind_of_string a.attr_name.txt with
| Some attr -> Some (a, attr)
| None -> None
) attrs
in
match jkind with
| None -> Ok None
Expand Down
14 changes: 12 additions & 2 deletions ocaml/parsing/builtin_attributes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ val has_unique: Parsetree.attributes -> (bool,unit) result

val has_once : Parsetree.attributes -> (bool, unit) result

type jkind_annotation =
| Any
| Value
| Void
| Immediate64
| Immediate
| Float64

val jkind_of_parsetree : Jane_asttypes.const_jkind -> jkind_annotation option
val jkind_to_parsetree : jkind_annotation -> Jane_asttypes.const_jkind

(* [jkind] gets the jkind in the attributes if one is present. We always
allow the [value] annotation, even if the layouts extensions are disabled.
If [~legacy_immediate] is true, we allow [immediate] and [immediate64]
Expand Down Expand Up @@ -207,5 +218,4 @@ val has_once : Parsetree.attributes -> (bool, unit) result
(* CR layouts: we should eventually be able to delete ~legacy_immediate (after we
turn on layouts by default). *)
val jkind : legacy_immediate:bool -> Parsetree.attributes ->
(Jane_asttypes.jkind_annotation option,
Jane_asttypes.jkind_annotation) result
(jkind_annotation Location.loc option, jkind_annotation Location.loc) result
27 changes: 27 additions & 0 deletions ocaml/parsing/jane_asttypes.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Antal Spector-Zabusky, Jane Street, New York *)
(* *)
(* Copyright 2023 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

open! Asttypes

type global_flag =
| Global
| Nothing

type const_jkind = string

let jkind_of_string x = x

let jkind_to_string x = x

type jkind_annotation = const_jkind Location.loc
23 changes: 11 additions & 12 deletions ocaml/parsing/jane_asttypes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@

*)

open Asttypes
open! Asttypes

type global_flag =
| Global
| Nothing

(* constant jkinds are parsed as jkind annotations, and also used
in the type checker as already-inferred (i.e. non-variable) jkinds *)
type const_jkind =
| Any
| Value
| Void
| Immediate64
| Immediate
| Float64

type jkind_annotation = const_jkind loc
(** [const_jkind] is private to limit confusion with type variables, which
are also strings in the parser.
*)
type const_jkind = private string

val jkind_of_string : string -> const_jkind

val jkind_to_string : const_jkind -> string

type jkind_annotation = const_jkind Location.loc
20 changes: 3 additions & 17 deletions ocaml/parsing/jane_syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -324,23 +324,9 @@ module Stringable_const_jkind = struct

let indefinite_article_and_name = "a", "layout"

let to_string = function
| Any -> "any"
| Value -> "value"
| Void -> "void"
| Immediate64 -> "immediate64"
| Immediate -> "immediate"
| Float64 -> "float64"

(* CR layouts v1.5: revise when moving jkind recognition away from parser *)
let of_string = function
| "any" -> Some Any
| "value" -> Some Value
| "void" -> Some Void
| "immediate" -> Some Immediate
| "immediate64" -> Some Immediate64
| "float64" -> Some Float64
| _ -> None
let to_string = jkind_to_string

let of_string t = Some (jkind_of_string t)
end

module Jkinds_pprint = struct
Expand Down
26 changes: 5 additions & 21 deletions ocaml/parsing/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -912,16 +912,6 @@ let mk_directive ~loc name arg =
pdir_loc = make_loc loc;
}

let check_jkind ~loc id : const_jkind =
match id with
| "any" -> Any
| "value" -> Value
| "void" -> Void
| "immediate64" -> Immediate64
| "immediate" -> Immediate
| "float64" -> Float64
| _ -> expecting_loc loc "layout"

(* Unboxed literals *)

(* CR layouts v2.5: The [unboxed_*] functions will both be improved and lose
Expand Down Expand Up @@ -1109,6 +1099,7 @@ let unboxed_float_type sloc tys =
%token PERCENT "%"
%token PLUS "+"
%token PLUSDOT "+."

%token PLUSEQ "+="
%token <string> PREFIXOP "!+" (* chosen with care; see above *)
%token PRIVATE "private"
Expand Down Expand Up @@ -3711,21 +3702,14 @@ type_parameters:
;

jkind_annotation: (* : jkind_annotation *)
ident { let loc = make_loc $sloc in
mkloc (check_jkind ~loc $1) loc }
;

jkind_string: (* : string with_loc *)
(* the [check_jkind] just ensures this is the name of a jkind *)
ident { let loc = make_loc $sloc in
ignore (check_jkind ~loc $1 : const_jkind);
mkloc $1 loc }
ident { mkloc (Jane_asttypes.jkind_of_string $1) (make_loc $sloc) }
;

jkind_attr:
COLON
jkind=jkind_string
{ Attr.mk ~loc:jkind.loc jkind (PStr []) }
jkind=ident
{ let jkind = mkloc jkind (make_loc $loc(jkind)) in
Attr.mk ~loc:jkind.loc jkind (PStr []) }
;

%inline type_param_with_jkind:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Error: Layout void is more experimental than allowed by -extension layouts.
Line 2, characters 11-15:
2 | type ('a : valu) t0 = 'a list;;
^^^^
Error: Syntax error: layout expected.
Error: Unknown layout valu
Line 2, characters 9-15:
2 | type t = float#;;
^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Error: This type ('a : value) should be an instance of type ('a0 : void)
Line 2, characters 11-15:
2 | type ('a : valu) t0 = 'a list;;
^^^^
Error: Syntax error: layout expected.
Error: Unknown layout valu
type t = float#
Line 2, characters 9-13:
2 | type t = int#;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Error: Layout void is more experimental than allowed by -extension layouts_beta.
Line 2, characters 11-15:
2 | type ('a : valu) t0 = 'a list;;
^^^^
Error: Syntax error: layout expected.
Error: Unknown layout valu
type t = float#
Line 2, characters 9-13:
2 | type t = int#;;
Expand Down
Loading