Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readability improvements around instance_constructor #10987

Merged
merged 4 commits into from
Mar 4, 2022

Conversation

trefis
Copy link
Contributor

@trefis trefis commented Feb 3, 2022

Sorry for the highly controversial PR which is neither related to multicore, nor fixing any bug.

As I said earlier, I was a bit confused (I'm easily confused) when trying to review #10959. The parts which confused me are actually related to #9584.
Anyway, I'm proposing 3 commits which shouldn't change at all the observable behavior of the compiler, but which make things slightly more readable in my opinion:

  • 7d8a99b : when reading instance_constructor without being careful, it seemed like we were sometimes (when in_pattern is Some) turning existentials into local types, then taking a different instance of the existentials, and returning that, ignoring the abstract types.
    That's of course not what happens: everything lives in the same "copy scope", so the second instance actually encounter a Tsubst nodes and gets the local type from before. It was a bit too subtle for me though. So I changed the code to only take one obvious instance of the existentials.
    (That's of course not quite true: another instance will be taken when getting a copy of ty_args ... so I'll admit that it's debatable that this commit actually makes things more readable)
  • c8404b1 and 3eba0b6 : I'm a lot more confident about the value of those! The criterion for turning existentials into local types was previously to be typing a pattern, justifying the in_pattern argument to instance_constructor. Now it's to be typing a pattern where the existentials haven't been explicitely named, so I feel justified in changing in_pattern for something indicating which behavior to adopt, rather than which context we were being called from a few versions of OCaml ago.

Please forgive me.

@trefis
Copy link
Contributor Author

trefis commented Feb 15, 2022

Ping @gasche (as he invited me to ping him explicitely).

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

Thanks for the ping! I was just reading this code this afternoon with Olivier Martinot...

I'm fine with the change, I believe it is correct, and I agree that the new names are clearer.

See various review comments.

typing/ctype.ml Show resolved Hide resolved
typing/typecore.ml Outdated Show resolved Hide resolved
typing/typecore.ml Show resolved Hide resolved
let (args, cstr_res, _ex) = Ctype.instance_constructor cdescr in
let (args, cstr_res, _ex) =
Ctype.instance_constructor Keep_existentials_flexible cdescr
in
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, do we know what happens here? _ex is ignored, so we cannot have existentials at this point? Or can there, and keeping existentials flexible is the right thing? (I guess we re-generalize later?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand you're question... but keeping existential variables flexible here does seem like the right thing yes.

@trefis trefis merged commit cfb362b into ocaml:trunk Mar 4, 2022
@trefis trefis deleted the instance_constructor branch March 4, 2022 17:33
@trefis
Copy link
Contributor Author

trefis commented Mar 4, 2022

The CI passed, so I merged.

Thanks for the review @gasche !

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

Successfully merging this pull request may close these issues.

None yet

2 participants