Skip to content

Restore a call to instance that was dropped in #12236#12542

Merged
gasche merged 3 commits intoocaml:trunkfrom
ncik-roberts:extra-call-to-instance-when-typing-constraints
Sep 15, 2023
Merged

Restore a call to instance that was dropped in #12236#12542
gasche merged 3 commits intoocaml:trunkfrom
ncik-roberts:extra-call-to-instance-when-typing-constraints

Conversation

@ncik-roberts
Copy link
Copy Markdown
Contributor

@ncik-roberts ncik-roberts commented Sep 9, 2023

#12236 dropped a possibly-load-bearing call to instance from the type-checking of Pexp_constraint: see the second component of the tuple on this removed line. This PR restores it.

I am unable to find a way that this change matters. I happened to notice the discrepancy while reading through #12236 for a related change internal to Jane Street. The main difference between pre-#12236 and post-#12236 code that I can think of is:

  • pre-Syntactic function arity #12236, the exp_type field of the result of type-checking Pexp_constraint was an instance of a possibly-generic type. (In particular, it was this result of this now-restored call to instance.)
  • post-Syntactic function arity #12236, the exp_type field of the result of type-checking Pexp_constraint can possibly be a type with generic level (and not an instance thereof).

I've been unable to find a way that this discrepancy results in a change in principality warnings/errors/etc. It's possible this current PR is just not needed! Either this call to instance is needed and this PR fixes an unintentional change in behavior, or it's not needed and I'll have learned something new about the type-checker.

Copy link
Copy Markdown
Contributor

@garrigue garrigue left a comment

Choose a reason for hiding this comment

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

Trivially correct.
The reason you cannot detect the difference is that rue unifies with an instance of the expected type, so the levels will be lowered anyway. And since the polymorphism of the structure is only used locally, it doesn't matter if those levels are lowered afterwards.
This said the current code is morally wrong (plain wrong if we prohibit lowering generic_level through unification, as I plan to do) and this fixes it.

@ncik-roberts
Copy link
Copy Markdown
Contributor Author

Thanks, the explanation makes sense. I think this PR is ready to merge then.

@gasche gasche merged commit 1a6784f into ocaml:trunk Sep 15, 2023
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.

3 participants