Skip to content

Fix issue with bytes_to_string in library. #5580

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 2 commits into from
Jul 22, 2022
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
5 changes: 1 addition & 4 deletions jscomp/core/js_of_lam_string.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,4 @@ let set_byte e e0 e1 = E.assign (E.array_index e e0) e1
]}
*)
let bytes_to_string e =
E.runtime_call Js_runtime_modules.bytes "bytes_to_string" [ e ]

let bytes_of_string s =
E.runtime_call Js_runtime_modules.bytes "bytes_of_string" [ s ]
E.runtime_call Js_runtime_modules.bytes_ "bytes_to_string" [ e ]
2 changes: 0 additions & 2 deletions jscomp/core/js_of_lam_string.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ val set_byte : J.expression -> J.expression -> J.expression -> J.expression
val const_char : char -> J.expression

val bytes_to_string : J.expression -> J.expression

val bytes_of_string : J.expression -> J.expression
2 changes: 1 addition & 1 deletion jscomp/core/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
| Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _
| Pjs_object_create _
(* TODO: check *)
| Pbytes_to_string | Pbytes_of_string | Pmakeblock _
| Pbytes_to_string | Pmakeblock _
(* whether it's mutable or not *)
| Pfield _ | Pval_from_option | Pval_from_option_not_nest
(* NOP The compiler already [t option] is the same as t *)
Expand Down
6 changes: 0 additions & 6 deletions jscomp/core/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@ let translate loc (cxt : Lam_compile_context.t) (prim : Lam_primitive.t)
*)
| [ range; e ] -> E.is_out (E.offset e off) range
| _ -> assert false)
| Pbytes_of_string ->
(* TODO: write a js primitive - or is it necessary ?
if we have byte_get/string_get
still necessary, since you can set it now.
*)
Js_of_lam_string.bytes_of_string (Ext_list.singleton_exn args)
| Pbytes_to_string ->
Js_of_lam_string.bytes_to_string (Ext_list.singleton_exn args)
| Pstringlength -> E.string_length (Ext_list.singleton_exn args)
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
| Ploc _ -> assert false (* already compiled away here*)
| Pbytes_to_string (* handled very early *) ->
prim ~primitive:Pbytes_to_string ~args loc
| Pbytes_of_string -> prim ~primitive:Pbytes_of_string ~args loc
| Pcreate_extension s -> prim ~primitive:(Pcreate_extension s) ~args loc
| Pignore ->
(* Pignore means return unit, it is not an nop *)
Expand Down
2 changes: 0 additions & 2 deletions jscomp/core/lam_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type record_representation =

type t =
| Pbytes_to_string
| Pbytes_of_string
(* Operations on heap blocks *)
| Pmakeblock of int * Lam_tag_info.t * Asttypes.mutable_flag
| Pfield of int * Lam_compat.field_dbg_info
Expand Down Expand Up @@ -172,7 +171,6 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
match rhs with Pcreate_extension b -> a = (b : string) | _ -> false)
| Pwrap_exn -> rhs = Pwrap_exn
| Pbytes_to_string -> rhs = Pbytes_to_string
| Pbytes_of_string -> rhs = Pbytes_of_string
| Praise -> rhs = Praise
| Psequand -> rhs = Psequand
| Psequor -> rhs = Psequor
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/lam_primitive.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type record_representation =

type t =
| Pbytes_to_string
| Pbytes_of_string
| Pmakeblock of int * Lam_tag_info.t * Asttypes.mutable_flag
| Pfield of int * Lambda.field_dbg_info
| Psetfield of int * Lambda.set_field_dbg_info
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/lam_print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ let primitive ppf (prim : Lam_primitive.t) =
| Pinit_mod -> fprintf ppf "init_mod!"
| Pupdate_mod -> fprintf ppf "update_mod!"
| Pbytes_to_string -> fprintf ppf "bytes_to_string"
| Pbytes_of_string -> fprintf ppf "bytes_of_string"
| Pjs_apply -> fprintf ppf "#apply"
| Pjs_runtime_apply -> fprintf ppf "#runtime_apply"
| Pjs_unsafe_downgrade { name; setter } ->
Expand Down
1 change: 1 addition & 0 deletions jscomp/ext/js_runtime_modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let format = "Caml_format"
let string = "Caml_string"

