@@ -177,6 +177,7 @@ module Fragment = struct
177177 ; conditions : bool StringMap .t
178178 ; fragment_target : Target_env .t option
179179 ; aliases : StringSet .t
180+ ; deprecated : string option
180181 }
181182
182183 let allowed_flags =
@@ -259,6 +260,7 @@ module Fragment = struct
259260 ; conditions = StringMap. empty
260261 ; fragment_target = None
261262 ; aliases = StringSet. empty
263+ ; deprecated = None
262264 }
263265 in
264266 let fragment =
@@ -289,6 +291,7 @@ module Fragment = struct
289291 | `Always -> { fragment with always = true }
290292 | `Alias name ->
291293 { fragment with aliases = StringSet. add name fragment.aliases }
294+ | `Deprecated txt -> { fragment with deprecated = Some txt }
292295 | `If name when Option. is_some (Target_env. of_string name) ->
293296 if Option. is_some fragment.fragment_target
294297 then Format. eprintf " Duplicated target_env in %s\n " (loc pi);
@@ -394,6 +397,7 @@ type state =
394397 { ids : IntSet .t
395398 ; always_required_codes : always_required list
396399 ; codes : (Javascript .program pack * bool ) list
400+ ; deprecation : (int list * string ) list
397401 ; missing : StringSet .t
398402 ; include_ : string -> bool
399403 }
@@ -456,6 +460,7 @@ let load_fragment ~target_env ~filename (f : Fragment.t) =
456460 ; aliases
457461 ; has_macro
458462 ; conditions
463+ ; deprecated
459464 } -> (
460465 let should_ignore =
461466 StringMap. exists
@@ -543,14 +548,14 @@ let load_fragment ~target_env ~filename (f : Fragment.t) =
543548 name
544549 { id; pi; filename; weakdef; target_env = fragment_target };
545550 Hashtbl. add provided_rev id (name, pi);
546- Hashtbl. add code_pieces id (code, has_macro, requires);
551+ Hashtbl. add code_pieces id (code, has_macro, requires, deprecated );
547552 StringSet. iter (fun alias -> Primitive. alias alias name) aliases;
548553 `Ok )
549554
550555let check_deps () =
551556 let provided = list_all () in
552557 Hashtbl. iter
553- (fun id (code , _has_macro , requires ) ->
558+ (fun id (code , _has_macro , requires , _deprecated ) ->
554559 match code with
555560 | Ok code -> (
556561 let traverse = new Js_traverse. free in
@@ -617,13 +622,18 @@ and resolve_dep_id_rev state path id =
617622 state)
618623 else
619624 let path = id :: path in
620- let code, has_macro, req = Hashtbl. find code_pieces id in
625+ let code, has_macro, req, deprecated = Hashtbl. find code_pieces id in
621626 let state = { state with ids = IntSet. add id state.ids } in
622627 let state =
623628 List. fold_left req ~init: state ~f: (fun state nm ->
624629 resolve_dep_name_rev state path nm)
625630 in
626- let state = { state with codes = (code, has_macro) :: state.codes } in
631+ let deprecation =
632+ match deprecated with
633+ | None -> state.deprecation
634+ | Some txt -> (path, txt) :: state.deprecation
635+ in
636+ let state = { state with codes = (code, has_macro) :: state.codes; deprecation } in
627637 state
628638
629639let proj_always_required { ar_filename; ar_requires; ar_program } =
@@ -640,6 +650,7 @@ let init ?from () =
640650 List. rev
641651 (List. filter_map ! always_included ~f: (fun x ->
642652 if include_ x.ar_filename then Some (proj_always_required x) else None ))
653+ ; deprecation = []
643654 ; codes = []
644655 ; include_
645656 ; missing = StringSet. empty
@@ -681,6 +692,29 @@ let link ?(check_missing = true) program (state : state) =
681692 { state with codes = (Ok always.program, false ) :: state.codes })
682693 in
683694 if check_missing then do_check_missing state;
695+ List. iter state.deprecation ~f: (fun (path , txt ) ->
696+ match path with
697+ | [] -> assert false
698+ | [ x ] ->
699+ if false
700+ then
701+ let name = fst (Hashtbl. find provided_rev x) in
702+ warn " The runtime primitive [%s] is deprecated. %s\n " name txt
703+ | x :: path ->
704+ let name = fst (Hashtbl. find provided_rev x) in
705+ let path =
706+ String. concat
707+ ~sep: " \n "
708+ (List. map path ~f: (fun id ->
709+ let nm, loc = Hashtbl. find provided_rev id in
710+ Printf. sprintf " -> %s:%s" nm (Parse_info. to_string loc)))
711+ in
712+ warn
713+ " The runtime primitive [%s] is deprecated. %s. Used by:\n %s\n "
714+ name
715+ txt
716+ path);
717+
684718 let codes =
685719 List. map state.codes ~f: (fun (x , has_macro ) ->
686720 let c = unpack x in
@@ -710,3 +744,10 @@ let origin ~name =
710744 let x = Hashtbl. find provided name in
711745 x.pi.Parse_info. src
712746 with Not_found -> None
747+
748+ let deprecated ~name =
749+ try
750+ let x = Hashtbl. find provided name in
751+ let _, _, _, deprecated = Hashtbl. find code_pieces x.id in
752+ Option. is_some deprecated
753+ with Not_found -> false
0 commit comments