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

Code and name organization #107

Merged
merged 101 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 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
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
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
218df9f
Merge remote-tracking branch 'upstream/master'
jonmeow Jun 22, 2020
5c33fbf
Merge remote-tracking branch 'upstream/master'
jonmeow Jun 22, 2020
160b5c4
Merge remote-tracking branch 'upstream/master'
jonmeow Jun 2, 2020
5829ac9
Merge remote-tracking branch 'upstream/trunk' into trunk
jonmeow Jul 6, 2020
8692c9a
Creating new proposal: Code and name organization
jonmeow Jul 8, 2020
6b7f469
Filling out template with PR 107
jonmeow Jul 8, 2020
654cad6
First draft for external
jonmeow Jul 8, 2020
aa96aaf
Merge
jonmeow Jul 31, 2020
ca5d5bd
Shift focus from files/libraries/packages to the code organization
jonmeow Aug 4, 2020
c132018
Rewriting
jonmeow Aug 5, 2020
3d99524
Drafting
jonmeow Aug 7, 2020
5813814
Progress
jonmeow Aug 11, 2020
3154969
Updates
jonmeow Aug 12, 2020
a546035
Updates
jonmeow Aug 12, 2020
1222334
Updates
jonmeow Aug 12, 2020
3cebea3
Updates
jonmeow Aug 12, 2020
4bbba84
Updates
jonmeow Aug 12, 2020
d7d2850
Extend justification
jonmeow Aug 12, 2020
7c4c32c
Updates
jonmeow Aug 12, 2020
d5b8ab9
Refactoring
jonmeow Aug 12, 2020
3e15730
Updates
jonmeow Aug 12, 2020
e578b1f
Updates
jonmeow Aug 12, 2020
5319498
Updates
jonmeow Aug 12, 2020
06dea5d
Apply suggestions from code review
jonmeow Aug 13, 2020
bf74c75
Updates
jonmeow Aug 13, 2020
9559bec
Merge branch 'proposal-code-and-name-organi' of https://github.com/jo…
jonmeow Aug 13, 2020
af6f4b1
Updates
jonmeow Aug 13, 2020
2311f03
Updates
jonmeow Aug 14, 2020
db2d550
Examples
jonmeow Aug 14, 2020
1ebecc1
A couple more examples
jonmeow Aug 14, 2020
54f740b
Updates
jonmeow Aug 14, 2020
cf53d74
Updates
jonmeow Aug 14, 2020
0d81ff4
Apply suggestions from code review
jonmeow Aug 15, 2020
03f92f8
Updates
jonmeow Aug 15, 2020
a5c4e16
Merge branch 'proposal-code-and-name-organi' of https://github.com/jo…
jonmeow Aug 15, 2020
8d62937
Prettier
jonmeow Aug 15, 2020
1d09728
Updates
jonmeow Aug 17, 2020
9fed213
Updates
jonmeow Aug 17, 2020
b53a98d
Updates
jonmeow Aug 17, 2020
50cb15b
Updates
jonmeow Aug 17, 2020
1e55c4f
Updates
jonmeow Aug 17, 2020
365a089
Updates
jonmeow Aug 17, 2020
0c6c6de
Updates
jonmeow Aug 17, 2020
8297dbe
Updates
jonmeow Aug 17, 2020
eae6a9b
Updates
jonmeow Aug 17, 2020
2111545
Apply suggestions from code review
jonmeow Aug 18, 2020
23bee19
Merge branch 'trunk' into proposal-code-and-name-organi
jonmeow Aug 18, 2020
94bd816
Updates
jonmeow Aug 18, 2020
69d1893
Updates
jonmeow Aug 19, 2020
4f10ddb
Updates
jonmeow Aug 19, 2020
e56549e
Updates
jonmeow Aug 19, 2020
1cec071
TODOS
jonmeow Aug 20, 2020
99801c1
Apply suggestions from code review
jonmeow Aug 20, 2020
91f989e
Updates
jonmeow Aug 21, 2020
559677b
Merge
jonmeow Aug 24, 2020
7c464a5
Updates
jonmeow Aug 27, 2020
e1c46e3
Updates
jonmeow Aug 27, 2020
60dfa21
Updates
jonmeow Aug 27, 2020
c8ea9bb
Updates
jonmeow Aug 27, 2020
578591b
Updates
jonmeow Aug 27, 2020
84cd55f
Updates
jonmeow Aug 31, 2020
882d5e0
Updates
jonmeow Aug 31, 2020
7a0a400
Updates
jonmeow Aug 31, 2020
f914c1b
Merge branch 'trunk' into proposal-code-and-name-organi
jonmeow Sep 1, 2020
d0ba98a
Address geoffromer comment
jonmeow Sep 3, 2020
b8f9fc2
Updates
jonmeow Sep 3, 2020
53a1072
Apply suggestions from code review
jonmeow Sep 8, 2020
0da274b
Updates
jonmeow Sep 8, 2020
16ba315
Merge branch 'trunk' into proposal-code-and-name-organi
jonmeow Sep 9, 2020
687c166
progress
jonmeow Sep 9, 2020
31a7619
Remove foo uses
jonmeow Sep 9, 2020
6efd78e
Merge branch 'trunk' into proposal-code-and-name-organi
jonmeow Sep 9, 2020
4d15065
Link
jonmeow Sep 10, 2020
441fe24
Updates
jonmeow Sep 11, 2020
6d9f997
Updates
jonmeow Sep 11, 2020
d9a7b34
Updates
jonmeow Sep 14, 2020
71375af
Apply suggestions from code review
jonmeow Sep 15, 2020
6c4d9e3
Merge branch 'trunk' into proposal-code-and-name-organi
jonmeow Sep 15, 2020
9607815
Update code_and_name_organization.md
jonmeow Sep 15, 2020
06b31f5
Updates
jonmeow Sep 16, 2020
8a5b20b
Software as wording
jonmeow Sep 16, 2020
79270d3
Updates
jonmeow Sep 17, 2020
754cb6b
Updates
jonmeow Sep 17, 2020
0388e5b
Updates
jonmeow Sep 17, 2020
3c52bb7
Updates
jonmeow Sep 18, 2020
2a1a662
Updates
jonmeow Sep 21, 2020
e9f4404
New open question from discussion with josh11b
jonmeow Sep 29, 2020
3ef6558
Update docs/design/code_and_name_organization.md
jonmeow Oct 6, 2020
f71c05d
Updates
jonmeow Oct 6, 2020
cd6e7b4
Merge branch 'proposal-code-and-name-organi' of https://github.com/jo…
jonmeow Oct 6, 2020
fe4c7d2
Minor adjustment
jonmeow Oct 6, 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
74 changes: 24 additions & 50 deletions docs/design/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- [Example code](#example-code)
- [Basic syntax](#basic-syntax)
- [Code and comments](#code-and-comments)
- [Files, libraries, and packages](#files-libraries-and-packages)
- [Packages, libraries, and namespaces](#packages-libraries-and-namespaces)
- [Names and scopes](#names-and-scopes)
- [Naming conventions](#naming-conventions)
- [Aliases](#aliases)
Expand Down Expand Up @@ -127,36 +127,36 @@ cleaned up during evolution.
live code
```

### Files, libraries, and packages
### Packages, libraries, and namespaces

> References: [Files, libraries and packages](files_libraries_and_packages.md)
>
> **TODO:** References need to be evolved.
> References: [Code and name organization](code_and_name_organization.md)

Carbon code is organized into files, libraries, and packages:
- **Files** are grouped into libraries, which are in turn grouped into
packages.
- **Libraries** are the granularity of code reuse through imports.
- **Packages** are the unit of distribution.

- A **file** is the unit of compilation.
- A **library** can be made up of multiple files, and is the unit whose public
interface can be imported.
- A **package** is a collection of one or more libraries, typically ones with
a single common source and with some close association.
Comment on lines -138 to -142
Copy link
Contributor

Choose a reason for hiding this comment

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

I liked this list because it gave succinct definitions of the concepts at the beginning of the section. Was it incorrect? If so, can we correct or improve it, instead of deleting?

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've rephrased the paragraph on line 134 as bullets.

Note here, this may end up going back again: it changed to a paragraph based on other feedback on writing styles. I'm not heavily opinionated, but I won't provide the same information both ways.

Name paths in Carbon always start with the package name. Additional namespaces
may be specified as desired.

A file belongs to precisely one library, and a library belongs to precisely one
package.
For example, this code declares a struct `Geometry.Shapes.Flat.Circle` in a
library `Geometry/OneSide`:

Files have a `.6c` extension. They must start with a declaration of their
package and library. They may import both other libraries from within their
package, as well as libraries from other packages. For example:
```carbon
package Geometry library("OneSide") namespace Shapes;

namespace Flat;
Copy link
Contributor

Choose a reason for hiding this comment

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

A semicolon-terminated namespace declaration is not very clear about how it combines with other namespace declarations. Specifically, does it override the namespace Shapes above, or does it create a nested namespace within Shapes?

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 line 140 covers this: Geometry.Shapes.Flat.Circle, meaning a nested namespace. Keep in mind that this is the overview, so won't go into deep detail.

struct Flat.Circle { ... }
```

This type can be used from another package:

```carbon
// This is a file in the "Eucalyptus" library of the "Koala" package.
package Koala library Eucalyptus;
package ExampleUser;

// Import the "Wombat" library from the "Widget" package.
import Widget library Wombat;
import Geometry library("OneSide");

// Import the "Container" library from the "Koala" package.
import library Container;
fn Foo(var Geometry.Shapes.Flat.Circle: circle) { ... }
```

### Names and scopes
Expand Down Expand Up @@ -222,37 +222,11 @@ textually after this can refer to `MyInt`, and it will transparently refer to

#### Name lookup

> References: [Name lookup](name_lookup.md)
> References: [name lookup](name_lookup.md)
>
> **TODO:** References need to be evolved.

Names are always introduced into some scope which defines where they can be
referenced. Many of these scopes are themselves named. `namespace` is used to
introduce a dedicated named scope, and we traverse nested names in a uniform way
with `.`-separated names. Unqualified name lookup will always find a file-local
result, including aliases.

For example:

```carbon
package Koala library Eucalyptus;

namespace Leaf {
namespace Vein {
fn Count() -> Int;
}
}
```

`Count` may be referred to as:

- `Count` from within the `Vein` namespace.
- `Vein.Count` from within the `Leaf` namespace.
- `Leaf.Vein.Count` from within this file.
- `Koala.Leaf.Vein.Count` from any arbitrary location.

Note that libraries do **not** introduce a scope; they share the scope of their
package.
Unqualified name lookup will always find a file-local result, including aliases.

##### Name lookup for common types

Expand Down
Loading