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
Show file tree
Hide file tree
Changes from 60 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 May 20, 2020
5bba3a8
Merge remote-tracking branch 'upstream/master'
jonmeow May 20, 2020
98562a6
Merge remote-tracking branch 'upstream/master'
jonmeow May 21, 2020
7cd79ae
An incomplete, early, and in-progress overview of the language design.
chandlerc May 21, 2020
a05e9c3
Merge pull request #2 from carbon-language/master
jonmeow Jun 1, 2020
dfe42cb
Merge pull request #3 from carbon-language/master
jonmeow Jun 3, 2020
3931951
Merge pull request #4 from carbon-language/master
jonmeow Jun 4, 2020
fbbc0a8
Merge branch 'master' into lang-design-overview
chandlerc Jun 10, 2020
f2d0fcf
Extensive updates based on review feedback.
chandlerc Jun 10, 2020
6be32d3
Apply suggestions from code review
chandlerc Jun 10, 2020
3c13624
More tweaks
chandlerc Jun 10, 2020
43cfde9
Merge pull request #5 from carbon-language/master
jonmeow Jun 10, 2020
b489c23
Merge pull request #6 from carbon-language/master
jonmeow Jun 12, 2020
5b10b4d
Merge pull request #7 from carbon-language/master
jonmeow Jun 12, 2020
6ce0f97
Merge remote-tracking branch 'upstream/master'
jonmeow Jun 16, 2020
0132532
Proposal adjustments
jonmeow Jun 17, 2020
5209564
Merge branch 'master' into proposal-design-overview
jonmeow Jun 17, 2020
e72cf68
toc
jonmeow Jun 17, 2020
2ec94a9
Evolving structure
jonmeow Jun 17, 2020
2d69118
Delete the old doc
jonmeow Jun 17, 2020
e220190
Trying different format
jonmeow Jun 17, 2020
68b4e9b
Progress
jonmeow Jun 17, 2020
4b0a788
Progress
jonmeow Jun 17, 2020
4f83e44
Progress
jonmeow Jun 17, 2020
45cfaab
Progress
jonmeow Jun 17, 2020
39f0147
Progress
jonmeow Jun 17, 2020
34bb96d
Progress
jonmeow Jun 18, 2020
5d39a54
Progress
jonmeow Jun 18, 2020
3361b92
Progress
jonmeow Jun 18, 2020
0264743
Progress
jonmeow Jun 18, 2020
ea0f8e5
Progress
jonmeow Jun 19, 2020
25437de
Progress
jonmeow Jun 19, 2020
218df9f
Merge remote-tracking branch 'upstream/master'
jonmeow Jun 22, 2020
473055a
Update docs/design/name_lookup.md
jonmeow Jun 22, 2020
9058c25
Update docs/design/functions.md
jonmeow Jun 22, 2020
b464996
Update docs/design/functions.md
jonmeow Jun 22, 2020
1bb22b3
Update docs/design/structs.md
jonmeow Jun 22, 2020
5463882
Update docs/design/structs.md
jonmeow Jun 22, 2020
06a4f07
Update docs/design/structs.md
jonmeow Jun 22, 2020
13ec30b
No overview alternative
jonmeow Jun 22, 2020
f082a0d
Merge branch 'proposal-design-overview' of https://github.com/jonmeow…
jonmeow Jun 22, 2020
66fe610
No overview alternative
jonmeow Jun 22, 2020
96033db
<->
jonmeow Jun 22, 2020
6e9feb7
Remove ??? for alias
jonmeow Jun 22, 2020
c4c7c92
Update docs/design/README.md
jonmeow Jun 22, 2020
212f5ea
Apply suggestions from code review
jonmeow Jun 22, 2020
3655b59
Let loops be conditional
jonmeow Jun 22, 2020
56874f5
Fix
jonmeow Jun 22, 2020
a646508
Merge branch 'proposal-design-overview' of https://github.com/jonmeow…
jonmeow Jun 22, 2020
3420293
Applying suggestions
jonmeow Jun 22, 2020
18bc50f
codespell
jonmeow Jun 22, 2020
5c33fbf
Merge remote-tracking branch 'upstream/master'
jonmeow Jun 22, 2020
f64aa7b
Merge branch 'master' into proposal-design-overview
jonmeow Jun 22, 2020
97da855
Syntactic conventions
jonmeow Jun 22, 2020
33425d9
Addressing comments
jonmeow Jun 23, 2020
9ce1bfc
Add examples
jonmeow Jun 2, 2020
4412a88
Add examples
jonmeow Jun 2, 2020
555fe93
Update docs/design/templates.md
jonmeow Jul 1, 2020
848b37c
Merge branch 'proposal-design-overview' of https://github.com/jonmeow…
jonmeow Jul 1, 2020
fc5c103
Precommits
jonmeow Jun 2, 2020
0b113ce
Add tuple ambiguity question
jonmeow Jul 9, 2020
e95da90
Apply suggestions from code review
jonmeow Jul 10, 2020
9863da8
Addressing comments
jonmeow Jul 10, 2020
4809730
Link PR 89
jonmeow Jul 20, 2020
504c971
Merge branch 'trunk' into proposal-design-overview
jonmeow Jul 27, 2020
ddfc5f7
Update formatting
jonmeow Jul 27, 2020
7610342
Addressing comments
jonmeow Jul 28, 2020
6c25f8a
carbon marker
jonmeow Jul 28, 2020
1d9a660
Merge branch 'trunk' into proposal-design-overview
jonmeow Jul 30, 2020
d4550e3
Rename interop per #114
jonmeow Jul 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
883 changes: 883 additions & 0 deletions docs/design/README.md

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions docs/design/aliases.md
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.
51 changes: 51 additions & 0 deletions docs/design/blocks_and_statements.md
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();
}
}
```
80 changes: 80 additions & 0 deletions docs/design/control_flow.md
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.
43 changes: 43 additions & 0 deletions docs/design/files_libraries_and_packages.md
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.
63 changes: 63 additions & 0 deletions docs/design/functions.md
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.
28 changes: 28 additions & 0 deletions docs/design/interoperability/template.md
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).
25 changes: 25 additions & 0 deletions docs/design/lexical_conventions.md
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.
29 changes: 29 additions & 0 deletions docs/design/metaprogramming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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.

## 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

#89 ?

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

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.

Copy link
Contributor Author

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.

Loading