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

[ProVerif] Renaming / AST transformation pseudophase #728

Closed
wants to merge 5 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions engine/backends/proverif/proverif_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ include
let backend = Diagnostics.Backend.ProVerif
end)

module ConcreteIdentMap = Map.M (Concrete_ident_generated)

let rename_map =
Map.of_alist_exn
(module Concrete_ident_generated)
Concrete_ident_generated.[ (Core__option__Option, "Option") ]

module SubtypeToInputLanguage
(FA : Features.T
(* type loop = Features.Off.loop *)
Expand Down Expand Up @@ -641,13 +648,19 @@ module Make (Options : OPTS) : MAKE = struct

method! concrete_ident' ~(under_current_ns : bool) : concrete_ident fn =
fun id ->
if under_current_ns then print#name_of_concrete_ident id
else
let crate, path = print#namespace_of_concrete_ident id in
let full_path = crate :: path in
separate_map (underscore ^^ underscore) utf8string full_path
^^ underscore ^^ underscore
^^ print#name_of_concrete_ident id
match
List.find (Map.to_alist rename_map) ~f:(fun (name, _) ->
Concrete_ident.eq_name name id)
with
| Some (_, plain_name) -> string plain_name
| _ ->
if under_current_ns then print#name_of_concrete_ident id
else
let crate, path = print#namespace_of_concrete_ident id in
let full_path = crate :: path in
separate_map (underscore ^^ underscore) utf8string full_path
^^ underscore ^^ underscore
^^ print#name_of_concrete_ident id

method! doc_construct_inductive
: is_record:bool ->
Expand Down Expand Up @@ -729,17 +742,6 @@ module Make (Options : OPTS) : MAKE = struct
| TApp { ident; args }
when Global_ident.eq_name Alloc__vec__Vec ident ->
string "bitstring"
| TApp { ident; args }
when Global_ident.eq_name Core__option__Option ident ->
string "Option"
| TApp { ident; args }
when Global_ident.eq_name Core__result__Result ident -> (
(* print first of args*)
let result_ok_type = List.hd_exn args in
match result_ok_type with
| GType typ -> print#ty ctx typ
| GConst e -> print#expr ctx e
| _ -> empty (* Do not tranlsate lifetimes *))
| TApp { ident; args } -> super#ty ctx ty
(*(
match translate_known_name ident ~dict:library_types with
Expand Down Expand Up @@ -864,6 +866,33 @@ module Make (Options : OPTS) : MAKE = struct
end)
end

module ProVerifRename (F : Features.T) =
Phase_utils.MakeMonomorphicPhase
(F)
(struct
module Visitors = Ast_visitors.Make (F)
open Ast.Make (F)

let visitor =
object (self)
inherit [_] Visitors.map as super

method! visit_ty () (ty : ty) =
match super#visit_ty () ty with
| TApp { ident; args = [ GType typ; _ ] }
when Global_ident.eq_name Core__result__Result ident ->
typ
| TApp { ident; args }
when Map.existsi rename_map ~f:(fun ~key ~data:_ ->
Global_ident.eq_name key ident) ->
TApp { ident; args = [] }
| x -> x
end

let phase_id = Diagnostics.Phase.ProVerifRename
let ditems = List.map ~f:(visitor#visit_item ())
end)

let translate m (bo : BackendOptions.t) (items : AST.item list) :
Types.file list =
let (module M : MAKE) =
Expand Down Expand Up @@ -904,6 +933,7 @@ module TransformToInputLanguage =
|> Phases.Local_mutation
|> Phases.Reject.Continue
|> Phases.Reject.Dyn
|> ProVerifRename
|> SubtypeToInputLanguage
|> Identity
]
Expand Down
1 change: 1 addition & 0 deletions engine/lib/diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module Phase = struct
| DropNeedlessReturns
| TransformHaxLibInline
| NewtypeAsRefinement
| ProVerifRename
| DummyA
| DummyB
| DummyC
Expand Down
Loading