-
Notifications
You must be signed in to change notification settings - Fork 470
Finish the optimization around visitor pattern using objects #4916
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
Conversation
the object already had a late binding for methods TODO: we may do eta-expansion here to avoid the cost of currying
the semantics for open recursion with high order function is tricky let's not use it at all code like this `(fun self -> self#hi)` is very hard to reason about
|
||
let calculate_hard_dependencies block = | ||
let hard_dependencies = create 17 in | ||
(count_hard_dependencies hard_dependencies)#block block ; | ||
let obj = (count_hard_dependencies hard_dependencies) in | ||
obj.block obj block ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this object is used only once
@@ -58,8 +57,8 @@ let flatten_map = | |||
| {statement_desc = Exp last_one ; _} :: rest_rev | |||
-> | |||
S.block (Ext_list.rev_map_append rest_rev | |||
[self#statement @@ S.exp (E.assign a last_one)] | |||
self#statement | |||
[self.statement self (S.exp (E.assign a last_one))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assuming we follow the design pattern, called as self.xx self xx
This could be fused just as: statement self
| x::rest | ||
-> | ||
let st = self#statement x in | ||
let block = self#block rest in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory, we can tie the knot, fix self
in the definition of flatten_map
object
match vd.ident_info.used_stats with | ||
| Dead_pure | ||
-> () | ||
| Dead_non_pure -> | ||
begin match vd.value with | ||
| None -> () | ||
| Some x -> self#expression x | ||
| Some x -> self.expression self x | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory, we can tie the knot here, and since mark_dead.expression is the same as super.expression, we can call super.expression directly
The downside is that if we do override super.expression, it will be wrong
@@ -48,30 +48,31 @@ let post_process_stats my_export_set (defined_idents : J.variable_declaration Ha | |||
since in this case it can not be global? | |||
|
|||
*) | |||
let super = Js_record_iter.iter | |||
let count_collects | |||
(* collect used status*) | |||
(stats : int Hash_ident.t) | |||
(* collect all def sites *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if this visitor is used a lot, some micro-optimizations could be applied here
begin _self.module_id _self _x0 end ) ; | ||
exception_ident : exception_ident fn = ( (fun _self arg -> _self.ident _self arg) ) ; | ||
for_ident : for_ident fn = ( (fun _self arg -> _self.ident _self arg) ) ; | ||
for_direction : for_direction fn = ( unknown ) ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be removed
exception_ident : exception_ident fn = ( (fun _self arg -> _self.ident _self arg) ) ; | ||
for_ident : for_ident fn = ( (fun _self arg -> _self.ident _self arg) ) ; | ||
for_direction : for_direction fn = ( unknown ) ; | ||
property_map : property_map fn = ( fun _self arg -> list ((fun _self (_x0,_x1) -> begin _self.expression _self _x1 end)) _self arg ) ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is actually hard to simplify -- we can create a closure using _self
, but not sure if it is worth it
No description provided.