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

Ocaml 4.14 #217

Open
wants to merge 15 commits into
base: ocaml-4.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
os:
- ubuntu-latest
ocaml-version:
- 4.13.1
- 4.14.0
coq-version:
- 8.13.2
- 8.14.1
Expand All @@ -39,7 +39,7 @@ jobs:
with:
ocaml-version: ${{ matrix.ocaml-version }}

- run: opam install ocamlformat.0.22.4
- run: opam install ocamlformat.0.24.1
- run: opam exec -- make fmt-check
- run: opam pin add coq ${{ matrix.coq-version }}
- run: opam pin add coq-of-ocaml.dev . --no-action
Expand Down
5 changes: 0 additions & 5 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.22.4
version=0.24.1
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,7 @@ opam pin add https://github.com/clarus/coq-of-ocaml.git#master
```

### Build manually
Clone the Git submodule for [Merlin](https://github.com/ocaml/merlin):
```
git submodule init
git submodule update
```
Then read the `coq-of-ocaml.opam` file at the root of the project to know the dependencies to install and get the list of commands to build the project.
Read the `coq-of-ocaml.opam` file at the root of the project to know the dependencies to install and get the list of commands to build the project.

## License
MIT (open-source software)
4 changes: 2 additions & 2 deletions coq-of-ocaml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ install: [
[make "-C" "proofs" "install"] {coq:installed}
]
depends: [
"angstrom"
"bisect_ppx" {dev & >= "2.5.0"}
"conf-ruby" {with-test}
"csexp"
"dune" {>= "2.9"}
"menhir" {dev}
"ocaml" {>= "4.13" & < "4.14"}
"ocaml" {>= "4.14" & < "4.15"}
"ocamlfind" {>= "1.5.2"}
"result"
"smart-print"
"yojson" {>= "1.6.0"}
"angstrom"
]
depopts: [
"coq"
Expand Down
6 changes: 3 additions & 3 deletions src/adtParameters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module AdtVariable = struct
| Parameter name | Index name -> Name.to_string name

let rec of_ocaml (typ : Types.type_expr) : t Monad.t =
match typ.Types.desc with
match Types.get_desc typ with
| Tvar x | Tunivar x -> (
match x with
| None | Some "_" -> return Unknown
Expand Down Expand Up @@ -78,8 +78,8 @@ let rec merge_typ_params (params1 : AdtVariable.t option list)
case of a non-GADT type. *)
let get_return_typ_params (defined_typ_params : t)
(return_typ : Types.type_expr option) : t Monad.t =
match return_typ with
| Some { Types.desc = Tconstr (_, typs, _); _ } -> of_ocaml typs
match Option.map Types.get_desc return_typ with
| Some (Tconstr (_, typs, _)) -> of_ocaml typs
| _ -> return defined_typ_params

let rec adt_parameters (defined_typ_params : AdtVariable.t option list)
Expand Down
35 changes: 18 additions & 17 deletions src/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
without_positivity_checking : bool;
}

let get_initial_loc (typedtree : Mtyper.typedtree) : Location.t =
let get_initial_loc (typedtree : Merlin_kernel.Mtyper.typedtree) : Location.t =
match typedtree with
| `Implementation structure -> (
match structure.str_items with
Expand Down Expand Up @@ -83,23 +83,24 @@
| _ :: _ ->
separate empty
(imports
|> List.map (fun { MonadEval.Import.base; import; mli; name } ->
let name_to_require = if mli then name ^ "_mli" else name in
nest
(!^"Require"
^^ (if import && not mli then !^"Import" else empty)
^^ !^base ^-^ !^"." ^-^ !^name_to_require ^-^ !^"."
^^
if mli then
|> List.map (fun { MonadEval.Import.import; mli } ->
(match import with
| Require (base, name) ->

Check warning on line 88 in src/ast.ml

View check run for this annotation

Codecov / codecov/patch

src/ast.ml#L86-L88

Added lines #L86 - L88 were not covered by tests
let name_to_require =
if mli then name ^ "_mli" else name

Check warning on line 90 in src/ast.ml

View check run for this annotation

Codecov / codecov/patch

src/ast.ml#L90

Added line #L90 was not covered by tests
in
nest
(!^"Module" ^^ !^name ^^ !^":=" ^^ !^name_to_require
^-^ !^".")
else empty)
^^ newline
^^
if import && mli then
nest (!^"Import" ^^ !^name ^-^ !^".") ^^ newline
else empty))
(!^"Require" ^^ !^base ^-^ !^"." ^-^ !^name_to_require
^-^ !^"."
^^

Check warning on line 95 in src/ast.ml

View check run for this annotation

Codecov / codecov/patch

src/ast.ml#L93-L95

Added lines #L93 - L95 were not covered by tests
if mli then
nest
(!^"Module" ^^ !^name ^^ !^":=" ^^ !^name_to_require
^-^ !^".")
else empty)
| RequireImport base ->
nest (!^"Require Import" ^^ !^base ^-^ !^"."))

Check warning on line 102 in src/ast.ml

View check run for this annotation

Codecov / codecov/patch

src/ast.ml#L97-L102

Added lines #L97 - L102 were not covered by tests
^^ newline))
^^ newline)
^^ (match ast.head_suffix with
| "" -> empty
Expand Down
68 changes: 67 additions & 1 deletion src/attribute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
| Cast
| ForceGadt
| GrabExistentials
| TaggedGadt
| Implicit of string * string
| IncludeWithout of string list
| MatchGadt
| MatchGadtWithResult
| MatchWithDefault
| MutualAsNotation
| Phantom
| PlainModule
| Struct of string
| TaggedGadt
| TaggedMatch
| TypAnnotation

Expand Down Expand Up @@ -75,6 +76,58 @@
("Expected two string parameters for this attribute.\n\n"
^ error_message)

let of_payload_strings (error_message : string) (id : string)
(payload : Parsetree.payload) : string list Monad.t =
match payload with
| Parsetree.PStr

Check warning on line 82 in src/attribute.ml

View check run for this annotation

Codecov / codecov/patch

src/attribute.ml#L81-L82

Added lines #L81 - L82 were not covered by tests
[
{
pstr_desc =
Pstr_eval
( { pexp_desc = Pexp_constant (Pconst_string (payload, _, _)); _ },
_ );
_;
};
] ->
return [ payload ]
| Parsetree.PStr

Check warning on line 93 in src/attribute.ml

View check run for this annotation

Codecov / codecov/patch

src/attribute.ml#L93

Added line #L93 was not covered by tests
[
{
pstr_desc =
Pstr_eval
( {
pexp_desc =
Pexp_apply
( {
pexp_desc = Pexp_constant (Pconst_string (head, _, _));
_;
},
arguments );
_;
},
_ );
_;
};
] ->
let* tail =
arguments
|> Monad.List.filter_map (fun argument ->
match argument with
| ( _,

Check warning on line 116 in src/attribute.ml

View check run for this annotation

Codecov / codecov/patch

src/attribute.ml#L114-L116

Added lines #L114 - L116 were not covered by tests
{
Parsetree.pexp_desc =
Pexp_constant (Pconst_string (payload, _, _));
_;
} ) ->
return (Some payload)
| _ -> raise None Unexpected error_message)

Check warning on line 123 in src/attribute.ml

View check run for this annotation

Codecov / codecov/patch

src/attribute.ml#L123

Added line #L123 was not covered by tests
in
return (head :: tail)
| _ ->

Check warning on line 126 in src/attribute.ml

View check run for this annotation

Codecov / codecov/patch

src/attribute.ml#L125-L126

Added lines #L125 - L126 were not covered by tests
raise [] Unexpected
("Expected at least one string parameter for this attribute.\n\n"
^ error_message)

let of_attributes (attributes : Typedtree.attributes) : t list Monad.t =
attributes
|> Monad.List.filter_map (fun { Parsetree.attr_name; attr_payload; _ } ->
Expand All @@ -101,6 +154,12 @@
of_payload_string_string error_message id attr_payload
in
return (Some (Implicit (name, typ)))
| "coq_include_without" ->

Check warning on line 157 in src/attribute.ml

View check run for this annotation

Codecov / codecov/patch

src/attribute.ml#L157

Added line #L157 was not covered by tests
let error_message =
"Give a list of item names not to include"
in
let* names = of_payload_strings error_message id attr_payload in
return (Some (IncludeWithout names))

Check warning on line 162 in src/attribute.ml

View check run for this annotation

Codecov / codecov/patch

src/attribute.ml#L161-L162

Added lines #L161 - L162 were not covered by tests
| "coq_match_gadt" -> return (Some MatchGadt)
| "coq_match_gadt_with_result" -> return (Some MatchGadtWithResult)
| "coq_match_with_default" -> return (Some MatchWithDefault)
Expand Down Expand Up @@ -140,6 +199,13 @@
| Implicit (name, typ) -> Some (name, typ)
| _ -> None)

let get_include_without (attributes : t list) : string list =
attributes
|> List.filter_map (function
| IncludeWithout exclude_list -> Some exclude_list
| _ -> None)

Check warning on line 206 in src/attribute.ml

View check run for this annotation

Codecov / codecov/patch

src/attribute.ml#L205-L206

Added lines #L205 - L206 were not covered by tests
|> List.concat

let has_match_gadt (attributes : t list) : bool =
attributes |> List.exists (function MatchGadt -> true | _ -> false)

Expand Down
30 changes: 15 additions & 15 deletions src/constant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@
*)
type parsed_string = PString of string | PChar of char | PDQuote

