@@ -612,13 +612,6 @@ let rec extension_of_error {loc; msg; if_highlight; sub} =
612612 ]
613613 @ List. map (fun ext -> Str. extension (extension_of_error ext)) sub) )
614614
615- module String_map = Map. Make (struct
616- type t = string
617- let compare = compare
618- end )
619-
620- let cookies = ref String_map. empty
621-
622615module Ppx_context = struct
623616 open Longident
624617 open Asttypes
@@ -641,18 +634,6 @@ module Ppx_context = struct
641634 Exp. construct (lid " ::" ) (Location. mknoloc [f x; make_list f rest])
642635 | [] -> Exp. construct (lid " []" ) (Location. mknoloc [] )
643636
644- let make_pair f1 f2 (x1 , x2 ) = Exp. tuple [f1 x1; f2 x2]
645-
646- let get_cookies () =
647- {
648- lid = lid " cookies" ;
649- x =
650- make_list
651- (make_pair make_string (fun x -> x))
652- (String_map. bindings ! cookies);
653- opt = false ;
654- }
655-
656637 let mk fields =
657638 ( {txt = " ocaml.ppx.context" ; loc = Location. none},
658639 Parsetree. PStr [Str. eval (Exp. record fields None )] )
@@ -677,98 +658,24 @@ module Ppx_context = struct
677658 opt = false ;
678659 };
679660 {lid = lid " debug" ; x = make_bool ! Clflags. debug; opt = false };
680- get_cookies () ;
661+ (* The compiler doesn't read back the cookies a PPX sets. *)
662+ {lid = lid " cookies" ; x = make_list Fun. id [] ; opt = false };
681663 ]
682664 in
683665 mk fields
684-
685- let get_fields = function
686- | PStr
687- [{pstr_desc = Pstr_eval ({pexp_desc = Pexp_record (fields, None )}, [] )}]
688- ->
689- fields
690- | _ -> raise_errorf " Internal error: invalid [@@@ocaml.ppx.context] syntax"
691-
692- let restore fields =
693- let field name payload =
694- let rec get_string = function
695- | {pexp_desc = Pexp_constant (Pconst_string payload )} ->
696- String_literal. string_semantic payload
697- | _ ->
698- raise_errorf
699- " Internal error: invalid [@@@ocaml.ppx.context { %s }] string \
700- syntax"
701- name
702- and get_bool pexp =
703- match pexp with
704- | {
705- pexp_desc = Pexp_construct ({txt = Longident. Lident " true" }, {txt = [] });
706- } ->
707- true
708- | {
709- pexp_desc =
710- Pexp_construct ({txt = Longident. Lident " false" }, {txt = [] });
711- } ->
712- false
713- | _ ->
714- raise_errorf
715- " Internal error: invalid [@@@ocaml.ppx.context { %s }] bool syntax"
716- name
717- and get_list elem = function
718- | {
719- pexp_desc =
720- Pexp_construct ({txt = Longident. Lident " ::" }, {txt = [exp; rest]});
721- } ->
722- elem exp :: get_list elem rest
723- | {
724- pexp_desc =
725- Pexp_construct ({txt = Longident. Lident " []" }, {txt = [] });
726- } ->
727- []
728- | _ ->
729- raise_errorf
730- " Internal error: invalid [@@@ocaml.ppx.context { %s }] list syntax"
731- name
732- and get_pair f1 f2 = function
733- | {pexp_desc = Pexp_tuple [e1; e2]} -> (f1 e1, f2 e2)
734- | _ ->
735- raise_errorf
736- " Internal error: invalid [@@@ocaml.ppx.context { %s }] pair syntax"
737- name
738- in
739- match name with
740- | "include_dirs" -> Clflags. include_dirs := get_list get_string payload
741- | "load_path" -> Config. load_path := get_list get_string payload
742- | "open_modules" -> Clflags. open_modules := get_list get_string payload
743- | "debug" -> Clflags. debug := get_bool payload
744- | "cookies" ->
745- let l = get_list (get_pair get_string (fun x -> x)) payload in
746- cookies :=
747- List. fold_left
748- (fun s (k , v ) -> String_map. add k v s)
749- String_map. empty l
750- | _ -> ()
751- in
752- List. iter
753- (function
754- | {lid = {txt = Lident name } ; x} -> field name x
755- | _ -> () )
756- fields
757666end
758667
759668let ppx_context = Ppx_context. make
760669
761- let drop_ppx_context_str ~ restore = function
762- | {pstr_desc = Pstr_attribute ({Location. txt = " ocaml.ppx.context" }, a )}
670+ let drop_ppx_context_str = function
671+ | {pstr_desc = Pstr_attribute ({Location. txt = " ocaml.ppx.context" }, _ )}
763672 :: items ->
764- if restore then Ppx_context. restore (Ppx_context. get_fields a);
765673 items
766674 | items -> items
767675
768- let drop_ppx_context_sig ~ restore = function
769- | {psig_desc = Psig_attribute ({Location. txt = " ocaml.ppx.context" }, a )}
676+ let drop_ppx_context_sig = function
677+ | {psig_desc = Psig_attribute ({Location. txt = " ocaml.ppx.context" }, _ )}
770678 :: items ->
771- if restore then Ppx_context. restore (Ppx_context. get_fields a);
772679 items
773680 | items -> items
774681
0 commit comments