Skip to content

Improve compilation time for toplevel include(struct ... end : sig ... end)#832

Merged
alainfrisch merged 2 commits intoocaml:trunkfrom
alainfrisch:fix_7357
Dec 21, 2016
Merged

Improve compilation time for toplevel include(struct ... end : sig ... end)#832
alainfrisch merged 2 commits intoocaml:trunkfrom
alainfrisch:fix_7357

Conversation

@alainfrisch
Copy link
Copy Markdown
Contributor

This is intended to fix MPR#7357, which uses the natural way of specifying an inline signature for a unit without using an external .mli file.

The trick is similar to the one applied for compiling module X = (struct ... end : sig ... end). Identifiers of the inner structure are "lifted" as extra fields of the top-level structure.

I'd argue this special case is relevant since it corresponds to the natural way of restricting a unit's signature without specifying an external .mli file. For instance, the change would be beneficial to #217 or to people using that encoding manually.

The trick is currently not applied to include (struct .... end); it would not be difficult to do so, but there is no real reason to use that form anyway (except perhaps to simplify code generators, or to customize warnings locally in a section), and one might argue that simplifying that to just the inner structure should be done earlier in the compilation process.

A minor point: I'm not sure about the call to Translattribute.check_attribute_on_module. In the current version, attributes on the include structure item are considered, not attributes on the either of the two module expression (the Tmod_structure and Tmod_constraint nodes). This is similar to what was done for the Tstr_module cases (starting from 58d6da1), but it does not look right to me. @chambart Can you comment?

@bobzhang
Copy link
Copy Markdown
Member

bobzhang commented Oct 3, 2016

thanks for the quick fix.
Note that include (struct .. end ) is still useful for local open in code generator, but it is not a high priority.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

Does anyone want to review this?

@alainfrisch
Copy link
Copy Markdown
Contributor Author

@garrigue Do you want to review this?

@chambart Can you comment on the attribute stuff (I think it was introduced by you in the existing case, which I only mimic here)?

@garrigue
Copy link
Copy Markdown
Contributor

I'm not sure I'm the best qualified to review this (except for having introduced my share of bugs in this part of the compiler).
Anyway, the code is clean, compact and non-intrusive, so if it passes the testsuite I would be tempted to say this is fine.
The improvement is limited to a specific pattern, but I understand it is an important one, particularly for generated code.

@alainfrisch
Copy link
Copy Markdown
Contributor Author

alainfrisch commented Dec 13, 2016

Thanks @garrigue. Waiting a few days before merging in case @chambart's wants to comment about the attributes stuff.

…. end)

This is intended to fix MPR#7357, which uses the natural way
of specifying an inline signature for a unit without using an external
.mli file.

The trick is similar than the one applied for compiling

  module X = (struct ... end : sig ... end)

Identifiers of the inner structure are "lifted" as extra fields
to the top-level structure.
@alainfrisch
Copy link
Copy Markdown
Contributor Author

Rebased and added a Changelog.

@alainfrisch alainfrisch merged commit 9dbcb1e into ocaml:trunk Dec 21, 2016
@alainfrisch alainfrisch deleted the fix_7357 branch December 21, 2016 13:38
camlspotter pushed a commit to camlspotter/ocaml that referenced this pull request Oct 17, 2017
…. end) (ocaml#832)

* Improve compilation time for toplevel include(struct ... end : sig ... end)

This is intended to fix MPR#7357, which uses the natural way
of specifying an inline signature for a unit without using an external
.mli file.

The trick is similar than the one applied for compiling

  module X = (struct ... end : sig ... end)

Identifiers of the inner structure are "lifted" as extra fields
to the top-level structure.

* Changelog.
ctk21 added a commit to ocaml-multicore/ocaml that referenced this pull request Jan 7, 2022
sadiqj pushed a commit to sadiqj/ocaml that referenced this pull request Jan 7, 2022
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Sep 21, 2022
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
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.

3 participants