Skip to content

Deprecation warning when checking signature inclusion#1138

Merged
alainfrisch merged 17 commits intoocaml:trunkfrom
alainfrisch:pr7444_deprecated_warning_upon_inclusion
May 15, 2017
Merged

Deprecation warning when checking signature inclusion#1138
alainfrisch merged 17 commits intoocaml:trunkfrom
alainfrisch:pr7444_deprecated_warning_upon_inclusion

Conversation

@alainfrisch
Copy link
Contributor

@alainfrisch alainfrisch commented Apr 5, 2017

https://caml.inria.fr/mantis/view.php?id=7444

Deprecation warning (3) is currently only reported when directly
accessing a component marked with the deprecated attribute; but it is
missed when we coerce the signature containing the deprecated component
to a signature without the attribute.

This PR adds the required machinery to detect such cases
and report the same warning. An alternative design could be
to introduce a new warning for that purpose. Do people believe one
should reuse the existing warning, or introduce a new one?

Another design choice is that only the presence of the deprecated attribute is checked. Changing the payload of the attribute does not trigger the warning.

Some of the new machinery could be used for other purposes:

  • During the inclusion check, keep the location that would used in
    the error message if the check fails.

  • Warnings can now hold extra "sub-locations" (and associated
    messages).

One case of a missing attribute was found on StringLabels.copy (after
bootstrapping the compiler).

All kinds of deprecated attributes are supported (on values, types, constructors, class/class types, module/module types; and also the "deprecated_mutable" attribute on record labels).

Deprecation warning (3) is currently only reported when directly
accessing a component marked with the deprecated attribute; but it is
missed when we coerce the signature contaning the deprecated component
to a signature without the attribute.

This commit adds the required machinery to detect such cases
and report the same warning. (An alternative design could be
to introduce a new warning for that purpose.)

Some of the new machinery could be used for other purposes:

  - During the inclusion check, keep the location that would used in
    the error message if the check fails.

  - Warnings can now hold extra "sub-locations" (and associated
    messages).
@alainfrisch
Copy link
Contributor Author

@let-def Do you think that adding the definition of Location.loc to Warnings (with a re-export from Location) could create problem with ocaml-migrate-parsetree?

@let-def
Copy link
Contributor

let-def commented Apr 5, 2017

No that seems fine. (The signature of Location will still be compatible)

It sounds weird to have the definition of locations in Warnings module, even though I can understand why it is that way.

@alainfrisch
Copy link
Contributor Author

Well, what is really weird is that Location (which should be rather generic) depends on Warning, and not the other way around.

@let-def
Copy link
Contributor

let-def commented Apr 5, 2017

Ahah, I agree. From migrate-parsetree point I wasn't paying attention to the dep on Warnings.

@alainfrisch alainfrisch changed the title [WIP] Deprecation warning when checking signature inclusion Deprecation warning when checking signature inclusion May 9, 2017
@alainfrisch
Copy link
Contributor Author

Implementation extended to all kinds of component which support the deprecated attribute. Added a test and a changelog entry. Now ready for review.

@alainfrisch
Copy link
Contributor Author

Is anyone interested to review this?

typing/env.ml Outdated
begin match get_components desc1 with
Functor_comps f ->
Misc.may (!check_modtype_inclusion env mty2 p2) f.fcomp_arg;
Misc.may (!check_modtype_inclusion ~loc:(match loc with Some l -> l | None -> Location.none) env mty2 p2) f.fcomp_arg;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this line is too long (and a bit messy). Could you lift the (match loc ...) bit out to it's own binding.

typing/env.ml Outdated
begin match get_components desc1 with
Functor_comps f ->
Misc.may (!check_modtype_inclusion env mty2 p2) f.fcomp_arg;
Misc.may (!check_modtype_inclusion ~loc:(match loc with Some l -> l | None -> Location.none) env mty2 p2) f.fcomp_arg;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

loc
cty1.clty_attributes cty2.clty_attributes
(Path.last cty1.clty_path);

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: I find this blank line makes it hard to see what is actually in class_type_declarations. I think leaving blank lines in the middle of definitions is against the unwritten style guide of the compiler.

loc
cd1.cd_attributes cd2.cd_attributes
(Ident.name cd1.cd_id);

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Unnecessary blank line hinders readability.

loc
ld1.ld_attributes ld2.ld_attributes
(Ident.name ld1.ld_id);

Copy link
Contributor

Choose a reason for hiding this comment

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

Sames as above

loc
decl1.type_attributes decl2.type_attributes
name;

Copy link
Contributor

Choose a reason for hiding this comment

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

And another

loc
md1.md_attributes md2.md_attributes
(Ident.name id1);

Copy link
Contributor

Choose a reason for hiding this comment

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

Unecessary blank line hinders readability

loc
info1.mtd_attributes info2.mtd_attributes
(Ident.name id);

Copy link
Contributor

Choose a reason for hiding this comment

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

As above

let type_declarations env id decl1 decl2 =
type_declarations env [] Subst.identity id decl1 decl2
let modtypes ~loc env mty1 mty2 = modtypes ~loc env [] Subst.identity mty1 mty2
let signatures env sig1 sig2 =
Copy link
Contributor

@lpw25 lpw25 May 15, 2017

Choose a reason for hiding this comment

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

It seems inconsistent for signatures not to have a loc parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Includemod.signatures is only used in context which could not trigger the warning, I believe (in {opt,}{compile,toploop}.ml). Moreover the resulting coercion is ignored in those cases. Perhaps it would be better to expose a more specific function (better name and a unit result) to cover those cases (do you happen to remember why we need to check self-inclusion of signatures e.g. in compiler.ml?). But this is not really related to this PR anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Ah, this could be used to mark the exported declarations as being used, to avoid the unused warnings.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough

@lpw25
Copy link
Contributor

lpw25 commented May 15, 2017

I left a few style comments, but it all looks correct to me.

@lpw25 lpw25 added the approved label May 15, 2017
@alainfrisch alainfrisch merged commit 1a93a20 into ocaml:trunk May 15, 2017
@alainfrisch
Copy link
Contributor Author

Thanks @lpw25!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants