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

Constraints for generics (generics details 3) #818

Merged
merged 95 commits into from
Oct 30, 2021
Merged

Constraints for generics (generics details 3) #818

merged 95 commits into from
Oct 30, 2021

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Sep 7, 2021

This proposal describes where clauses that can add constraints on a type-of-type, for example define restrictions on its associated types. Example:

fn FindFirstPrime[T:! Container where .Element = i32]
    (c: T) -> Optional(i32) {
  // The elements of `c` have type `T.Element`, which is `i32`.
  ...
}

fn PrintContainer[T:! Container where .Element is Printable](c: T) {
  // The type of the elements of `c` is not known, but we do know
  // that type satisfies the `Printable` interface.
  ...
}

Some other constraints, such as Sized are defined as type-of-types directly, possibly parameterized.

@josh11b josh11b added the proposal A proposal label Sep 7, 2021
@josh11b josh11b requested a review from a team September 7, 2021 20:54
@google-cla google-cla bot added the cla: yes PR meets CLA requirements according to bot. label Sep 7, 2021
@josh11b josh11b changed the title Constraints for generics Constraints for generics (generics details 3) Sep 7, 2021
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.

I've not tried to do a complete or super detailed review, but I wanted to explicitly say I've gone through this at a high level and I'm really happy. The problems here are remarkably hard, and I feel like this is a really compelling set of solutions. I also think the analysis, explanation, comparisons, and alternatives are fantastic.

I've left a bunch of pretty minor comments as I went through. Many are really questions or ideas for the future, and completely not blocking. Others are optional or super minor. Don't wait on me for landing this. =D

docs/design/generics/details.md Outdated Show resolved Hide resolved
docs/design/generics/details.md Outdated Show resolved Hide resolved
docs/design/generics/details.md Outdated Show resolved Hide resolved
docs/design/generics/details.md Show resolved Hide resolved
docs/design/generics/details.md Outdated Show resolved Hide resolved
docs/design/generics/details.md Show resolved Hide resolved
docs/design/generics/details.md Outdated Show resolved Hide resolved
proposals/p0818.md Show resolved Hide resolved
proposals/p0818.md Outdated Show resolved Hide resolved
docs/design/generics/details.md Show resolved Hide resolved
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.

I'm very happy with this.

@chandlerc, I think all the remaining unresolved comment threads are yours. I'm happy with you going ahead and approving once they're resolved.

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.

Nice!

proposals/p0818.md Show resolved Hide resolved
docs/design/generics/details.md Outdated Show resolved Hide resolved
@josh11b josh11b merged commit a0d8122 into carbon-language:trunk Oct 30, 2021
@josh11b josh11b deleted the constraints branch October 30, 2021 03:32
@github-actions github-actions bot added proposal accepted Decision made, proposal accepted and removed proposal rfc Proposal with request-for-comment sent out labels Oct 30, 2021
chandlerc added a commit that referenced this pull request Jun 28, 2022
This proposal describes `where` clauses that can add constraints on a type-of-type, for example define restrictions on its associated types. Example:

```
fn FindFirstPrime[T:! Container where .Element = i32]
    (c: T) -> Optional(i32) {
  // The elements of `c` have type `T.Element`, which is `i32`.
  ...
}

fn PrintContainer[T:! Container where .Element is Printable](c: T) {
  // The type of the elements of `c` is not known, but we do know
  // that type satisfies the `Printable` interface.
  ...
}
```

Some other constraints, such as `Sized` are defined as type-of-types directly, possibly parameterized.

Co-authored-by: Richard Smith <[email protected]>
Co-authored-by: Chandler Carruth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes PR meets CLA requirements according to bot. proposal accepted Decision made, proposal accepted proposal A proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants