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

Template generics #2200

Merged
merged 34 commits into from
Nov 17, 2022
Merged

Template generics #2200

merged 34 commits into from
Nov 17, 2022

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Sep 20, 2022

Add template generics, with optional constraints but no SFINAE, to Carbon. Template generics allows the compiler postpone type checking of expressions dependent on a template parameter until the function is called and the value of that parameter is known.

Example usage:

fn Identity[template T:! Type](x: T) -> T {
  return x;
}

@josh11b josh11b added proposal A proposal proposal draft Proposal in draft, not ready for review labels Sep 20, 2022
@josh11b josh11b changed the title Basic templates Template generics Sep 22, 2022
@josh11b josh11b marked this pull request as ready for review October 6, 2022 21:48
@josh11b josh11b requested a review from zygoloid October 6, 2022 21:49
@github-actions github-actions bot requested a review from jonmeow October 6, 2022 21:49
@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 Oct 6, 2022
@josh11b josh11b removed the request for review from jonmeow October 6, 2022 21:49
@josh11b
Copy link
Contributor Author

josh11b commented Oct 11, 2022

@zygoloid I added an update aa5cb72 to include our discussion about what is dependent from 10-10

proposals/p2200.md Outdated Show resolved Hide resolved
## Abstract

Add template generics, with optional constraints but no SFINAE, to Carbon.
Template generics allows the compiler postpone type checking of expressions
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I have a better word to suggest, but "allows" seems misleading here. This is more "requires" I think?

But more broadly, I wonder if we should put the emphasis differently, on the user instead of the compiler, maybe something like: template generics allows a developer to write code against the interface of a family of types that share a common API, even if the specific types are not known where the template is defined and the API is not formally defined.

proposals/p2200.md Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated 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.

Thanks, looks good. I don't have any blocking concerns.

proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide resolved
proposals/p2200.md Show resolved Hide resolved
proposals/p2200.md Outdated Show resolved Hide 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.

(just a drive by comment, all of this looks great to me)

proposals/p2200.md Outdated Show resolved Hide resolved
@josh11b josh11b merged commit c9a1e35 into carbon-language:trunk Nov 17, 2022
@josh11b josh11b deleted the template branch November 17, 2022 18:23
josh11b added a commit to josh11b/carbon-lang that referenced this pull request Aug 31, 2023
github-merge-queue bot pushed a commit that referenced this pull request Sep 6, 2023
Follow-on to #3160. Incorporates decision about template specialization
from #2200.
github-merge-queue bot pushed a commit that referenced this pull request Sep 8, 2023
Incorporates proposals: #1885, #2138, #2188, #2200, #2360, #2760, #2964,
and #3162.

---------

Co-authored-by: Richard Smith <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Sep 19, 2023
First step in updating `docs/design/generics/details.md`. It
incorporates changes from proposals: #989 #2138 #2173 #2200 #2360 #2964
#3162 , but there are still more changes from those proposals to be
made.

It also switches away from suggesting static-dispatch witness tables,
and creates an appendix to describe that decision.

---------

Co-authored-by: Richard Smith <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Sep 23, 2023
Includes proposals:
- #990
- #2188
- #2138
- #2200
- #2360
- #2760
- #2964
- #3162

Also tries to use more precise language when talking about:
- implementations, to avoid confusing `impl` declaration and definitions
with the `impls` operator used in `where` clauses, an issue brought up
in #2495 and #2483;
- "binding patterns", like `x: i32`, and "bindings" like `x`.

---------

Co-authored-by: Chandler Carruth <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Oct 3, 2023
Continued from part 1: #3231. Second step updating
`docs/design/generics/details.md`. There remains some work to
incorporate proposal #2200.

- The biggest changes are incorporating much of the text of proposals:
  - #2173
  - #2687
- It incorporates changes from proposals:
  - #989
  - #1178
  - #2138
  - #2200
  - #2360
  - #2964
  - #3162
- It also updates the text to reflect the latest thinking from leads
issues:
  - #996
  - #2153 -- most notably deleting the section on `TypeId`.
- Update to rule for prioritization blocks with mixed type structures
from [discussion on
2023-07-18](https://docs.google.com/document/d/1gnJBTfY81fZYvI_QXjwKk1uQHYBNHGqRLI2BS_cYYNQ/edit?resourcekey=0-ql1Q1WvTcDvhycf8LbA9DQ#heading=h.7jxges9ojgy3)
- Adds reference links to proposals, issues, and discussions relevant to
the text.
- Also tries to use more precise language when talking about
implementations, to avoid confusing `impl` declaration and definitions
with the `impls` operator used in `where` clauses, an issue brought up
in
  - #2495 
  - #2483

---------

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
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