-
Notifications
You must be signed in to change notification settings - Fork 89
Make tailrec label optional #48
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,13 @@ let rec eliminate_dead_blocks cfg_with_layout = | |
Printf.printf "\n" ); | ||
(* Termination: the number of remaining blocks is strictly smaller in | ||
each recursive call. *) | ||
eliminate_dead_blocks cfg_with_layout ) | ||
eliminate_dead_blocks cfg_with_layout; | ||
begin match cfg.fun_tailrec_entry_point_label with | ||
| None -> () | ||
| Some label -> | ||
if List.exists (Label.equal label) found_dead then | ||
Cfg.set_fun_tailrec_entry_point_label cfg None | ||
end) | ||
Comment on lines
+68
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this check is not correct here: if there is another There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, this is actually fine and I was confused about who is dead! I still think it's better to do this check at the end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am slightly confused: it looks like the operation is the very There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check will happen at the end of each recursive call. As suggested offline, this problem would completely go away if we change the representation of Tailcall Self to include the label, and also remove fun_tailrec_entry_point_label in Cfg. It is still worth changing Linear.fundecl.fun_tailrec_entry_point_label to an option. The pass Cfg_to_linear can compute the field and check its consistency (i.e., all Tailrec Self have the same destination label). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand your point about the recursive calls. |
||
else | ||
(* check that no blocks are left that are marked as dead *) | ||
C.iter_blocks cfg ~f:(fun label block -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,13 @@ let rec disconnect_fallthrough_blocks cfg_with_layout = | |
if !C.verbose then | ||
Printf.printf "%s: disconnected fallthrough blocks: %d\n" cfg.fun_name | ||
len; | ||
disconnect_fallthrough_blocks cfg_with_layout ) | ||
disconnect_fallthrough_blocks cfg_with_layout; | ||
begin match cfg.fun_tailrec_entry_point_label with | ||
| None -> () | ||
| Some label -> | ||
if List.exists (Label.equal label) found then | ||
Cfg.set_fun_tailrec_entry_point_label cfg None | ||
end) | ||
Comment on lines
+78
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, I think this check should be done at the end of the entire transformation. Unlike the above case, this seem correct for a subtle reason: if tailrec block was a fallthrough and got eliminated, then either (a) there are Tailcall Self, and then the |
||
|
||
let run cfg_with_layout = | ||
let cfg = CL.cfg cfg_with_layout 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 the case of Tailcall(Self), t.fun_tailrec_entry_point_label must not be None, so Option.map is fine, but may be worth checking.