Skip to content

Warning for missing .cmx files#319

Merged
gasche merged 6 commits intoocaml:trunkfrom
lpw25:opaque-cmis
Dec 26, 2015
Merged

Warning for missing .cmx files#319
gasche merged 6 commits intoocaml:trunkfrom
lpw25:opaque-cmis

Conversation

@lpw25
Copy link
Copy Markdown
Contributor

@lpw25 lpw25 commented Nov 29, 2015

This patch adds a warning for missing cmx files during cross-module inlining. This is useful because currently a misspecified build can silently damage the performance of programs.

The patch also extends the -opaque option to work on .mli files. Using -opaque on an .ml file means that its implementation should not be considered for cross-module inlining. Using -opaque on an .mli file means that no implementation of that interface should be considered for cross-module inlining.

If an interface is marked as opaque then the compiler does not search for a .cmx file, and so the new warning will not be triggered. This means that modules which are intended to be chosen at link-time (and so deliberately hide .cmx files) can avoid unnecessarily triggering the warning.

As an illustration of the utility of this new warning, not all cmx files were installed by the OCaml distribution, and the patch also adjusts the installation rules to install these files (which were in compiler-libs and ocamldoc).

@gasche
Copy link
Copy Markdown
Member

gasche commented Nov 29, 2015

Using -opaque on an .ml file means that its implementation should not be considered for cross-module inlining. Using -opaque on an .mli file means that no implementation of that interface should be considered for cross-module inlining.

I have a more semantic/indirect definition for what -opaque is, or at least should be: -opaque should guarantee that, if a module that is compiled with -opaque changes its implementation and gets recompiled, then its dependencies do not need to be recompiled as well. For now I think that both definitions coincide, but that is the "no implementation-dependency on opaque modules" that needs to be preserved in the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code is duplicated twice, here and in Env. Would it make sense to factorize it into a Cmi_format.global_pers_flags () function?

Also with my nitpicking hat on, I think you could factorize this as

  []
  @ (if !Clflags.recursive_types then [Cmi_format.Rectypes] else [])
  @ (if !Clflags.opaque then [Cmi_format.Opaque] else [])

@gasche
Copy link
Copy Markdown
Member

gasche commented Nov 29, 2015

I like the feature, and the code seems fairly simple and very reasonable. In favor.

@lpw25
Copy link
Copy Markdown
Contributor Author

lpw25 commented Nov 30, 2015

I have a more semantic/indirect definition for what -opaque is, or at least should be: -opaque should guarantee that, if a module that is compiled with -opaque changes its implementation and gets recompiled, then its dependencies do not need to be recompiled as well.

I would actually go further and define it in terms of being able to choose between different implementations at link-time.

@lpw25
Copy link
Copy Markdown
Contributor Author

lpw25 commented Nov 30, 2015

I'll tidy up the code, warning message and changes file this evening.

@gasche
Copy link
Copy Markdown
Member

gasche commented Dec 6, 2015

I wanted to merge this PR right now, but in fact it now conflicts with @alainfrisch 's change on compilation unit deprecation. Could you rebase the patchset against the current trunk? In addition, it would be nice if you could:

  • squash the minor fixup commits (it's nice to have separate commits for modified install rules, but the rest is just noise)
  • add a very small testsuite exercising both -opaque on ml files (the test could simply modify the source, rebuild and relink as a way to check that a dependency was really seing the compilation unit as opaque), on mli files (same thing, but with -opaque passed earlier in the compilation chain), and the warning.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be "its".

@damiendoligez damiendoligez added this to the 4.03.0 milestone Dec 21, 2015
@lpw25
Copy link
Copy Markdown
Contributor Author

lpw25 commented Dec 25, 2015

I've fixed the message, rebased and added tests for both -opaque and the new warning.

typing/env.ml Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this last line should be parenthesized or use begin .. end.

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.

Done

gasche added a commit that referenced this pull request Dec 26, 2015
Warning for missing .cmx files
@gasche gasche merged commit eab493d into ocaml:trunk Dec 26, 2015
@gasche
Copy link
Copy Markdown
Member

gasche commented Dec 26, 2015

Nice PR, thanks!

@gasche
Copy link
Copy Markdown
Member

gasche commented Jan 5, 2016

@lpw25 with more usage experience, there is one aspect of this change that I'm not fully satisfied with: it is the fact that -opaque is only supported by ocamlopt, not ocamlc. This means that people that want to compile a .mli to produce an opaque .cmi have to use ocamlopt -opaque, and cannot use ocamlc -opaque for this purpose. This changes the previously-true property that either compiler can be used to compile interfaces, and I wouldn't be surprised if some makefiles or build systems relied on it.

I think that with your change, we should add -opaque as an option to ocamlc as well. If you agree, would you maybe have the time to do this change in the following days? (I probably don't, but we could consider asking someone else.)

@lpw25
Copy link
Copy Markdown
Contributor Author

lpw25 commented Jan 5, 2016

I completely agree, in fact I consider this to be a bug as it was not intentional. However, I'm not sure that I'll have time to look at this in the next few days.

@damiendoligez
Copy link
Copy Markdown
Member

ping

poechsel added a commit to poechsel/ocaml that referenced this pull request Feb 24, 2021
poechsel added a commit to poechsel/ocaml that referenced this pull request Mar 1, 2021
poechsel added a commit to poechsel/ocaml that referenced this pull request Mar 1, 2021
chambart pushed a commit to chambart/ocaml-1 that referenced this pull request Jan 4, 2022
)

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Co-authored-by: Rahul Kumar <rkumar85@bloomberg.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants