Skip to content

Commit 3d2cbc0

Browse files
authored
Merge pull request #1199 from cryspen/rework-name-repr
Engine: rework global name representation
2 parents c7c611f + 051c4eb commit 3d2cbc0

File tree

80 files changed

+3682
-1908
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3682
-1908
lines changed

engine/backends/coq/coq/coq_backend.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ module AST = Ast.Make (InputLanguage)
6868
module BackendOptions = Backend.UnitBackendOptions
6969
open Ast
7070
module CoqNamePolicy = Concrete_ident.DefaultNamePolicy
71-
module U = Ast_utils.MakeWithNamePolicy (InputLanguage) (CoqNamePolicy)
71+
module U = Ast_utils.Make (InputLanguage)
72+
module RenderId = Concrete_ident.MakeRenderAPI (CoqNamePolicy)
7273
open AST
7374

7475
let hardcoded_coq_headers =
@@ -492,7 +493,7 @@ struct
492493
let crate =
493494
String.capitalize
494495
(Option.value ~default:"(TODO CRATE)"
495-
(Option.map ~f:fst current_namespace))
496+
(Option.bind ~f:List.hd current_namespace))
496497
in
497498
let concat_capitalize l =
498499
String.concat ~sep:"_" (List.map ~f:String.capitalize l)
@@ -509,7 +510,7 @@ struct
509510
(crate
510511
:: List.drop_last_exn
511512
(Option.value ~default:[]
512-
(Option.map ~f:snd current_namespace))
513+
(Option.bind ~f:List.tl current_namespace))
513514
@ xs)
514515
| [ a ] -> a
515516
| xs -> concat_capitalize_include xs
@@ -729,7 +730,7 @@ struct
729730

