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

Clarify rules around Self and .Self #2107

Merged
merged 6 commits into from
Sep 8, 2022
Merged

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Aug 25, 2022

A number of smaller changes grouped together in one proposal:

  • Make Self a keyword.
  • Clarify that Self refers to the current type in a base class and in impl declarations.
  • Clarify when .Self is legal, and what type it has.
  • Also specify that where is not an associative operator.

@josh11b josh11b added proposal A proposal proposal draft Proposal in draft, not ready for review labels Aug 25, 2022
@josh11b josh11b marked this pull request as ready for review August 30, 2022 04:53
@josh11b josh11b requested a review from zygoloid August 30, 2022 04:53
@github-actions github-actions bot added proposal rfc Proposal with request-for-comment sent out and removed proposal draft Proposal in draft, not ready for review labels Aug 30, 2022
@github-actions github-actions bot requested a review from jonmeow August 30, 2022 04:53
Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Comment on lines +2835 to +2836
fn F[T:! InterfaceA where .A is
(InterfaceB where .B == .Self)](x: T);
Copy link
Contributor

Choose a reason for hiding this comment

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

Getting a bit into the fine details here, what happens for:

fn F[T:! InterfaceA where .Self is 
             (InterfaceB where .B == .Self)](x: T);

? The second .Self arguably only means one thing here -- it resolves to T -- but that fact is somewhat obscured via the indirection through the first .Self.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As written, I agree that would be allowed. Do you think that should change? We could instead have a rule about is expression in where clauses. What happens when we greatly expand the kinds of expressions in where clauses for templates?

I'm mostly looking for a rule with a concise and easy-to-remember statement.

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 we also need to think about implementability, for example for:

fn F[T:! Identity(InterfaceA where .T == .Self)]();

I'd prefer a rule that can be checked immediately and locally. I think the current rule would require an instance of .Self to track all the possible results until we reach some enclosing context where we can resolve them and see if they're the same. Maybe we can special-case a where expression as the top-level expression on the right of a :! and treat all other cases as being immediately ambiguous?

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

LG for me as well, so I think we have consensus among leads. (Kate is out sick at the moment.)

@josh11b josh11b merged commit e4595de into carbon-language:trunk Sep 8, 2022
@josh11b josh11b deleted the s2 branch September 8, 2022 20:22
@chandlerc chandlerc added the documentation An issue or proposed change to our documentation label Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation An issue or proposed change to our documentation proposal rfc Proposal with request-for-comment sent out proposal A proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants