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

Diff for: CHANGES.md

+12
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

Diff for: VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.9.0
1+
5.9.1

Diff for: compiler/bin-js_of_ocaml/check_runtime.ml

+3-3
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 ] ))

Diff for: compiler/lib/annot_lexer.mll

+1
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 }

Diff for: compiler/lib/annot_parser.mly

+2
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) }

Diff for: compiler/lib/linker.ml

+45-4
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

Diff for: compiler/lib/linker.mli

+2
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

Diff for: compiler/lib/primitive.ml

+1
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

Diff for: compiler/lib/primitive.mli

+1
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

Diff for: compiler/tests-check-prim/main.output

+4-3
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

Diff for: compiler/tests-check-prim/main.output5

+4-3
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ BigStringReader
101101
caml_marshal_constants
102102

103103
From +mlBytes.js:
104-
caml_array_of_bytes
105-
caml_array_of_string
104+
caml_array_of_bytes (deprecated)
105+
caml_array_of_string (deprecated)
106106
caml_bytes_of_utf16_jsstring
107+
caml_new_string (deprecated)
107108
caml_string_concat
108-
caml_to_js_string
109+
caml_to_js_string (deprecated)
109110

110111
From +runtime_events.js:
111112
caml_runtime_events_create_cursor

Diff for: compiler/tests-check-prim/unix-unix.output

+4-3
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,12 @@ BigStringReader
217217
caml_marshal_constants
218218

219219
From +mlBytes.js:
220-
caml_array_of_bytes
221-
caml_array_of_string
220+
caml_array_of_bytes (deprecated)
221+
caml_array_of_string (deprecated)
222222
caml_bytes_of_utf16_jsstring
223+
caml_new_string (deprecated)
223224
caml_string_concat
224-
caml_to_js_string
225+
caml_to_js_string (deprecated)
225226

226227
From +stdlib.js:
227228
caml_build_symbols

Diff for: compiler/tests-check-prim/unix-unix.output5

+4-3
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,12 @@ BigStringReader
212212
caml_marshal_constants
213213

214214
From +mlBytes.js:
215-
caml_array_of_bytes
216-
caml_array_of_string
215+
caml_array_of_bytes (deprecated)
216+
caml_array_of_string (deprecated)
217217
caml_bytes_of_utf16_jsstring
218+
caml_new_string (deprecated)
218219
caml_string_concat
219-
caml_to_js_string
220+
caml_to_js_string (deprecated)
220221

221222
From +runtime_events.js:
222223
caml_runtime_events_create_cursor

Diff for: compiler/tests-check-prim/unix-win32.output

+4-3
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,12 @@ BigStringReader
182182
caml_marshal_constants
183183

184184
From +mlBytes.js:
185-
caml_array_of_bytes
186-
caml_array_of_string
185+
caml_array_of_bytes (deprecated)
186+
caml_array_of_string (deprecated)
187187
caml_bytes_of_utf16_jsstring
188+
caml_new_string (deprecated)
188189
caml_string_concat
189-
caml_to_js_string
190+
caml_to_js_string (deprecated)
190191

191192
From +stdlib.js:
192193
caml_build_symbols

Diff for: compiler/tests-check-prim/unix-win32.output5

+4-3
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ BigStringReader
178178
caml_marshal_constants
179179

180180
From +mlBytes.js:
181-
caml_array_of_bytes
182-
caml_array_of_string
181+
caml_array_of_bytes (deprecated)
182+
caml_array_of_string (deprecated)
183183
caml_bytes_of_utf16_jsstring
184+
caml_new_string (deprecated)
184185
caml_string_concat
185-
caml_to_js_string
186+
caml_to_js_string (deprecated)
186187

187188
From +runtime_events.js:
188189
caml_runtime_events_create_cursor

Diff for: compiler/tests-dynlink-js/dune

-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
(libraries js_of_ocaml)
66
(link_flags
77
(:standard -linkall))
8-
;; Until dune is fixed https://github.com/ocaml/dune/pull/10935
98
(js_of_ocaml
109
(flags
1110
(:standard)
12-
--linkall
1311
(:include effects_flags.sexp))
1412
(build_runtime_flags
1513
(:standard)

Diff for: compiler/tests-sourcemap/dune

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
(executable
77
(name test)
88
(modules test)
9+
(enabled_if
10+
(<> %{profile} using-effects))
911
(modes js)
1012
(js_of_ocaml
1113
(link_flags

Diff for: compiler/tests-toplevel/dune

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
(rule
1818
(target test_toplevel.bc.js.actual)
19-
(enabled_if %{env:js-enabled=})
19+
(enabled_if
20+
(and
21+
(>= %{ocaml_version} 5.2)
22+
%{env:js-enabled=}))
2023
(action
2124
(with-stdout-to
2225
%{target}

0 commit comments

Comments
 (0)