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

Basic classes: use cases, struct literals, struct types, and future work #561

Merged
merged 83 commits into from
Aug 9, 2021
Merged

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Jun 2, 2021

This proposal defines the very basics of class types, primarily focused on:

  • use cases including: data classes, encapsulated types, inheritance with and without virtual, interfaces as base classes, and mixins for code reuse;
  • anonymous data types for called structural data classes or struct types. Struct literals are used to initialize class values and ad-hoc parameter and return types with named components; and
  • future work, including the provisional syntax already in use for features that have not been decided.

The intent is to both make some small incremental progress and get agreement on direction. As such it doesn't include things like nominal types, methods, access control, inheritance, etc.

It proposes this struct type and literal syntax:

var p: {.x: Int, .y: Int} = {.x = 0, .y = 1};

Note that it uses commas (,) between fields instead of semicolons (;), and no introducer for types or literal values.

Incorporates decisions from #665 , #653 , #651

@josh11b josh11b added the proposal A proposal label Jun 2, 2021
@josh11b josh11b requested a review from a team June 2, 2021 22:59
@google-cla google-cla bot added the cla: yes PR meets CLA requirements according to bot. label Jun 2, 2021
@github-actions github-actions bot added the proposal rfc Proposal with request-for-comment sent out label Jun 26, 2021
@josh11b josh11b mentioned this pull request Aug 4, 2021
docs/design/classes.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.

Generally I think this is looking very good.

docs/design/classes.md Show resolved Hide resolved
docs/design/classes.md Outdated Show resolved Hide resolved
docs/design/classes.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.

LGTM

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.

Couple of super minor wording responses inline. Don't block on any of them though, ship it!

docs/design/classes.md Outdated Show resolved Hide resolved
in line with avoiding global variables more generally. Carbon may need some
support in this area, though, for parity with and migration from C++.

### Computed properties
Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. I just think we'll also want to consider non-computed properties. Anyways, no need to sweat the details of this section I think.

docs/design/classes.md Show resolved Hide resolved
@josh11b josh11b merged commit febf880 into carbon-language:trunk Aug 9, 2021
@josh11b josh11b deleted the structs-2 branch August 9, 2021 19:28
@github-actions github-actions bot added proposal accepted Decision made, proposal accepted and removed proposal rfc Proposal with request-for-comment sent out labels Aug 9, 2021
zygoloid added a commit that referenced this pull request Aug 28, 2021
… (#699)

This supports both struct type literals, `{.x: i32, .y: i32}`, and struct
value literals, `{.x = 3, .y = 4}`. The degenerate case of `{}` is
treated as a struct value literal, with the expectation that an empty
struct value has the same type/value duality as an empty tuple value.
chandlerc added a commit that referenced this pull request Jun 28, 2022
…ork (#561)

This proposal defines the very basics of `class` types, primarily focused on:

-   use cases including: data classes, encapsulated types, inheritance with and without `virtual`, interfaces as base classes, and mixins for code reuse;
-   anonymous data types for called _structural data classes_ or _struct types_. Struct literals are used to initialize class values and ad-hoc parameter and return types with named components; and
-   future work, including the provisional syntax already in use for features that have not been decided.

The intent is to both make some small incremental progress and get agreement on direction. As such it doesn't include things like nominal types, methods, access control, inheritance, etc.

It proposes this struct type and literal syntax:
```
var p: {.x: Int, .y: Int} = {.x = 0, .y = 1};
```
Note that it uses commas (`,`) between fields instead of semicolons (`;`), and no introducer for types or literal values.

Incorporates decisions from #665 , #653 , #651


Co-authored-by: Geoff Romer <[email protected]>
Co-authored-by: Chandler Carruth <[email protected]>
chandlerc pushed a commit that referenced this pull request Jun 28, 2022
… (#699)

This supports both struct type literals, `{.x: i32, .y: i32}`, and struct
value literals, `{.x = 3, .y = 4}`. The degenerate case of `{}` is
treated as a struct value literal, with the expectation that an empty
struct value has the same type/value duality as an empty tuple value.
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.

4 participants