(** Kind of "good" printable characters
(according to the coq documentation). *)
let is_printable_ascii c = Char.code c >= 32 && c != '"'

(** Characters which may need special representation
(according to the coq documentation), except double quotes. *)
let non_printable_ascii c = Char.code c < 32
(** Kind of "good" printable characters (according to the coq documentation).
We do not assume the string to be in utf-8. *)
let is_printable_ascii c =
let code = Char.code c in
32 <= code && code < 128 && code <> Char.code '\n' && c <> '"'

(** Double qoutes char, special case for coq. *)
let dquote = Angstrom.map ~f:(fun _ -> PDQuote) (Angstrom.char '"')
Expand All @@ -61,11 +59,10 @@
(Angstrom.take_while1 is_printable_ascii)

(** Parser for Coq non-printable chars. *)
let nonprintable =
Angstrom.map ~f:(fun c -> PChar c) (Angstrom.satisfy non_printable_ascii)
let nonprintable = Angstrom.map ~f:(fun c -> PChar c) Angstrom.any_char

(** Parser for Coq string. *)
let parse_string_for_coq = many (printable <|> nonprintable <|> dquote)
let parse_string_for_coq = many (dquote <|> printable <|> nonprintable)

(** Just a wrapper. *)
let npchar c : SmartPrint.t =
Expand All @@ -77,17 +74,19 @@
| [] -> double_quotes !^""
| PChar c :: xs ->
let res = npchar c ^^ nest @@ to_coq_s true xs in
if need_parens then parens res else res
Pp.parens need_parens res
| PDQuote :: xs -> to_coq_s need_parens @@ (PString "\"\"" :: xs)
| PString s :: PDQuote :: xs ->
to_coq_s need_parens @@ (PString (s ^ "\"\"") :: xs)
| PString s1 :: PString s2 :: xs ->
to_coq_s need_parens @@ (PString (s1 ^ s2) :: xs)
| [ PString s ] -> double_quotes !^s
| PString s :: xs -> double_quotes !^s ^^ !^"++" ^^ nest @@ to_coq_s false xs
| PString s :: xs ->
Pp.parens need_parens
(double_quotes !^s ^^ !^"++" ^^ nest @@ to_coq_s false xs)

(** Pretty-print a constant to Coq. *)
let rec to_coq (c : t) : SmartPrint.t =
let rec to_coq (need_parens : bool) (c : t) : SmartPrint.t =
match c with
| Int n -> if n >= 0 then OCaml.int n else parens @@ OCaml.int n
| Char c ->
Expand All @@ -99,9 +98,10 @@
nest (double_quotes !^s ^^ !^"%" ^^ !^"char")
| String s -> (
match Angstrom.parse_string ~consume:All parse_string_for_coq s with
| Result.Ok xs -> nest @@ to_coq_s true xs
| Result.Ok xs -> nest @@ to_coq_s need_parens xs
| Result.Error _ ->
(* This should mean it is an empty string
(... or something else, but it should be a rare case). *)
double_quotes !^"")
| Warn (c, message) -> group (Error.to_comment message ^^ newline ^^ to_coq c)
| Warn (c, message) ->
group (Error.to_comment message ^^ newline ^^ to_coq need_parens c)

Check warning on line 107 in src/constant.ml

View check run for this annotation

Codecov / codecov/patch

src/constant.ml#L106-L107

Added lines #L106 - L107 were not covered by tests
1 change: 1 addition & 0 deletions src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(name coqOfOCaml)
(package coq-of-ocaml)
(flags
-open Merlin_kernel
-open Ocaml_parsing
-open Ocaml_typing)
(public_name coq-of-ocaml)
Expand Down
36 changes: 14 additions & 22 deletions src/exp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,11 @@

