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

An incomplete, early, and in-progress overview of the language design. #83

Merged
merged 70 commits into from
Jul 30, 2020
Merged

An incomplete, early, and in-progress overview of the language design. #83

merged 70 commits into from
Jul 30, 2020

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Jun 17, 2020

Co-authored by: chandlerc

This proposal should be considered a starting point of the language design. It's not intended to be final; language details may change. This is intended to offer a reasonable starting point for:

  • Example code.
  • Conceptualizing Carbon at a high level.
  • Reasonable, but not necessarily final, approaches to features in README.md.
    • If any idea is obviously bad, we can clean it up here.

This proposal is not intended to achieve:

  • A whole language design.
    • This is way too much work for a single proposal; this is a skeletal framework only.
    • As we work on feature-specific designs, we may decide to use other approaches. That's fine: we only need somewhere to start.
    • The summaries in README.md may be expected to change over time.
  • Feature-specific files aren't intended to be well-written or comprehensive. They are a quick jot of prior thoughts.
    • We want to avoid getting stuck on language details that we should consider
      more carefully regardless. If you're passionate about a feature, please feel
      free to start a new proposal for it.
    • Each and every aspect of the suggested overview should be subject to careful
      examination and justification before it becomes a settled plan of record.

Chandler started this with #22. I've taken it over with the following changes:

  • More of a directory hierarchy.
  • Trying to thin out the main file (now README.md) to lighter summaries of features.
  • Details/rationale/alternatives should be in feature-specific files.
    • Draft files are linked as references where added.

