Skip to content

Add -flambda/-no-flambda compile-time options to ocamlopt#699

Closed
alainfrisch wants to merge 2 commits intoocaml:trunkfrom
alainfrisch:flambda_at_compile_time
Closed

Add -flambda/-no-flambda compile-time options to ocamlopt#699
alainfrisch wants to merge 2 commits intoocaml:trunkfrom
alainfrisch:flambda_at_compile_time

Conversation

@alainfrisch
Copy link
Copy Markdown
Contributor

This PR is about allowing to compile with or without flambda independently of the default mode chosen at configure-time.

The configure-time option determines the default mode (and the one used to compiled stdlib and compiler-libs), but the restriction that code compiled with/without flambda (as determined at configure-time) cannot be linked together is lifted.

The same magic number is used in .cmx files for flambda and non-flambda mode. Previously, different magic numbers were used, which leads to potentially cryptic error messages when trying to mix the two modes.

When compiling a unit B which imports A.cmx, in different mode w.r.t. flambda, cross-module optimization information from A.cmx are ignored (just as if A.cmx had been obtained by -opaque). This also trigger a new warning 61 explaning the situation (instead of the above-mentioned error message).

In addition, this removes some code duplication between asmpackager.ml and compilenv.ml.

In the long term, if the non-flambda mode is maintained, one could hope to get more interoperability between the two modes, i.e. mapping cross-module info of one mode into the other one, in only one or both directions. But even if we never reach that point, this PR will give more visibility to flambda since it simplifies testing flambdalocally (e.g. to see if some kinds of optimizations -- not involving external modules -- are triggered). For quick testing, it is much simpler to pass "-flambda" than to rebuild a full OCaml configured with -flambda (which is rather slow).

There is also the case of very big and boring modules which takes a lot of time to compile even with -Oclassic, and for which performance is known to be completely irrelevant. For these cases, one could use -no-flambda to speed up compilation.

There remains a TODO in Clflags (to initialize inlining threshold), hence the WIP in the title.

The configure-time option determines the default mode (and the one used to compiled stdlib and compiler-libs),
but the restriction that code compiled with/without flambda (as determined at configure-time) cannot be linked together
is lifted.

The same magic number is used in .cmx files for flambda and non-flambda mode.  Previously, different magic
numbers were used, which leads to potentially cryptic error messages when trying to mix the two modes.

When compiling a unit B which imports A.cmx, in different mode w.r.t. flambda, the cross-module optimization information from A.cmx are ignored
(just as if A.cmx had been obtained by -opaque).  This also trigger a new warning 61 explaning the situation (instead of the above-mentioned error
message).

In addition, this removes some code duplication between asmpackager.ml and compilenv.ml.
utils/config.mlp Outdated
else
"Caml1999Z014"
and cmx_magic_number = "Caml1999Y015"
and cmxa_magic_number = "Caml1999Z014"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want to decrease the maximum magic. Future compiler versions would risk reusing Caml1999Y016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks. I'm now using the magic numbers that used to be for the flambda case.

@const-rs
Copy link
Copy Markdown
Contributor

const-rs commented Jul 19, 2016

Previously, different magic numbers were used, which leads to potentially cryptic error messages when trying to mix the two modes.

There are only two places which issue these messages - objinfo.ml and compilenv.ml.

In compilenv.ml to make things clear one can just add "(or outdated format)" to error message at the very end of the file - Not_a_unit_info. This will cover both .cmx and .cmxa files. Of course format may be too new, but it will give a hint in most situations.

@mshinwell
Copy link
Copy Markdown
Contributor

I would like to discuss this before any merge (I am on vacation at the moment).

@mshinwell
Copy link
Copy Markdown
Contributor

