Skip to content

Allow shadowing of items coming from an include#1892

Merged
trefis merged 4 commits intoocaml:trunkfrom
trefis:shadow-includes
Jul 25, 2018
Merged

Allow shadowing of items coming from an include#1892
trefis merged 4 commits intoocaml:trunkfrom
trefis:shadow-includes

Conversation

@trefis
Copy link
Copy Markdown
Contributor

@trefis trefis commented Jul 10, 2018

This GPR implements the change described in https://blog.janestreet.com/plans-for-ocaml-408/#shadowing-of-items-from-include.

Most of the actual work happens in typemod.ml and revolves around check_name and simplify_signature.

Previously:

  • check_name was checking that all names in a signature were unique (excluding value names for which the check wasn't called)
  • simplify_signature was dropping shadowed value names from a signature.

Now:

  • check_name keeps track of what can (or not) be shadowed, and errors when one tries to shadow something that's not allowed to be
  • simplify_signature drops shadowed items from a signature, and calls nondep_* to remove reference to the shadowed items from the ones that remain. That last step is not guaranteed to succeed, and a error message is printed when it fails.

All the other changes qualify as plumbing (to get vaguely decent error messages, to not call nondep_* in a loop, etc.).

I'm not all that fond of the error message that is emitted when something cannot be shadowed, (see testsuite/tests/shadow_include/cannot_shadow_error.{ml,compilers.reference} for an example), so if someone has a better formulation, I'd be happy to integrate it.

The last commit ("check for repeated name after having typed the item") is not strictly necessary for this PR, but it makes the implementation a bit more regular.

A note on performances: for the moment we always call nondep_, even though there might be no ident to hide (more clearly: we should call nondep only when an ident which can appear in a type gets shadowed). I plan to add one last commit to that, but I think one can already start to look at this PR even without that.

Loading
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.

7 participants