For an example of how we may proceed with feature-specific designs, see #80. In this structure:

  • docs/design/README.md mentions interoperability, with a light overview.
  • docs/design/interoperability/README.md goes into more depth on interoperability, covering key points of the approach.
  • Individual files in docs/design/interoperability/* go into more depth on interoperability.

Simple designs may not have a subdirectory. All current feature-specific designs do not -- they may be moved later.

jonmeow and others added 15 commits May 20, 2020 08:36
Move firebase support into a src directory. (#15)
This is basically a snapshot of an in-progress document, moved to
markdown and prepared for sharing with the wider community. It isn't
finished. It isn't even necessarily up to date with the latest thinking
on any particular area. But I think it will make more sense to land it
as essentially a collective WIP and let people iterate on any given
section as those details get sorted out.

Even in its current form, I think it still provides a starting point and
gives people the feel of what this will look like.

There are a number of document links lost in this conversion. I've
carefully left a `TODO` in the document at each point to come back and
add the appropriate link back to the document once the rest of the
existing material is somewhere visible. These were all fairly easy to
preserve as they primarily were links out to an entire document.
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
@jonmeow jonmeow added proposal A proposal WIP labels Jun 17, 2020
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@jonmeow jonmeow marked this pull request as draft June 17, 2020 20:15
docs/design/aliasing.md Outdated Show resolved Hide resolved
proposals/p0083.md Outdated Show resolved Hide resolved
Copy link
Contributor Author

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

Mostly addressing comments from @josh11b, with one from @zygoloid

supported.
- Line comments look like `// ...`. However, they are required to be the only
non-whitespace on the line for readability.
- Block comments begin with `//\{`, and end with `//\}`. The begin and end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to guess at what you mean, rephrased the next sentence.


Carbon provides metaprogramming facilities that look similar to regular Carbon
code. These are structured, and do not offer inclusion or arbitrary
preprocessing of source text such as C/C++ does.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's a related proposal. Note though, I'm generally not taking time to link to related proposals -- I think the right thing to do is to maybe mention them if needed elsewhere, but not in the actual design. Rather, it should be accepted that the design will evolve over time, and that the specific proposal to do that may change (e.g., due to evolving ideas, or changes in ownership like how I took this proposal from Chandler).

Comment on lines 173 to 174
- `UpperCamelCase` for names of compile-time resolved constants, such that they
can participate in the type system and type checking of the program.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

Comment on lines 251 to 253
Common types that we expect to be used universally will be provided for every
file, including `Int` and `Bool`. These will likely be defined in a `Carbon`
package, and be treated as if always imported and aliased by every file.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed Carbon name.

- Bitwise: `2 & 3`, `2 | 4`, `3 ^ 1`, `~7`
- Bit sequence: `1 << 3`, `8 >> 1`
- Comparison: `2 == 2`, `3 != 4`, `5 < 6`, `7 > 6`, `8 <= 8`, `8 >= 8`
- Logical: `a && b`, `c || d`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking with @zygoloid for a second opinion; I'd actually thought the leaning was the stated way. Of course, this is a fairly minor point and can always be swapped later if proposals change.

Comment on lines 83 to 88
### Indices as compile-time constants

In the example `t1[2, 1, 0]`, we will likely want to restrict these indices to
compile-time constants. Without that, run-time indexing would need to suddenly
switch to a variant-style return type to handle heterogeneous tuples. This would
both be surprising and complex for little or no value.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved

Comment on lines 90 to 97
### Multiple indices

In the example `t1[2, 1, 0]`, using multiple indices in this way is a bit
questionable. If we end up wanting to support multidimensional arrays / slices
(a likely selling point for the scientific world), a sequence of indices seems a
likely desired facility there. We'd either need to find a different syntax
there, change this syntax, or cope with tuples and arrays having different
semantics for multiple indices (which seems really bad).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just removing this (if the final design wants to talk about this more, that's fine)

docs/design/tuples.md Show resolved Hide resolved
Comment on lines 1 to 25
# TODO

<!--
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-->

## Table of contents

<!-- toc -->

- [TODO](#todo)
- [Overview](#overview)

<!-- tocstop -->

## TODO

This is a skeletal design, added to support [the overview](README.md). It should
not be treated as accepted by the core team; rather, it is a placeholder until
we have more time to examine this detail. Please feel welcome to rewrite and
update as appropriate.

## Overview
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mistake, removed

Comment on lines 48 to 56
### Declaring constants

An open question is what syntax (and mechanism) to use for declaring constants.
There are serious problems with the use of `const` in C++ as part of the type
system, so alternatives to pseudo-types (type qualifiers) are being explored.
The obvious syntax is `let` from Swift, although there are some questions around
how intuitive it is for this to introduce a constant. Another candidate is `val`
from Kotlin. Another thing we need to contend with is the surprise of const and
reference (semantic) types.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, adjusted the argument for alternatives.

- All source code is UTF-8 encoded text. For simplicity, no other encoding is
supported.
- Line comments look like `// ...`. However, they are required to be the only
non-whitespace on the line for readability.
Copy link
Contributor

Choose a reason for hiding this comment

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

It makes me sad to not have the ability to write:

var Int: x = foo; // This is a variable declaration

I'm not sure I understand the rationale here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@chandlerc I think this is from you. I personally agree with Bryce here.

Copy link
Contributor Author

@jonmeow jonmeow Jul 20, 2020

Choose a reason for hiding this comment

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

I believe this reflects the current proposal of #17. Rather than injecting a personal opinion on this issue, I think that:

  1. This can be resolved on the syntax-specific proposal, given there are differing opinions about the issue.
  2. If we start allowing examples to use <code> // <comment>, that's more expensive to fix later if the decision is to not allow that syntax than if we assume it will not be allowed and change our minds later.

Copy link
Contributor

Choose a reason for hiding this comment

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

I commented there: #17 (comment)

Choose a reason for hiding this comment

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

If I could remove all end-of-line comments from my codbase, I'd be real happy. Because under maintenance, lines often get longer. Some codebases have max-column limits. And when you have to automatically re-wrap as a result, there aren't good options.

@sidney13 sidney13 added needs decision and removed proposal rfc Proposal with request-for-comment sent out labels Jul 16, 2020
Comment on lines 116 to 117
- Block comments begin with `//\{`, and end with `//\}`. The begin and end
markers must be the only things on their lines.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Block comments begin with `//\{`, and end with `//\}`. The begin and end
markers must be the only things on their lines.
- Block comments begin with a line starting with `//\{`, and end with a line starting with `//\}`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern is this is difficult to read. Rewrote this a little, and gave an example.

- All source code is UTF-8 encoded text. For simplicity, no other encoding is
supported.
- Line comments look like `// ...`. However, they are required to be the only
non-whitespace on the line for readability.
Copy link
Contributor

Choose a reason for hiding this comment

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

@chandlerc I think this is from you. I personally agree with Bryce here.

Comment on lines 116 to 117
- Block comments begin with `//\{`, and end with `//\}`. They are always at the
start of a line.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Block comments begin with `//\{`, and end with `//\}`. They are always at the
start of a line.
- Block comments begin with a line starting with `//\{`, and end with a line starting with `//\}`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"begin with a line starting with" phrasing is a little confusing to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

As I understand @zygoloid 's lexing proposal, there may be additional characters on the line that starts with //\{ or //\}, as in:

//\{ disabled
  This is disabled
//\} disabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten with example


Carbon provides metaprogramming facilities that look similar to regular Carbon
code. These are structured, and do not offer inclusion or arbitrary
preprocessing of source text such as C/C++ does.
Copy link
Contributor

Choose a reason for hiding this comment

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

In 4 other cases you linked to the PR, I'm not sure what is different here.

docs/design/name_lookup.md Show resolved Hide resolved
modifying other types. They also have semantics that are defined from first
principles rather than in terms of other operations. Even though these are
special, their names are not keywords or reserved; they are just names in the
global scope.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is an example of using the phrase "global scope". I think this is consistent with how that term is used in other in-progress design docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote as prelude

- `Baz()` is invoked if `x` is greater than `77`.
- Nothing happens if `x` is between `42` and `77`.

#### `loop`, `break`, and `continue`
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 should replace loop with while in this section. There is no reason to be different from what people expect here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

docs/design/README.md Outdated Show resolved Hide resolved
docs/design/README.md Outdated Show resolved Hide resolved
docs/design/README.md Outdated Show resolved Hide resolved

Common types that we expect to be used universally will be provided for every
file, including `Int` and `Bool`. These will likely be defined in a special
"prelude" package which is treated as if always imported and aliased by every
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what "imported and aliased" means. I think this might be another place where it would be clearer to explain that the prelude (and only the prelude) populates the global namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Comment on lines 37 to 38
- `UpperCamelCase` for names of compile-time resolved constants, such that they
can participate in the type system and type checking of the program.
Copy link
Contributor

Choose a reason for hiding this comment

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

See revised correction.

modifying other types. They also have semantics that are defined from first
principles rather than in terms of other operations. Even though these are
special, their names are not keywords or reserved; they are just names in the
implicit "prelude" that is imported and aliased into all files.
Copy link
Contributor

Choose a reason for hiding this comment

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

Again I don't think "imported and aliased" is clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy-pasted new text from readme

- All source code is UTF-8 encoded text. For simplicity, no other encoding is
supported.
- Line comments look like `// ...`. However, they are required to be the only
non-whitespace on the line for readability.
Copy link
Contributor

Choose a reason for hiding this comment

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

I commented there: #17 (comment)

@jonmeow
Copy link
Contributor Author

jonmeow commented Jul 27, 2020

@josh11b I started accepting changes, and then I realized I shouldn't because the decision is already underway. I can't make any more edits without an explicit decision from the core team. I agree the wording could be improved, but in the future, could you please consider filing an issue, plan out a follow-up PR for changes, or state explicit edits as a condition for your approval? This came up before with the goals PR, where I filed #106, but it's difficult to respond appropriately.

Copy link
Contributor Author

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

Comment pass; may need to take a closer look for unresponded comments

Comment on lines 116 to 117
- Block comments begin with `//\{`, and end with `//\}`. The begin and end
markers must be the only things on their lines.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern is this is difficult to read. Rewrote this a little, and gave an example.

Comment on lines 173 to 174
- `UpperCamelCase` for names of compile-time resolved constants, such that they
can participate in the type system and type checking of the program.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for suggesting a fix! I hadn't understood your criticism, so the positive example really helps.

- `Baz()` is invoked if `x` is greater than `77`.
- Nothing happens if `x` is between `42` and `77`.

#### `loop`, `break`, and `continue`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

modifying other types. They also have semantics that are defined from first
principles rather than in terms of other operations. Even though these are
special, their names are not keywords or reserved; they are just names in the
global scope.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote as prelude

> **TODO:** References need to be evolved.

User-defined types may have template parameters. The resulting type-function may
be used to instantiate the parameterized definition with the provided arguments
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we'll need to switch terminology if we substantively change the meaning of "instantiate" -- it's too well known a term. As-is, I think either the templates proposal or the proposed glossary would be better places to define terminology.

>
> **TODO:** References need to be evolved.

Both implicit and explicit function parameters in Carbon can be marked as
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was looking at rewriting this, but nothing was popping out for me. For now, I'd rather rely on existing knowledge of implicit/explicit.

docs/design/name_lookup.md Show resolved Hide resolved
Comment on lines 37 to 38
- `UpperCamelCase` for names of compile-time resolved constants, such that they
can participate in the type system and type checking of the program.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepted, thanks.

modifying other types. They also have semantics that are defined from first
principles rather than in terms of other operations. Even though these are
special, their names are not keywords or reserved; they are just names in the
implicit "prelude" that is imported and aliased into all files.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy-pasted new text from readme

Comment on lines 116 to 117
- Block comments begin with `//\{`, and end with `//\}`. They are always at the
start of a line.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten with example

@sidney13 sidney13 added proposal accepted Decision made, proposal accepted and removed needs decision labels Jul 30, 2020
@sidney13 sidney13 self-requested a review July 30, 2020 02:53
@jonmeow jonmeow merged commit cec8a85 into carbon-language:trunk Jul 30, 2020
@jonmeow jonmeow deleted the proposal-design-overview branch July 30, 2020 18:37
jonmeow added a commit that referenced this pull request Jul 31, 2020
The main comment on a review wasn't being handled, and this change interleaves it with the PR comments. GitHub treats these as different entities.

I'm hiding reviews with no top-level comment; these didn't seem worth including empty comments.

Links are being added to PR comments to make them easier to find. This means indenting the content, so now all comments (PR or review thread) are consistently indented, removing a parameter. Also, I'm adjusting the formatting of review threads to match.

snippets for comparison:
```
#83 (comment)
  googlebot: All (the pull request submitter and all commit authors) CLAs are...

#83 (review)
  chandlerc: Overall, I think this is a pretty significant improved direction...
```

and from a review thread:
```
https://github.com/carbon-language/carbon-lang/pull/83/files/9863da8#diff-8f28081abb21e65fba5a0b0b29404c78R16
  - line 16; unresolved
  - diff: https://github.com/carbon-language/carbon-lang/pull/83/files/9863da8..HEAD#diff-8f28081abb21e65fba5a0b0b29404c78L16
  josh11b: ```suggestion¶ - Block comments begin with a line starting with `/...
  jonmeow: "begin with a line starting with" phrasing is a little confusing t...
  josh11b: As I understand @zygoloid 's lexing proposal, there may be additio...
  jonmeow: Rewritten with example
```
jonmeow added a commit that referenced this pull request Aug 20, 2020
- [RFC topic](https://forums.carbon-lang.dev/t/rfc-add-idiomatic-code-performance-and-developer-facing-docs-to-goals/105)
- [Decision](https://forums.carbon-lang.dev/t/request-for-decision-add-idiomatic-code-performance-and-developer-facing-docs-to-goals/116)

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>

Most of this is addressing issue #106.

Two new explicit sub-goals:

- Idiomatic code should be performant, stemming from #106.
- User-facing documentation, separate thought from #83 discussion.

I think both of these are on people's minds and assumed, but still worth spelling out.
chandlerc pushed a commit that referenced this pull request Jun 28, 2022
- [RFC topic](https://forums.carbon-lang.dev/t/rfc-add-idiomatic-code-performance-and-developer-facing-docs-to-goals/105)
- [Decision](https://forums.carbon-lang.dev/t/request-for-decision-add-idiomatic-code-performance-and-developer-facing-docs-to-goals/116)

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>

Most of this is addressing issue #106.

Two new explicit sub-goals:

- Idiomatic code should be performant, stemming from #106.
- User-facing documentation, separate thought from #83 discussion.

I think both of these are on people's minds and assumed, but still worth spelling out.
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.

10 participants