730731
method concrete_ident ~local:_ id : document =
731732
string
732-
(match id.definition with
733+
(match id.name with
733734
| "not" -> "negb"
734735
| "eq" -> "t_PartialEq_f_eq"
735736
| "lt" -> "t_PartialOrd_f_lt"
@@ -765,12 +766,13 @@ let translate m _ ~bundles:_ (items : AST.item list) : Types.file list =
765766
let my_printer = make m in
766767
U.group_items_by_namespace items
767768
|> Map.to_alist
769+
|> List.filter_map ~f:(fun (_, items) ->
770+
let* first_item = List.hd items in
771+
Some ((RenderId.render first_item.ident).path, items))
768772
|> List.map ~f:(fun (ns, items) ->
769773
let mod_name =
770774
String.concat ~sep:"_"
771-
(List.map
772-
~f:(map_first_letter String.uppercase)
773-
(fst ns :: snd ns))
775+
(List.map ~f:(map_first_letter String.uppercase) ns)
774776
in
775777
let sourcemap, contents =
776778
let annotated = my_printer#entrypoint_modul items in

engine/backends/coq/ssprove/ssprove_backend.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ module AST = Ast.Make (InputLanguage)
7474
module BackendOptions = Backend.UnitBackendOptions
7575
open Ast
7676
module CoqNamePolicy = Concrete_ident.DefaultNamePolicy
77-
module U = Ast_utils.MakeWithNamePolicy (InputLanguage) (CoqNamePolicy)
77+
module U = Ast_utils.Make (InputLanguage)
78+
module RenderId = Concrete_ident.MakeRenderAPI (CoqNamePolicy)
7879
open AST
7980

8081
module SSProveLibrary : Library = struct
@@ -553,7 +554,7 @@ end
553554

554555
module Context = struct
555556
type t = {
556-
current_namespace : string * string list;
557+
current_namespace : string list;
557558
analysis_data : StaticAnalysis.analysis_data;
558559
}
559560
end
@@ -618,10 +619,10 @@ module TransformToInputLanguage (* : PHASE *) =
618619
(* | None -> Error.unimplemented ~details:err span *)
619620

620621
let pconcrete_ident (id : Ast.concrete_ident) : string =
621-
U.Concrete_ident_view.to_definition_name id
622+
(RenderId.render id).name
622623

623624
let plocal_ident (e : Local_ident.t) : string =
624-
U.Concrete_ident_view.local_ident
625+
RenderId.local_ident
625626
(match String.chop_prefix ~prefix:"impl " e.name with
626627
| Some name ->
627628
let name = "impl_" ^ Int.to_string ([%hash: string] name) in
@@ -690,7 +691,7 @@ struct
690691
| Bool b -> SSP.AST.Const_bool b
691692

692693
let operators =
693-
let c = Ast.Global_ident.of_name Value in
694+
let c = Ast.Global_ident.of_name ~value:true in
694695
[
695696
(c Rust_primitives__hax__array_of_list, (3, [ ""; ".a["; "]<-"; "" ]));
696697
(c Core__ops__index__Index__index, (2, [ ""; ".a["; "]" ]));
@@ -1556,8 +1557,8 @@ struct
15561557
let id = [%show: concrete_ident] macro in
15571558
Error.raise { kind = UnsupportedMacro { id }; span = e.span }
15581559
in
1559-
match U.Concrete_ident_view.to_view macro with
1560-
| { crate = "hacspec_lib"; path = _; definition = name } -> (
1560+
match RenderId.render macro with
1561+
| { path = "hacspec_lib" :: _; name } -> (
15611562
match name with
15621563
| "public_nat_mod" ->
15631564
let open Hacspeclib_macro_parser in
@@ -1713,7 +1714,7 @@ struct
17131714
| _ -> unsupported ())
17141715
| _ -> unsupported ())
17151716
| Use { path; is_external; rename } ->
1716-
let _ns_crate, _ns_path = ctx.current_namespace in
1717+
let _ns_path = ctx.current_namespace in
17171718
if is_external then []
17181719
else
17191720
[ SSP.AST.Require (None, (* ns_crate:: ns_path @ *) path, rename) ]
@@ -1989,10 +1990,7 @@ let print_item (analysis_data : StaticAnalysis.analysis_data) (item : AST.item)
19891990
: SSP.AST.decl list =
19901991
let (module Print) =
19911992
make
1992-
{
1993-
current_namespace = U.Concrete_ident_view.to_namespace item.ident;
1994-
analysis_data;
1995-
}
1993+
{ current_namespace = (RenderId.render item.ident).path; analysis_data }
19961994
in
19971995
Print.pitem item
19981996

@@ -2422,12 +2420,14 @@ let translate _ (_bo : BackendOptions.t) ~(bundles : AST.item list list)
24222420
let analysis_data = StaticAnalysis.analyse items in
24232421
U.group_items_by_namespace items
24242422
|> Map.to_alist
2423+
|> List.filter_map
2424+
~f:
2425+
(snd >> List.hd
2426+
>> Option.map ~f:(fun i -> ((RenderId.render i.ident).path, items)))
24252427
|> List.map ~f:(fun (ns, items) ->
24262428
let mod_name =
24272429
String.concat ~sep:"_"
2428-
(List.map
2429-
~f:(map_first_letter String.uppercase)
2430-
(fst ns :: snd ns))
2430+
(List.map ~f:(map_first_letter String.uppercase) ns)
24312431
in
24322432
let file_content =
24332433
hardcoded_coq_headers ^ "\n"

engine/backends/easycrypt/easycrypt_backend.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ include
2222
module BackendOptions = Backend.UnitBackendOptions
2323
module AST = Ast.Make (InputLanguage)
2424
module ECNamePolicy = Concrete_ident.DefaultNamePolicy
25-
module U = Ast_utils.MakeWithNamePolicy (InputLanguage) (ECNamePolicy)
25+
module U = Ast_utils.Make (InputLanguage)
26+
module RenderId = Concrete_ident.MakeRenderAPI (ECNamePolicy)
2627
open AST
2728

2829
module RejectNotEC (FA : Features.T) = struct
@@ -88,14 +89,11 @@ module NM = struct
8889

8990
{ the with subnms = Map.Poly.update ~f:update the.subnms name }
9091

91-
let push_using_namespace (the : nmtree) (nm : string * string list)
92-
(item : AST.item) =
93-
push_using_longname the (List.rev (fst nm :: snd nm)) item
92+
let push_using_namespace (the : nmtree) (nm : string list) (item : AST.item) =
93+
push_using_longname the (List.rev nm) item
9494

9595
let push (the : nmtree) (item : AST.item) =
96-
push_using_namespace the
97-
(U.Concrete_ident_view.to_namespace item.ident)
98-
item
96+
push_using_namespace the (RenderId.render item.ident).path item
9997
end
10098

10199
let suffix_of_size (size : Ast.size) =
@@ -132,7 +130,7 @@ let translate' (_bo : BackendOptions.t) (items : AST.item list) :
132130
match item.v with
133131
| Fn { name; generics; body; params }
134132
when List.is_empty generics.params ->
135-
let name = U.Concrete_ident_view.to_definition_name name in
133+
let name = (RenderId.render name).name in
136134

137135
doit_fn fmt (name, params, body)
138136
| Fn _ -> assert false
@@ -166,7 +164,7 @@ let translate' (_bo : BackendOptions.t) (items : AST.item list) :
166164
pp_param)
167165
params doit_stmt body
168166
and doit_concrete_ident (fmt : Formatter.t) (p : Concrete_ident.t) =
169-
Stdlib.Format.fprintf fmt "%s" (U.Concrete_ident_view.to_definition_name p)
167+
Stdlib.Format.fprintf fmt "%s" (RenderId.render p).name
170168
and doit_type (fmt : Formatter.t) (typ : ty) =
171169
match typ with
172170
| TBool -> assert false
@@ -281,7 +279,7 @@ let translate' (_bo : BackendOptions.t) (items : AST.item list) :
281279
|| eq_name Core__cmp__PartialEq__ne op
282280
|| eq_name Core__cmp__PartialEq__eq op) ->
283281
Stdlib.Format.fprintf fmt "(%a) %s (%a)" doit_expr e1
284-
(match U.Concrete_ident_view.to_definition_name op with
282+
(match (RenderId.render op).name with
285283
| "bitxor" -> "^"
286284
| "bitand" -> "&"
287285
| "bitor" -> "|"

0 commit comments

Comments
 (0)