Allow shadowing of items coming from an include#1892
Merged
trefis merged 4 commits intoocaml:trunkfrom Jul 25, 2018
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.mland revolves aroundcheck_nameandsimplify_signature.Previously:
check_namewas checking that all names in a signature were unique (excluding value names for which the check wasn't called)simplify_signaturewas dropping shadowed value names from a signature.Now:
check_namekeeps track of what can (or not) be shadowed, and errors when one tries to shadow something that's not allowed to besimplify_signaturedrops shadowed items from a signature, and callsnondep_*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.