(In particular this is probably related to #620.)

@alainfrisch
Copy link
Copy Markdown
Contributor Author

(In particular this is probably related to #620.)

Well, the two PRs could be combined so that a single compiler could be used for flambda and non-flambda projects by installing two versions of the stdlib. That said, in practice, people are likely to use external packages (installed e.g. by OPAM), and I don't think we want to go to the direction where all installed packages would have to build and install multiple versions.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

@chambart, @mshinwell, @lpw25 : do you see big obstacles in allow a limited form of cross-module optimization between flambda and closure modes? My guess is that supporting direct function calls, even if not inlining, should be rather simple, no?

@alainfrisch
Copy link
Copy Markdown
Contributor Author

I would like to discuss this before any merge (I am on vacation at the moment).

Ping @mshinwell.

@mshinwell
Copy link
Copy Markdown
Contributor

Sorry, I failed to look at this one, and I'm about to be away again.

@alainfrisch To address your most recent comment, my general feeling is that we need to be looking to a world in which the old Closure code is removed. To that end, given how stretched we are on manpower, I think it's a much better use of time to work on speed improvements to Flambda rather than trying to achieve interoperability. I will let @lpw25 and @chambart comment.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

This specific PR is rather simple and low-risk. Do you have any objection on principle on having it integrated?

@chambart
Copy link
Copy Markdown
Contributor

I don't, as long as it is quite clear what are the limitation. Also there might be some reason for removing it later, if for instance the ABI has to change. It should be clear that it might happen.

@mshinwell mshinwell changed the title [WIP] Add -flambda/-no-flambda compile-time options to ocamlopt Add -flambda/-no-flambda compile-time options to ocamlopt Dec 28, 2016
@alainfrisch
Copy link
Copy Markdown
Contributor Author

Ok, our flambda gurus seem reluctant to the idea of allowing flambda and non-flambda code to interact (and I can see that this would be difficult for support if flambda changes the ABI). I don't think it is meaningful to push in this direction, then.

kayceesrk pushed a commit to ocaml-multicore/ocaml that referenced this pull request Oct 22, 2021
Cleanup fiber implementation and add documentation
lukemaurer pushed a commit to lukemaurer/ocaml that referenced this pull request Jul 19, 2022
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Sep 21, 2022
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Sep 21, 2022
ce76e02 flambda-backend: Bugfix for type_application (ocaml#746)
44f3afb flambda-backend: PR580 for main branch (ocaml#743)
b851eaa flambda-backend: Backport first part of ocaml/ocaml PR10498 (ocaml#737)
fafb4bd flambda-backend: Fix return mode for eta-expanded function in type_argument (ocaml#735)
c31f6c3 flambda-backend: Fix treatment of functions called [@nontail] (ocaml#725)
847781e flambda-backend: Fix build_upstream post-PR703 (ocaml#712)
bfcbbf8 flambda-backend: Extend Pblock value kind to handle variants (ocaml#703)
b2cab95 flambda-backend: Merge ocaml-jst
a6d6e0e flambda-backend: Merge ocaml-jst
88a4f63 flambda-backend: Use Pmakearray for immutable arrays (ocaml#699)
eeaa44b flambda-backend: Install an ocamldoc binary (ocaml#695)
48d322b flambda-backend: Ensure that GC is not invoked from bounds check failures (ocaml#681)
4370fa1 flambda-backend: Review changes of term directory (ocaml#602)
65a4566 flambda-backend: Add code coverage using bisect_ppx (ocaml#352)
63ab65f flambda-backend: Bugfix for primitive inclusion (ocaml#662)
7e3e0c8 flambda-backend: Fix inclusion checks for primitives (ocaml#661)
96c68f9 flambda-backend: Speed up linking by changing cmxa format (ocaml#607)
1829150 flambda-backend: Bugfix for Translmod.all_idents (ocaml#659)

git-subtree-dir: ocaml
git-subtree-split: ce76e02
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
* Ood code uniformization: paper

* Let metadata be the @@deriving yaml type
* Let Paper.t be an alias of Paper.metadata
* Misc required changes

* Formatting

Co-authored-by: Cuihtlauac ALVARADO <cuihtmlauac@tarides.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants