Skip to content

Commit e6ca2d3

Browse files
authored
Merge pull request #135 from ocaml-wasm/jsoo-merge
Merge with js_of_ocaml master
2 parents b12f852 + 2e14088 commit e6ca2d3

File tree

26 files changed

+221
-114
lines changed

26 files changed

+221
-114
lines changed

CHANGES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# dev
2+
3+
## Features/Changes
4+
* Lib: fix the type of some DOM properties and methods (#1747)
5+
* Test: use dune test stanzas (#1631)
6+
7+
# 5.9.1 (02-12-2024) - Lille
8+
9+
## Features/Changes
10+
* Compiler: add mechanism to deprecate runtime promitives
11+
* Runtime: re-introduce caml_new_string, marked as deprecated
12+
113
# 5.9.0 (2024-11-22) - Lille
214

315
## Features/Changes

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.9.0
1+
5.9.1

compiler/bin-js_of_ocaml/check_runtime.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ let f (runtime_files, bytecode, target_env) =
101101
StringSet.of_list (Linker.all state), missing
102102
in
103103
assert (StringSet.equal missing missing');
104+
let extra = StringSet.diff from_runtime1 all_used |> StringSet.elements in
104105
let extra =
105-
StringSet.diff from_runtime1 all_used
106-
|> StringSet.elements
106+
extra
107107
|> List.map ~f:(fun name ->
108-
( name
108+
( (name ^ if Linker.deprecated ~name then " (deprecated)" else "")
109109
, match Linker.origin ~name with
110110
| None -> []
111111
| Some x -> [ x ] ))

compiler/lib/annot_lexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rule main = parse
2828
| "Always" {TAlways}
2929
| "If" {TIf}
3030
| "Alias" {TAlias}
31+
| "Deprecated: " ([^'\n']* as txt) {TDeprecated txt}
3132
| "pure" {TA_Pure }
3233
| "const" {TA_Const }
3334
| "mutable" {TA_Mutable }

compiler/lib/annot_parser.mly

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
%token<string> TIdent TVNum
2323
%token TComma TColon EOF EOL LE LT GE GT EQ LPARENT RPARENT
2424
%token<string> TOTHER
25+
%token<string> TDeprecated
2526
%token TBang
2627

2728
%start annot
@@ -40,6 +41,7 @@ annot:
4041
{ `Version (l) }
4142
| TWeakdef endline { `Weakdef }
4243
| TAlways endline { `Always }
44+
| TDeprecated endline { `Deprecated $1 }
4345
| TAlias TColon name=TIdent endline { `Alias (name) }
4446
| TIf TColon name=TIdent endline { `If (name) }
4547
| TIf TColon TBang name=TIdent endline { `Ifnot (name) }

compiler/lib/linker.ml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

550555
let 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

629639
let 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

compiler/lib/linker.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ val all : state -> string list
6868
val missing : state -> string list
6969

7070
val origin : name:string -> string option
71+
72+
val deprecated : name:string -> bool

compiler/lib/primitive.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type t =
5050
| `Weakdef
5151
| `Always
5252
| `Alias of string
53+
| `Deprecated of string
5354
| condition
5455
]
5556

compiler/lib/primitive.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type t =
4848
| `Weakdef
4949
| `Always
5050
| `Alias of string
51+
| `Deprecated of string
5152
| condition
5253
]
5354

compiler/tests-check-prim/main.output

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ BigStringReader
108108
caml_marshal_constants
109109

110110
From +mlBytes.js:
111-
caml_array_of_bytes
112-
caml_array_of_string
111+
caml_array_of_bytes (deprecated)
112+
caml_array_of_string (deprecated)
113113
caml_bytes_of_utf16_jsstring
114+
caml_new_string (deprecated)
114115
caml_string_concat
115-
caml_to_js_string
116+
caml_to_js_string (deprecated)
116117

117118
From +stdlib.js:
118119
caml_build_symbols

0 commit comments

Comments
 (0)