Skip to content

Extract runtime functionality into separate Runtime_* modules (part 1) #6841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions jscomp/ext/js_runtime_modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ let external_polyfill = "Caml_external_polyfill"
let caml_js_exceptions = "Caml_js_exceptions"

let caml_splice_call = "Caml_splice_call"

let deriving = "Runtime_deriving"

let promise = "Runtime_promise"

let astExtensions = "Runtime_ast_extensions"
9 changes: 4 additions & 5 deletions jscomp/frontend/ast_derive_js_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@ let app2 = Ast_compatible.app2

let ( ->~ ) a b = Ast_compatible.arrow a b

let js_mapper_rt = Longident.Ldot (Lident "Js", "MapperRt")
let raise_when_not_found_ident =
Longident.Ldot (Lident Js_runtime_modules.deriving, "raiseWhenNotFound")

let raise_when_not_found x =
app1
(Exp.ident
{loc = noloc; txt = Longident.Ldot (js_mapper_rt, "raiseWhenNotFound")})
x
app1 (Exp.ident {loc = noloc; txt = raise_when_not_found_ident}) x

let deriving_name = "jsConverter"

let init () =
Expand Down
11 changes: 9 additions & 2 deletions jscomp/frontend/ast_exp_extension.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,21 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
Exp.sequence ~loc
(Ast_compatible.app1 ~loc
(Exp.ident ~loc
{loc; txt = Ldot (Ldot (Lident "Js", "Console"), "timeStart")})
{
loc;
txt = Ldot (Lident Js_runtime_modules.astExtensions, "timeStart");
})
(Ast_compatible.const_exp_string ~loc loc_string))
(Exp.let_ ~loc Nonrecursive
[Vb.mk ~loc (Pat.var ~loc {loc; txt = "timed"}) e]
(Exp.sequence ~loc
(Ast_compatible.app1 ~loc
(Exp.ident ~loc
{loc; txt = Ldot (Ldot (Lident "Js", "Console"), "timeEnd")})
{
loc;
txt =
Ldot (Lident Js_runtime_modules.astExtensions, "timeEnd");
})
(Ast_compatible.const_exp_string ~loc loc_string))
(Exp.ident ~loc {loc; txt = Lident "timed"})))
| _ ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/ast_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let add_promise_type ?(loc = Location.none) ~async
if async then
let unsafe_async =
Ast_helper.Exp.ident ~loc
{txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_async"); loc}
{txt = Ldot (Lident Js_runtime_modules.promise, "unsafe_async"); loc}
in
Ast_helper.Exp.apply ~loc unsafe_async [(Nolabel, result)]
else result
Expand Down
4 changes: 2 additions & 2 deletions jscomp/ml/ast_await.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let create_await_expression (e : Parsetree.expression) =
let loc = {e.pexp_loc with loc_ghost = true} in
let unsafe_await =
Ast_helper.Exp.ident ~loc
{txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_await"); loc}
{txt = Ldot (Lident Js_runtime_modules.promise, "unsafe_await"); loc}
in
Ast_helper.Exp.apply ~loc unsafe_await [(Nolabel, e)]

Expand All @@ -24,7 +24,7 @@ let create_await_module_expression ~module_type_lid (e : Parsetree.module_expr)
(Exp.apply ~loc:e.pmod_loc
(Exp.ident ~loc:e.pmod_loc
{
txt = Longident.Ldot (Lident "Js", "import");
txt = Longident.Ldot (Lident Js_runtime_modules.promise, "import");
loc = e.pmod_loc;
})
[
Expand Down
162 changes: 0 additions & 162 deletions jscomp/others/.depend

This file was deleted.

2 changes: 0 additions & 2 deletions jscomp/others/js.res
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latt
/** JS object type */
type t<'a> = {..} as 'a

module MapperRt = Js_mapperRt

module Internal = {
external opaqueFullApply: 'a => 'a = "%uncurried_apply"

Expand Down
3 changes: 0 additions & 3 deletions jscomp/others/js_promise.res
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ external catch: (@uncurry (error => promise<'a>)) => promise<'a> = "catch"
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
*/

external unsafe_async: 'a => promise<'a> = "%identity"
external unsafe_await: promise<'a> => 'a = "?await"

/*
let errorAsExn (x : error) (e : (exn ->'a option))=
if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then
Expand Down
Loading