Conversation
| iter foo [1; 2; 3] | ||
| \end{verbatim} | ||
| The argument {\tt f} to {\tt iter} is invariant so the function may be | ||
| specialised: |
There was a problem hiding this comment.
Why do you call that a specialization even if no argument have been substituted? Even if it is not the reality, for the sake of the explanation is it not better to write:
let do_iter foo =
let rec iter' l =
match l with
| [] -> ()
| h :: t ->
foo h;
iter' t
in
iter' [1; 2; 3]
There was a problem hiding this comment.
The comment in the code shows the specialisation.
I will add another paragraph showing what happens next (the indirect call being replaced by the direct call, followed by removal of the unused argument f).
|
This chapter is very interesting to read, thank you! |
manual/manual/cmds/flambda.etex
Outdated
| this function should probably not be inlined systematically: if {\tt b} | ||
| is unknown, or indeed {\tt false}, there is little benefit to trade off | ||
| against a large increase in code size. In the existing non-Flambda inliner | ||
| this isn't a great problem because chains of inlining were cut off farly |
|
Impressive amount of work (both flambda and this manual).
|
| Consult the {\em Glossary} at the end of this chapter for definitions of | ||
| technical terms used below. | ||
|
|
||
| \section{Command-line flags} |
There was a problem hiding this comment.
Do these flags only have effect at compile time, or should they be used at link time too?
There was a problem hiding this comment.
Theoretically they have an effect at link time because they apply to the code in the startup file. However in practice that's probably not relevant.
|
The last two questions are in fact related, so let's address those first. There isn't any support at the moment for saying things like "function foo isn't exposed in the interface of this module and isn't used inside, so we'll delete it before optimisation". It's possible something like that could be thought about in the future though. I have plans for a whole-program mode which will recompile at link time based on the intermediate representations in the .cmx files (with all .cmx files being required). We could have a flag to suppress normal object file generation when planning to link in that mode. The main advantage this will give is that dead code elimination will happen at the Flambda stage basically automatically. Proposals for other means of large-scale dead code elimination are highly involved. |
|
I think the answer about bounds checks is that they won't be eliminated statically since they are expanded after Flambda. (I'm not completely sure about this, but I think it is the case.) There isn't any special handling based on "assert". |
|
I agree with @edwintorok, this is impressive. I think adding a section with (automatically generated) benchmark numbers (optimisation, code size, performance) would provide valuable context as it is difficult to imagine the effect of different optimisations. |
|
The problem is that it so heavily depends on what the code actually is that generalised benchmark numbers may be misleading. I think we should perhaps leave something like that until 4.04, when we will have received more information on general use cases in the wild. |
|
Suggestions received from William via email, which I shall look at: "20.1 : "Detailed descriptions of each flag are given in the sections that follow." : I would replace by : "Terms and concepts used here are better described in the following sections". 20.2 : -unbox-closures "advanced options" : do you mean it is even less used that "less commonly-used options" ? "The set of command line flags relating to optimisation should typically be specified to be the same across an entire project." why not give a typical ocamlbuild command. ? In the mean time, I see you are from Janestreet, so you would not do that as you use other tool ... "Flambda-specific flags are silently accepted " : as it is silent only for benchmark purposes, why not make warnings by default, and add an option to make them silent when performing benchmanking ? "-rounds" : refer to the related chapter 20.2.1 "If the first form is used, the value will apply to all rounds.If the second form is used, zero-based round integers specify values which are to be used only for those rounds. " : what is first/second forms ? Maybe reformulating this with examples would be clearer. Glossary |
manual/manual/cmds/flambda.etex
Outdated
| based on the dataflow between invariant arguments. | ||
|
|
||
| \paragraph{Example:} Having been given the following code, the compiler | ||
| will inline {\tt loop} into {\tt f}, and then observe {\tt env} |
|
Remarks:
can also be written : Same thing for the module. I'll let you decide if it's better or not. :)
|
| application and takes an integer argument. Each time the inliner sees | ||
| the attribute it behaves as follows: | ||
| \begin{itemize} | ||
| \item If $n$ is zero or less, nothing happens. |
There was a problem hiding this comment.
The compiler accepts [@unrolled] but it is not clear what effect it has. It looks like it is equivalent to [@unrolled 0] ? It should probably be documented here
There was a problem hiding this comment.
@Drup: comments on the manual noted.
It seems that the warning about unused arguments you suggest would be easier implemented prior to Flambda. (This presumably concerns cases involving recursive functions, since there is already a warning for simple cases.) Flambda ends up making arguments unused, and we probably wouldn't want to trigger the warning for those. For example [Remove_unused_arguments] will remove a single unit argument to a function, forming a zero-arity function, and you wouldn't want to warn about that...
The [@NoEscape] attribute sounds like a good idea. Two places in the compiler ([Simplif] and [Ref_to_variables]) would need updating. We would be pleased to receive a patch from you. :)
User documentation about Flambda for the manual.
If you would like to read this without building the manual, there is a temporary link here:
https://ocaml.janestreet.com/ocaml-core/flambda_manual/
This doesn't constitute developer documentation. That is intended to be provided by the source code itself and the comments in that code. We will try to do some more improving of comments before the 4.03 release.
In this GPR there is a hack in fix_index.sh (so it would work for me) which I shall revert before merging this.