let bytes = "Caml_bytes"
let bytes_ = "Bytes"

let float = "Caml_float"

Expand Down
38 changes: 19 additions & 19 deletions jscomp/main/builtin_cmj_datasets.ml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion jscomp/ml/lambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ type is_safe =
type primitive =
| Pidentity
| Pbytes_to_string
| Pbytes_of_string
| Pignore
| Prevapply
| Pdirapply
Expand Down
1 change: 0 additions & 1 deletion jscomp/ml/lambda.mli
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ type pointer_info =
type primitive =
| Pidentity
| Pbytes_to_string
| Pbytes_of_string
| Pignore
| Prevapply
| Pdirapply
Expand Down
2 changes: 0 additions & 2 deletions jscomp/ml/printlambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ let primitive ppf = function
| Puncurried_apply -> fprintf ppf "@app"
| Pidentity -> fprintf ppf "id"
| Pbytes_to_string -> fprintf ppf "bytes_to_string"
| Pbytes_of_string -> fprintf ppf "bytes_of_string"
| Pignore -> fprintf ppf "ignore"
| Prevapply -> fprintf ppf "revapply"
| Pdirapply -> fprintf ppf "dirapply"
Expand Down Expand Up @@ -239,7 +238,6 @@ let primitive ppf = function
let name_of_primitive = function
| Puncurried_apply -> "Puncurried_apply"
| Pidentity -> "Pidentity"
| Pbytes_of_string -> "Pbytes_of_string"
| Pbytes_to_string -> "Pbytes_to_string"
| Pignore -> "Pignore"
| Prevapply -> "Prevapply"
Expand Down
1 change: 0 additions & 1 deletion jscomp/ml/translcore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ let primitives_table =
[
("%identity", Pidentity);
("%bytes_to_string", Pbytes_to_string);
("%bytes_of_string", Pbytes_of_string);
("%ignore", Pignore);
("%revapply", Prevapply);
("%apply", Pdirapply);
Expand Down
3 changes: 1 addition & 2 deletions jscomp/test/test_bytes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

var Bytes = require("../../lib/js/bytes.js");
var Caml_bytes = require("../../lib/js/caml_bytes.js");

var f = Bytes.unsafe_to_string;

var ff = Caml_bytes.bytes_to_string;
var ff = Bytes.bytes_to_string;

exports.f = f;
exports.ff = ff;
Expand Down
64 changes: 22 additions & 42 deletions lib/4.06.1/unstable/js_compiler.ml

Large diffs are not rendered by default.

64 changes: 22 additions & 42 deletions lib/4.06.1/unstable/js_playground_compiler.ml

Large diffs are not rendered by default.

64 changes: 22 additions & 42 deletions lib/4.06.1/whole_compiler.ml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/es6/char.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


import * as Caml_bytes from "./caml_bytes.js";
import * as Bytes from "./bytes.js";

function chr(n) {
if (n < 0 || n > 255) {
Expand Down Expand Up @@ -64,11 +64,11 @@ function escaped(c) {
s[1] = 48 + (c / 100 | 0) | 0;
s[2] = 48 + (c / 10 | 0) % 10 | 0;
s[3] = 48 + c % 10 | 0;
return Caml_bytes.bytes_to_string(s);
return Bytes.bytes_to_string(s);
case 2 :
var s$1 = [0];
s$1[0] = c;
return Caml_bytes.bytes_to_string(s$1);
return Bytes.bytes_to_string(s$1);

}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/js/char.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var Caml_bytes = require("./caml_bytes.js");
var Bytes = require("./bytes.js");

function chr(n) {
if (n < 0 || n > 255) {
Expand Down Expand Up @@ -64,11 +64,11 @@ function escaped(c) {
s[1] = 48 + (c / 100 | 0) | 0;
s[2] = 48 + (c / 10 | 0) % 10 | 0;
s[3] = 48 + c % 10 | 0;
return Caml_bytes.bytes_to_string(s);
return Bytes.bytes_to_string(s);
case 2 :
var s$1 = [0];
s$1[0] = c;
return Caml_bytes.bytes_to_string(s$1);
return Bytes.bytes_to_string(s$1);

}
}
Expand Down