-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Generic parameterized impls (details 5) #920
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
josh11b
changed the title
Generic blanket impls and access control (details 4)
Generic blanket impls(details 5)
Oct 29, 2021
josh11b
changed the title
Generic blanket impls(details 5)
Generic blanket impls (details 5)
Oct 29, 2021
josh11b
changed the title
Generic blanket impls (details 5)
Generic parameterized impls (details 5)
Nov 2, 2021
github-actions
bot
added
the
proposal rfc
Proposal with request-for-comment sent out
label
Nov 10, 2021
zygoloid
reviewed
Dec 7, 2021
Co-authored-by: Richard Smith <[email protected]>
Co-authored-by: Richard Smith <[email protected]>
Co-authored-by: Richard Smith <[email protected]>
zygoloid
reviewed
Dec 9, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great! No further comments from me.
zygoloid
approved these changes
Dec 9, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go ahead.
github-actions
bot
added
proposal accepted
Decision made, proposal accepted
and removed
proposal rfc
Proposal with request-for-comment sent out
labels
Dec 9, 2021
chandlerc
pushed a commit
that referenced
this pull request
Jun 28, 2022
There are cases where an impl definition should apply to more than a single type and interface combination. The solution is to parameterize the impl definition, so it applies to a family of types, interfaces, or both. This includes: - Declare an impl for a parameterized type, which may be external or declared out-of-line. ``` external impl [T:! Type] Vector(T) as Iterable { ... } external impl Vector(T:! Type) as Iterable { ... } ``` - "Conditional conformance" where a parameterized type implements some interface if the parameter to the type satisfies some criteria, like implementing the same interface. ``` external impl [T:! Type] Pair(T, T) as Foo(T) { ... } class Array(T:! Type, template N:! Int) { impl [P:! Printable] Array(P, N) as Printable { ... } impl Array(P:! Printable, N) as Printable { ... } } ``` - "Blanket" impls where an interface is implemented for all types that implement another interface, or some other criteria beyond being a specific type. ``` external impl [T:! Ordered] T as PartiallyOrdered { ... } ``` - "Wildcard" impls where a family of interfaces are implemented for single type. ``` class BigInt { external impl [T:! ImplicitAs(i32)] as AddTo(T) { ... } external impl as AddTo(T:! ImplicitAs(i32)) { ... } } external impl [T:! ImplicitAs(i32)] BigInt as AddTo(T) { ... } external impl BigInt as AddTo(T:! ImplicitAs(i32)) { ... } ``` In addition to a syntax for defining parameterized impls, we need rules for coherence: - Orphan rules that ensure that impls are imported in any code that might use it. - We need overlap rules that pick a specific impl when more than one impl declaration matches a specific query about whether a type implements an interface. Co-authored-by: Richard Smith <[email protected]>
github-merge-queue bot
pushed a commit
that referenced
this pull request
Aug 2, 2023
This reflects changes from a number of approved proposals: - #920 : concrete statements about orphan and overlap in Carbon - #2138 : "generic" -> "checked generic", "template" -> "template generic" - #2188 : binding patterns are forbidden in type position - #2360 : "type", "facet type", "facet". Note: I am not using the term "generic type" from #2360 since that meaning conflicts with the generally accepted meaning of "generic type" of a type with a compile-time parameter. - #2760 / #2770 : internal/external impl -> extending impl - #2964 : "symbolic constant" and "template constant" --------- Co-authored-by: Geoff Romer <[email protected]> Co-authored-by: Richard Smith <[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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are cases where an impl definition should apply to more than a single type and interface combination. The solution is to parameterize the impl definition, so it applies to a family of types, interfaces, or both. This includes:
In addition to a syntax for defining parameterized impls, we need rules for coherence: