Skip to content
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

the optimization of optional arguments never applies with -g #7384

Closed
vicuna opened this issue Oct 12, 2016 · 5 comments
Closed

the optimization of optional arguments never applies with -g #7384

vicuna opened this issue Oct 12, 2016 · 5 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Oct 12, 2016

Original bug ID: 7384
Reporter: @sliquister
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2016-10-17T08:37:45Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.03.0
Fixed in version: 4.04.0 +dev / +beta1 / +beta2
Category: middle end (typedtree to clambda)
Related to: #7345
Monitored by: @gasche

Bug description

The optimization of optional arguments probably breaks because -g inserts nodes in the lambda AST, which breaks Simplif.split_default_wrapper.

$ cat c.ml
let f ?(x = 1) y = x + y
$ ocamlopt -S -c c.ml && grep -m1 inner c.s
.globl camlC__f_inner_4
$ ocamlopt -g -S -c c.ml && grep -m1 inner c.s
$
$ ocamlopt -dlambda -g -S -c c.ml && grep -m1 inner c.s
(let
(f/1199 =
(function opt/1200 y/1203
(funct-body c.ml(1):6-24
(before c.ml(1):19-24
(let
(x/1201 =
(if opt/1200 (before c.ml(1):12-13 (field 0 opt/1200))
(before c.ml(1):12-13 1)))
(before c.ml(1):19-24 (+ x/1201 y/1203)))))))
(pseudo none(1):-1--1 (makeblock 0 f/1199)))

I think this is worth fixing because it impacts both the normal backend and flambda (as the function might be too big to inline repeatedly).

@vicuna
Copy link
Author

vicuna commented Oct 12, 2016

Comment author: @sliquister

While I'm creating a ticket, I'll note it'd be nice if this optimization worked in cases where we cannot use optional arguments without being forced to introduce some silly unit parameters:

let f ?x t =
let x =
match x with
| None -> String.length t
| Some x -> x
in
..

(of course one can write wrappers, but with this reasoning the existing optimization is not necessary either)

@vicuna
Copy link
Author

vicuna commented Oct 17, 2016

Comment author: @alainfrisch

Hmm, I thought debug events were not generated when compiling in native code. Will look at that.

@vicuna
Copy link
Author

vicuna commented Oct 17, 2016

Comment author: @alainfrisch

Well, this is now the case anyway (since commit 5f00ce7), so the bug is gone in trunk. One should probably add a non-regression test for that.

@vicuna
Copy link
Author

vicuna commented Oct 17, 2016

Comment author: @alainfrisch

There is already asmcomp/optargs.ml, but not compiled with -g.

@vicuna
Copy link
Author

vicuna commented Oct 17, 2016

Comment author: @alainfrisch

Now compiling the non-regression test with -g (commit 735acaf).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants