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 4 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
44 changes: 26 additions & 18 deletions docs/design/code_and_name_organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- [Referring to the package as `package`](#referring-to-the-package-as-package)
- [Remove the `library` keyword from `package` and `import`](#remove-the-library-keyword-from-package-and-import)
- [Rename package concept](#rename-package-concept)
- [Strict association between the filesystem path and library/namespace](#strict-association-between-the-filesystem-path-and-librarynamespace)
- [No association between the filesystem path and library/namespace](#no-association-between-the-filesystem-path-and-librarynamespace)
- [Libraries](#libraries-1)
- [Allow exporting namespaces](#allow-exporting-namespaces)
- [Allow importing implementation files from within the same library](#allow-importing-implementation-files-from-within-the-same-library)
Expand Down Expand Up @@ -338,9 +338,15 @@ that are implementation.
`package Geometry library "Shapes" api;`
- API filenames must have the `.carbon` extension. They must not have a
`.impl.carbon` extension.
- API file paths will correspond to the library name.
- The precise form of this correspondence is undetermined, but should
be expected to be similar to a "Math/Algebra" library being in a
"Math/Algebra.carbon" file path.
Comment on lines +341 to +344
Copy link
Contributor

Choose a reason for hiding this comment

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

I had thought we would want to use the exact API file's path? That is, include the .carbon? But maybe not.

(I don't feel strongly about this either way, and don't think this is super important, mostly want us to be intentional in the choice)

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 should omit it -- however, that can always change in another, more targeted proposal. I do admit an assumption that we wouldn't want to repeat file extensions, if possible. This is particularly notable if we expect all impl files to be prefixed with the library name, e.g. "Math/Algebra.impl.carbon", "Math/Algebra.impl.MyDetail.carbon", at which point adding the ".carbon" to the library will end up obfuscating the path.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree it should be omitted, as it is just boilerplate noise. Including it will make it harder to support filesystems that use . as a directory separator.

- The package will not be used when considering the file path.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we mention that the API file path above is relative to some package-specific root? or not at all?

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'd argue for leaving that to be resolved later. I think "package-specific" could imply that each package has its own root, and I believe the discussion so far had been:

  1. A package may have multiple roots, such as one for human-authored files and one for auto-generated files. This could also be multiplied by separating public and package-internal APIs.

  2. A given root could arguably contain multiple packages, as was suggested for the Google use-case.

Thus the idea of making a quick remark about a package-specific root seems pretty limiting, and one that should be delayed for further proposals. I can particularly see how #2 may get arguments.

- An implementation file's `package` will have `impl`. For example,
`package Geometry library "Shapes" impl;`.
- Implementation filenames must have the `.impl.carbon` extension.
- Implementation file paths need not correspond to the library name.
- Implementation files implicitly import the library's API. Implementation
files cannot import each other. There is no facility for file or
non-`api` imports.
Expand Down Expand Up @@ -721,8 +727,8 @@ may require manually adding imports.
- Rename a file, or move a file between directories.

- Build configuration will need to be updated.
- Carbon code will not change. The `package` keyword determines how a file
is imported, so the library is unaffected by filesystem location.
- This additionally requires the steps to rename a library, because
library names must correspond to the renamed paths.

### Preference for few child namespaces

Expand Down Expand Up @@ -1014,7 +1020,7 @@ Disadvantages:
- [Swift](https://developer.apple.com/documentation/swift_packages), as a
distributable unit.

#### Strict association between the filesystem path and library/namespace
#### No association between the filesystem path and library/namespace

Several languages create a strict association between the method for pulling in
an API and the path to the file that provides it. For example:
Expand All @@ -1038,18 +1044,12 @@ For contrast:
- For example, `import "PATH/TO/NAME"` means there is a directory
`PATH/TO` that contains one or more files starting with `package NAME`.

In Carbon, we could say that `import PACKAGE library "PATH/TO/LIBRARY"` means
there are one more more files `PACKAGE/PATH/TO/LIBRARY(.impl)?.carbon`.
In Carbon, we are using a strict association to say that
`import PACKAGE library "PATH/TO/LIBRARY"` means there is a file
`PATH/TO/LIBRARY.carbon` under some package root.

Advantages:

- A strict association between filesystem path and import path makes it easier
to find source files. This is used by some languages for compilation.
- Allows getting rid of the `package` keyword by inferring related information
from the filesystem path.

Disadvantages:

- The strict association makes it harder to move names between files without
updating callers.
- If there were a strict association of paths, it would also need to handle
Expand All @@ -1059,10 +1059,18 @@ Disadvantages:
`config` and a directory `Config/` would conflict, even though this
would be a valid structure on Unix-based filesystems.

We are choosing to avoid the strict association with filesystem paths in order
to ease refactoring. With this approach,
[more refactorings](#potential-refactorings) will not need changes to imports of
callers.
Disadvantages:

- A strict association between filesystem path and import path makes it easier
to find source files. This is used by some languages for compilation.
- Allows getting rid of the `package` keyword by inferring related information
from the filesystem path.

We are choosing to have some association between the filesystem path and library
for API files to make it easier to find a library's files. We are not getting
rid of the `package` keyword because we don't want to become dependent on
filesystem structures, particularly as it would increase the complexity of
distributed builds.

### Libraries

Expand Down Expand Up @@ -1397,7 +1405,7 @@ approaches looks like:
- Alternative: `import "Boost/Random";`
- Multi-layer library:
- Proposal: `import BoostRandom library "Uniform";`
- Alternative: `import "Boost/Random.Uniform";`
- Alternative: `import "Boost/Random.Uniform";`
- Namespaces have no effect on `import` under both approaches.
- Changes to use an imported entity:
- Proposal: `BoostRandom.UniformDistribution`
Expand Down
11 changes: 8 additions & 3 deletions proposals/p0107.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ Related issues that are out-of-scope for this proposal are:
is out of scope.

- Name lookup, including addressing conflicting names between imports and
names in the current file: Name lookup is likely to address this better,
including offering syntax that could refer to it if needed.
names in the current file: the name lookup design is likely to address this
better, including offering syntax that could refer to it if needed.

- After discussion, we believe we do not need to support package renaming.
However, that final decision should be based on name lookup addressing
Expand All @@ -83,6 +83,8 @@ in addition to the `code_and_organization.md` alternatives section.

### Should we switch to a library-oriented structure that's package-agnostic?

**Decision:** No.

Right now, the `package` syntax is very package-oriented. We could instead
eliminate package semantics from code and organization, relying only on
libraries and removing the link to distribution. This is the
Expand All @@ -95,10 +97,13 @@ proposal, or is some other approach preferred?

### Should there be a tight association between file paths and packages/libraries?

**Decision:** Make paths correspond to libraries for API files, not impl files.
Keep `package`.

Right now, the `package` syntax requires the package's own name be repeated
through code. This touches on a couple alternatives:

- [Strict association between the filesystem path and library/namespace](/docs/design/code_and_name_organization.md#strict-association-between-the-filesystem-path-and-librarynamespace)
- Strict association between the filesystem path and library/namespace
- [Referring to the package as `package`](/docs/design/code_and_name_organization.md#referring-to-the-package-as-package)

The end result of taking both alternatives would be that:
Expand Down