Skip to content

Turn on optimizations for unicode strings. #5457

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 1 commit into from
Jun 22, 2022
Merged

Turn on optimizations for unicode strings. #5457

merged 1 commit into from
Jun 22, 2022

Conversation

cristianoc
Copy link
Collaborator

These are the same as for strings, except indexing.

Fixes #5454

These are the same as for strings, except indexing.

Fixes #5454
@cristianoc cristianoc requested a review from cknitt June 22, 2022 00:48
Copy link
Collaborator Author

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the various cases and added comments.

@@ -268,6 +270,6 @@ let rev_toplevel_flatten block =

let rec is_okay_to_duplicate (e : J.expression) =
match e.expression_desc with
| Var _ | Bool _ | Str _ | Number _ -> true
| Var _ | Bool _ | Str _ | Unicode _ | Number _ -> true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to duplicate unicode strings

@@ -35,7 +35,7 @@ type t = J.expression
*)
let rec remove_pure_sub_exp (x : t) : t option =
match x.expression_desc with
| Var _ | Str _ | Number _ -> None (* Can be refined later *)
| Var _ | Str _ | Unicode _ | Number _ -> None (* Can be refined later *)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like same behaviour as strings: both pure.

@@ -173,7 +173,7 @@ module L = Literals
let typeof ?comment (e : t) : t =
match e.expression_desc with
| Number _ | Length _ -> str ?comment L.js_type_number
| Str _ -> str ?comment L.js_type_string
| Str _ | Unicode _ -> str ?comment L.js_type_string
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type of unicode is string.

@@ -810,7 +812,8 @@ let uint32 ?comment n : J.expression =

let string_comp (cmp : J.binop) ?comment (e0 : t) (e1 : t) =
match (e0.expression_desc, e1.expression_desc) with
| Str {txt=a0}, Str {txt=b0} -> (
| Str {txt=a0}, Str {txt=b0}
| Unicode a0, Unicode b0 -> (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equality s1 == s2 should correspond to equal byte representation also in unicode.

@@ -192,7 +192,7 @@ let subst_map (substitution : J.expression Hash_ident.t) =
let _, e, bindings =
Ext_list.fold_left ls (0, [], []) (fun (i, e, acc) x ->
match x.expression_desc with
| Var _ | Number _ | Str _ | J.Bool _ | Undefined ->
| Var _ | Number _ | Str _ | Unicode _ | J.Bool _ | Undefined ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what enables inlining from the relevant issue linked to this PR.

@@ -220,7 +220,7 @@ let record_scope_pass =
TODO:
*)
match x.expression_desc with
| Fun _ | Number _ | Str _ -> state
| Fun _ | Number _ | Str _ | Unicode _ -> state
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unicode strings are immutable.

@cristianoc cristianoc merged commit 7e58a20 into master Jun 22, 2022
@cristianoc cristianoc deleted the opt_unicode branch June 22, 2022 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unnecessary variables generated for string literals in record fields
1 participant