Repository navigation
Compile records as objects: single commit. - #3785
cristianoc wants to merge 3 commits into
Conversation
0fde268 to
5e8db96
Compare
0a9409d to
4c2367f
Compare
aaf5d13 to
9060894
Compare
Still need to activate based on version, once the version number where the corresponding bucklescript changes ship is known: rescript-lang/rescript#3785.
|
|
||
| let get_lo x = E.dot x "lo" | ||
| let get_hi x = E.dot x "hi" | ||
|
|
There was a problem hiding this comment.
Mark to check if such inlining is really worth such complexity later
There was a problem hiding this comment.
I will send a PR to rely less on internals of int64, it makes more sense, since we probably will switch the implementation relying on bigint in the future
| tbl.lex_check = caml_lex_array(tbl[lex_check]); | ||
| tbl.lex_trans = caml_lex_array(tbl[lex_trans]); | ||
| tbl.lex_default = caml_lex_array(tbl[lex_default]); | ||
| tbl.processed = true; |
There was a problem hiding this comment.
what's the rational of adding tbl.processed, is it a bug fix?
There was a problem hiding this comment.
This is subtle:
This code already existed before my change:
tbl.lex_default = caml_lex_array(tbl[lex_default]);So the code was effectively using object fields in addition to array index.
And then the check
if (!tbl.lex_default) {semantically means: "I have already processed this code".
In my changes, I've made this subtle distinction explicit. The behavior has not changed.
| *) | ||
|
|
||
| external caml_update_dummy : Caml_obj_extern.t -> Caml_obj_extern.t -> unit = "Object.assign" [@@bs.val] | ||
|
|
There was a problem hiding this comment.
caml_update_dummy is used in initializating rec values, how is it related to record encoding?
There was a problem hiding this comment.
This is used when initializing:
type a = {
b: b;
}
and b = {
a: a
};;And it affects gpr_1716_test.ml.
Is it used for other things as well, and should there be 2 versions of it?
There was a problem hiding this comment.
type a = {
b: b;
}
and b = {
a: a
};;
let rec a = { b } and b = { a };;
This seems more subtle. Here the recursive value could be record, but other blocks too, I guess changing caml_update_dummy will break other recursive values, will dig into later
| (* compatibility with old hash tables *) | ||
| if Obj.size (Obj.repr h) >= 3 | ||
| if (* XXX *) true || Obj.size (Obj.repr h) >= 3 | ||
| then (seeded_hash_param 10 100 h.seed key) land (Array.length h.data - 1) |
There was a problem hiding this comment.
we may remove such thing, since we don't need maintain compatibility with old hashtbl
There was a problem hiding this comment.
Happy to remove.
Does it mean I should remove the false branch and any dead code it could result from that?
| external incr : int ref -> unit = "%incr" | ||
| external decr : int ref -> unit = "%decr" | ||
| (* external ( ! ) : 'a ref -> 'a = "%field0" *) | ||
| let (!) x = x.contents |
There was a problem hiding this comment.
maybe we can introduce new primitives for deferencing and update
There was a problem hiding this comment.
This may affect an optimization pass of reference elimination
There was a problem hiding this comment.
Sure, can be done in a cleanup phase. Reminder: search field0 and create another version.
In this pass, I'd like to focus on correctness first.
| comment=comment_with_tag | ||
| } | ||
| | _ -> | ||
| let comment = |
There was a problem hiding this comment.
How about we delay the creation of Object .., stay with Caml_block, only convert it to Object in js_dump.ml to preserve existing semantics the most
|
|
||
| let get_lo x = E.dot x "lo" | ||
| let get_hi x = E.dot x "hi" | ||
|
|
There was a problem hiding this comment.
I will send a PR to rely less on internals of int64, it makes more sense, since we probably will switch the implementation relying on bigint in the future
| | Fld_record comment | ||
| -> E.array_index_by_int ~comment e i | ||
| | Fld_record comment -> | ||
| E.dot e comment |
There was a problem hiding this comment.
can we do something similiar as module_access below to preserve as much as semantics as possible
| | Fld_record s | ||
| | Fld_module s | ||
| -> E.array_index_by_int ~comment:s e i | ||
| -> E.dot e s |
There was a problem hiding this comment.
Float record does not make too much sense in JS context, I will send a PR to remove such stuff
| (Js_arr.set_array (E.var id) (E.int (Int32.of_int i)) (E.var lid)) | ||
| -> | ||
| S.exp | ||
| (E.assign (E.dot (E.var id) fields.(i)) (E.var lid)) |
There was a problem hiding this comment.
Let's create a dedicated module for record operations.
Still need to activate based on version, once the version number where the corresponding bucklescript changes ship is known: rescript-lang/rescript#3785.
Still need to activate based on version, once the version number where the corresponding bucklescript changes ship is known: rescript-lang/rescript#3785.
* Prepare for records represented as objects. Still need to activate based on version, once the version number where the corresponding bucklescript changes ship is known: rescript-lang/rescript#3785. * Rebase on master. * Version check.
|
In master. |
Cleaned up version of #3741.
Changes
Blk_recordtag, create an object.int64becomes an object withloandhi.caml_lexer.mlandcaml.parser.mlare "manually compiled" and need to switch to objects.caml_obj.mlwhich does not use the modified pervasives.stream.mlhas an internal optimization assuming array runtime and needs changing.Questions
bytecomp/translobj.mlfor implicit assumptions about the memory layout.Object.assignwith a more direct implementation.Check interaction with hooks PPX.