let rec get_include_name (module_expr : module_expr) : Name.t Monad.t =
match module_expr.mod_desc with
| Tmod_apply (applied_expr, _, _) -> (
match applied_expr.mod_desc with
| Tmod_ident (path, _)
| Tmod_constraint ({ mod_desc = Tmod_ident (path, _); _ }, _, _, _) ->
let* path_name = PathName.of_path_with_convert false path in
let* name = PathName.to_name false path_name in
return (Name.suffix_by_include name)
| _ -> get_include_name applied_expr)
| Tmod_ident (path, _) ->
let* path_name = PathName.of_path_with_convert false path in
let* name = PathName.to_name false path_name in
return (Name.suffix_by_include name)
| Tmod_apply (applied_expr, _, _) -> get_include_name applied_expr
| Tmod_constraint (module_expr, _, _, _) -> get_include_name module_expr
| _ ->
raise
Expand Down Expand Up @@ -1262,7 +1259,7 @@
(* Special case for functions whose type is given by a type
synonym at the end rather than with a type on each
parameter or an explicit arrow type. *)
match (vb_expr.exp_desc, vb_expr.exp_type.desc) with
match (vb_expr.exp_desc, Types.get_desc vb_expr.exp_type) with
| Texp_function _, Tconstr (path, _, _) -> (
match Env.find_type path vb_expr.exp_env with
| { type_manifest = Some ty; _ } -> ty
Expand Down Expand Up @@ -1312,18 +1309,11 @@
(cases : Typedtree.value_binding list) (e2 : t) : t Monad.t =
match cases with
| [
{
vb_pat =
{
pat_desc =
Tpat_construct
(_, { cstr_res = { desc = Tconstr (path, _, _); _ }; _ }, _, _);
_;
};
_;
};
{ vb_pat = { pat_desc = Tpat_construct (_, { cstr_res; _ }, _, _); _ }; _ };
]
when PathName.is_unit path ->
when match Types.get_desc cstr_res with
| Tconstr (path, _, _) -> PathName.is_unit path
| _ -> false ->

Check warning on line 1316 in src/exp.ml

View check run for this annotation

Codecov / codecov/patch

src/exp.ml#L1315-L1316

Added lines #L1315 - L1316 were not covered by tests
raise
(ErrorMessage (e2, "top_level_evaluation"))
SideEffect "Top-level evaluations are ignored"
Expand Down Expand Up @@ -1710,7 +1700,7 @@
set). *)
let rec to_coq (paren : bool) (e : t) : SmartPrint.t =
match e with
| Constant c -> Constant.to_coq c
| Constant c -> Constant.to_coq paren c
| Variable (x, implicits) -> (
let x = MixedPath.to_coq x in
match implicits with
Expand Down Expand Up @@ -1854,7 +1844,9 @@
let first_case = index = 0 in
(if first_case then
!^"let"
^^ if def.Definition.is_rec then !^"fix" else empty
^^
if def.Definition.is_rec && e <> None then !^"fix"
else empty
else if def.Definition.is_rec then !^"with"
else !^"in" ^^ !^"let")
^^ Name.to_coq header.Header.name
Expand Down
Loading
Loading