-
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
An incomplete, early, and in-progress overview of the language design. #83
Merged
jonmeow
merged 70 commits into
carbon-language:trunk
from
jonmeow:proposal-design-overview
Jul 30, 2020
Merged
Changes from 64 commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
2ae6b6f
Merge pull request #1 from carbon-language/master
jonmeow 5bba3a8
Merge remote-tracking branch 'upstream/master'
jonmeow 98562a6
Merge remote-tracking branch 'upstream/master'
jonmeow 7cd79ae
An incomplete, early, and in-progress overview of the language design.
chandlerc a05e9c3
Merge pull request #2 from carbon-language/master
jonmeow dfe42cb
Merge pull request #3 from carbon-language/master
jonmeow 3931951
Merge pull request #4 from carbon-language/master
jonmeow fbbc0a8
Merge branch 'master' into lang-design-overview
chandlerc f2d0fcf
Extensive updates based on review feedback.
chandlerc 6be32d3
Apply suggestions from code review
chandlerc 3c13624
More tweaks
chandlerc 43cfde9
Merge pull request #5 from carbon-language/master
jonmeow b489c23
Merge pull request #6 from carbon-language/master
jonmeow 5b10b4d
Merge pull request #7 from carbon-language/master
jonmeow 6ce0f97
Merge remote-tracking branch 'upstream/master'
jonmeow 0132532
Proposal adjustments
jonmeow 5209564
Merge branch 'master' into proposal-design-overview
jonmeow e72cf68
toc
jonmeow 2ec94a9
Evolving structure
jonmeow 2d69118
Delete the old doc
jonmeow e220190
Trying different format
jonmeow 68b4e9b
Progress
jonmeow 4b0a788
Progress
jonmeow 4f83e44
Progress
jonmeow 45cfaab
Progress
jonmeow 39f0147
Progress
jonmeow 34bb96d
Progress
jonmeow 5d39a54
Progress
jonmeow 3361b92
Progress
jonmeow 0264743
Progress
jonmeow ea0f8e5
Progress
jonmeow 25437de
Progress
jonmeow 218df9f
Merge remote-tracking branch 'upstream/master'
jonmeow 473055a
Update docs/design/name_lookup.md
jonmeow 9058c25
Update docs/design/functions.md
jonmeow b464996
Update docs/design/functions.md
jonmeow 1bb22b3
Update docs/design/structs.md
jonmeow 5463882
Update docs/design/structs.md
jonmeow 06a4f07
Update docs/design/structs.md
jonmeow 13ec30b
No overview alternative
jonmeow f082a0d
Merge branch 'proposal-design-overview' of https://github.com/jonmeow…
jonmeow 66fe610
No overview alternative
jonmeow 96033db
<->
jonmeow 6e9feb7
Remove ??? for alias
jonmeow c4c7c92
Update docs/design/README.md
jonmeow 212f5ea
Apply suggestions from code review
jonmeow 3655b59
Let loops be conditional
jonmeow 56874f5
Fix
jonmeow a646508
Merge branch 'proposal-design-overview' of https://github.com/jonmeow…
jonmeow 3420293
Applying suggestions
jonmeow 18bc50f
codespell
jonmeow 5c33fbf
Merge remote-tracking branch 'upstream/master'
jonmeow f64aa7b
Merge branch 'master' into proposal-design-overview
jonmeow 97da855
Syntactic conventions
jonmeow 33425d9
Addressing comments
jonmeow 9ce1bfc
Add examples
jonmeow 4412a88
Add examples
jonmeow 555fe93
Update docs/design/templates.md
jonmeow 848b37c
Merge branch 'proposal-design-overview' of https://github.com/jonmeow…
jonmeow fc5c103
Precommits
jonmeow 0b113ce
Add tuple ambiguity question
jonmeow e95da90
Apply suggestions from code review
jonmeow 9863da8
Addressing comments
jonmeow 4809730
Link PR 89
jonmeow 504c971
Merge branch 'trunk' into proposal-design-overview
jonmeow ddfc5f7
Update formatting
jonmeow 7610342
Addressing comments
jonmeow 6c25f8a
carbon marker
jonmeow 1d9a660
Merge branch 'trunk' into proposal-design-overview
jonmeow d4550e3
Rename interop per #114
jonmeow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Aliases | ||
|
||
<!-- | ||
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) | ||
- [Alternatives](#alternatives) | ||
|
||
<!-- 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 | ||
|
||
Naming is one of the things that most often requires careful management over | ||
time -- things tend to get renamed and moved around. | ||
|
||
Carbon provides a fully general name aliasing facility to declare a new name as | ||
an alias for a value; everything is a value in Carbon. This is a fully general | ||
facility because everything is a value in Carbon, including types. | ||
|
||
For example: | ||
|
||
``` | ||
alias MyInt = Int; | ||
``` | ||
|
||
This creates an alias called `MyInt` for whatever `Int` resolves to. Code | ||
textually after this can refer to `MyInt`, and it will transparently refer to | ||
`Int`. | ||
|
||
### Alternatives | ||
|
||
The syntax here is not at all in a good state yet. We've considered a few | ||
alternatives, but they all end up being confusing in some way. We need to figure | ||
out a good and clean syntax that can be used here. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Blocks and statements | ||
|
||
<!-- | ||
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 | ||
|
||
The body or definition of a function is provided by a block of code containing | ||
statements, much like in C or C++. The body of a function is also a new, nested | ||
scope inside the function's scope (meaning that parameter names are available). | ||
Statements within a block are terminated by a semicolon. Each statement can, | ||
among other things, be an expression. Here is a trivial example of a function | ||
definition using a block of statements: | ||
|
||
``` | ||
fn Foo() { | ||
Bar(); | ||
Baz(); | ||
} | ||
``` | ||
|
||
Statements can also themselves be a block of statements, which provide scopes | ||
and nesting: | ||
|
||
``` | ||
fn Foo() { | ||
Bar(); | ||
{ | ||
Baz(); | ||
} | ||
} | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Control flow | ||
|
||
<!-- | ||
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) | ||
- [Open questions](#open-questions) | ||
- [`if` blocks](#if-blocks) | ||
- [`break` and `continue`](#break-and-continue) | ||
|
||
<!-- 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. | ||
|
||
At least summarize `if` and `else` to cover basics. Especially important to | ||
surface the idea of using basic conditionals as both expressions and statements | ||
to avoid needing conditional operators. | ||
|
||
Looping is an especially interesting topic to explore as there are lots of | ||
challenges posed by the C++ loop structure. Even C++ itself has been seeing | ||
significant interest and pressure to improve its looping facilities. | ||
|
||
## Overview | ||
|
||
Blocks of statements are generally executed linearly. However, statements are | ||
the primary place where this flow of execution can be controlled. Carbon's | ||
control flow constructs are mostly similar to those in C, C++, and other | ||
languages. | ||
|
||
``` | ||
fn Foo(Int: x) { | ||
if (x < 42) { | ||
Bar(); | ||
} else if (x > 77) { | ||
Baz(); | ||
} | ||
} | ||
``` | ||
|
||
Loops will at least be supported with a low-level primitive `loop` statement, | ||
with `break` and `continue` statements which work the same as in C++. | ||
|
||
Last but not least, for the basics we need to include the `return` statement. | ||
This statement ends the flow of execution within a function, returning it to the | ||
caller. If the function returns a value to the caller, that value is provided by | ||
an expression in the return statement. This allows us to complete the definition | ||
of our `Sum` function from earlier as: | ||
|
||
``` | ||
fn Sum(Int: a, Int: b) -> Int { | ||
return a + b; | ||
} | ||
``` | ||
|
||
## Open questions | ||
|
||
### `if` blocks | ||
|
||
It is an open question whether a block is required or a single statement may be | ||
nested in an `if` statement. Similarly, it is an open question whether `else if` | ||
is a single keyword versus a nested `if` statement, and if it is a single | ||
construct whether it should be spelled `elif` or something else. | ||
|
||
### `break` and `continue` | ||
|
||
If and how to support a "labeled break" or "labeled continue" is still a point | ||
of open discussion. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Files, libraries, and packages | ||
|
||
<!-- | ||
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) | ||
- [Alternatives](#alternatives) | ||
- [File extensions](#file-extensions) | ||
|
||
<!-- 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. | ||
|
||
## Alternatives | ||
|
||
### File extensions | ||
|
||
The use of `6c` as a short file extension or top-level CLI (with subcommands | ||
below it similar to `git` or `go`) has some drawbacks. There are several other | ||
possible extensions / commands: | ||
|
||
- `cb`: This collides with several acronyms and may not be especially memorable | ||
as referring to Carbon. | ||
- `c6`: This seems a weird incorrect ordering of the atomic number and has a bad | ||
(if _extremely_ obscure) Internet slang association (NSFW, use caution if | ||
searching, as with too much Internet slang). | ||
- `carbon`: This is an obvious and unsurprising choice, but also quite long. | ||
|
||
This seems fairly easy for us to change as we go along, but we should at some | ||
point do a formal proposal to gather other options and let the core team try to | ||
find the set that they feel is close enough to be a bikeshed. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Functions | ||
|
||
<!-- | ||
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) | ||
- [Basic functions](#basic-functions) | ||
|
||
<!-- 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. | ||
|
||
## Basic functions | ||
|
||
Programs written in Carbon, much like those written in other languages, are | ||
primarily divided up into "functions" (or "procedures", "subroutines", or | ||
"subprograms"). These are the core unit of behavior for the programming | ||
language. Let's look at a simple example to understand how these work: | ||
|
||
``` | ||
fn Sum(Int: a, Int: b) -> Int; | ||
``` | ||
|
||
This declares a function called `Sum` which accepts two `Int` parameters, the | ||
first called `a` and the second called `b`, and returns an `Int` result. C++ | ||
might declare the same thing: | ||
|
||
``` | ||
std::int64_t Sum(std::int64_t a, std::int64_t b); | ||
|
||
// Or with trailing return type syntax: | ||
auto Sum(std::int64_t a, std::int64_t b) -> std::int64_t; | ||
``` | ||
|
||
Let's look at how some specific parts of this work. The function declaration is | ||
introduced with a keyword `fn` followed by the name of the function `Sum`. This | ||
declares that name in the surrounding scope and opens up a new scope for this | ||
function. We declare the first parameter as `Int: a`. The `Int` part is an | ||
expression (here referring to a constant) that computes the type of the | ||
parameter. The `:` marks the end of the type expression and introduces the | ||
identifier for the parameter, `a`. The parameter names are introduced into the | ||
function's scope and can be referenced immediately after they are introduced. | ||
The return type is indicated with `-> Int`, where again `Int` is just an | ||
expression computing the desired type. The return type can be completely omitted | ||
in the case of functions which do not return a value. | ||
|
||
Calling functions involves a new form of expression: `Sum(1, 2)` for example. | ||
The first part, `Sum`, is an expression referring to the name of the function. | ||
The second part, `(1, 2)` is a parenthesized list of arguments to the function. | ||
The juxtaposition of one expression with parentheses forms the core of a call | ||
expression, similar to a postfix operator. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Carbon ↔ C/C++ interoperability | ||
|
||
<!-- | ||
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 | ||
|
||
See the draft in | ||
[PR 80](https://github.com/carbon-language/carbon-lang/pull/80). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Lexical conventions | ||
|
||
<!-- | ||
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) | ||
|
||
<!-- 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. | ||
|
||
See [PR 17](https://github.com/carbon-language/carbon-lang/pull/17) for context | ||
-- that proposal may replace this. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Metaprogramming | ||
|
||
<!-- | ||
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. | ||
|
||
See | ||
[carbon-proposals PR 89](https://github.com/carbon-language/carbon-proposals/pull/89) | ||
for context -- that proposal may replace this. | ||
|
||
## Overview | ||
|
||
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. | ||
Oops, something went wrong.
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 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.
#89 ?
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.
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).
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.
In 4 other cases you linked to the PR, I'm not sure what is different here.
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.
You're right. Sorry, and linked.