Skip to content

Commit 7abae0c

Browse files
committed
Address some review comments. Fill out rationale.
1 parent eb3d349 commit 7abae0c

2 files changed

Lines changed: 43 additions & 14 deletions

File tree

docs/project/principles/namespace_cleanliness.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ for entities. Different languages make different choices in this space:
3434

3535
- Many languages have a set of keywords that are not usable as identifiers,
3636
with no workaround. If this set collides with a name needed by user code,
37-
the user is left to solve this problem, often by rewriting the
38-
identifier in some way (`klass` or `class_`), which sometimes conflicts with the general
37+
the user is left to solve this problem, often by rewriting the identifier in
38+
some way (`klass` or `class_`), which sometimes conflicts with the general
3939
naming convention used by the code. And conversely, suboptimal choices are
4040
made for new language keywords to avoid causing problems for existing code.
4141
- C and C++ reserve a family of identifiers, such as those beginning with an
@@ -44,7 +44,12 @@ for entities. Different languages make different choices in this space:
4444
library vendors and compiler authors, as well as between implementation
4545
extensions and language extensions.
4646
- MSVC provides a `__identifier(keyword)` extension that allows using a
47-
keyword as an identifier.
47+
keyword as an identifier. This extension is also implemented by Clang in
48+
`-fms-extensions` mode.
49+
- GCC provides an `__asm__(symbol)` extension that allows a specific
50+
symbol to be assigned to an object or function, which provides ABI
51+
compatibility but not source compatibility with code that uses a keyword
52+
as a symbol name. This extension is also implemented by Clang.
4853
- Python reserves some identifiers but still allows them to be freely
4954
overwritten (such as `bool`) and reserves some identifiers but rejects
5055
assignment to them (such as `True`).
@@ -61,10 +66,11 @@ for entities. Different languages make different choices in this space:
6166
extending this to allow arbitrary non-word-shaped character sequences
6267
between the `` ` ``s.
6368

64-
Carbon provides raw identifier syntax, for example `r#for`, to allow using
65-
keywords as identifiers. Carbon also has strict shadowing rules that mean that
66-
predeclared identifiers that are _not_ keywords are difficult or impossible to
67-
redeclare and use in inner scopes.
69+
Carbon provides
70+
[raw identifier syntax](/docs/design/lexical_conventions/words.md#raw-identifiers),
71+
for example `r#for`, to allow using keywords as identifiers. Carbon also intends
72+
to have strict shadowing rules that may make predeclared identifiers that are
73+
_not_ keywords difficult or impossible to redeclare and use in inner scopes.
6874

6975
## Principle
7076

@@ -77,7 +83,8 @@ Conversely, when adding language keywords, we will not select an inferior
7783
keyword merely to avoid the risk of breaking existing programs. We will still
7884
take into account how often it is desirable to use the word as an identifier,
7985
including in domain-specific contexts, because that is a factor in whether it
80-
would make a good keyword.
86+
would make a good keyword, and will manage the rollout of new keywords to make
87+
it straightforward to migrate existing uses to `r#` or a different name.
8188

8289
## Applications of this principle
8390

proposals/p4864.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,44 @@ clarification:
6868
- As a keyword naming the `Core` package, much like the `package` keyword.
6969

7070
The identifier `r#Core` can be used freely and does not conflict with the
71-
keyword. This includes use of `r#Core` as the name of a package.
71+
keyword. This includes use of `r#Core` as the name of a package. Language
72+
constructs that are defined in terms of entities in the `Core` package refer
73+
specifically to the package named with the _keyword_ `Core`, not to any
74+
other entity named `Core`.
7275

7376
- The `self` keyword is now included in the list of keywords. It is already
7477
treated as a keyword by the toolchain.
7578

7679
## Rationale
7780

78-
- [Community and culture](/docs/project/goals.md#community-and-culture)
7981
- [Language tools and ecosystem](/docs/project/goals.md#language-tools-and-ecosystem)
80-
- [Performance-critical software](/docs/project/goals.md#performance-critical-software)
82+
- Code generation tools can have a uniform handling for all words with
83+
special meaning, with no need to alter the spelling of names from other
84+
languages.
85+
- Language tools can determine the meaning of `Core.<name>` without
86+
needing to do any name lookup or sophisticated analysis.
8187
- [Software and language evolution](/docs/project/goals.md#software-and-language-evolution)
88+
- Migration between versions of Carbon with a changed set of reserved
89+
words can be done uniformly.
90+
- Adding names to the prelude remains a non-breaking change. Adding new
91+
predeclared names requires adding a keyword, with the same cost and
92+
value tradeoffs regardless of whether the keyword names a library
93+
declaration or introduces new language syntax.
8294
- [Code that is easy to read, understand, and write](/docs/project/goals.md#code-that-is-easy-to-read-understand-and-write)
83-
- [Practical safety and testing mechanisms](/docs/project/goals.md#practical-safety-and-testing-mechanisms)
84-
- [Fast and scalable development](/docs/project/goals.md#fast-and-scalable-development)
85-
- [Modern OS platforms, hardware architectures, and environments](/docs/project/goals.md#modern-os-platforms-hardware-architectures-and-environments)
95+
- Syntax highlighting tools can easily distinguish between words with
96+
special meaning and words with program-defined meaning.
97+
- The meaning of core language constructs can be defined as a rewrite in
98+
terms of `Core.<name>` without concern that `Core` may have some
99+
different local interpretation.
86100
- [Interoperability with and migration from existing C++ code](/docs/project/goals.md#interoperability-with-and-migration-from-existing-c-code)
101+
- All C++ identifiers are nameable from Carbon code without conflicts.
102+
Virtual functions introduced in Carbon can be overridden in Carbon
103+
regardless of their name. C++ code can be migrated to Carbon even if its
104+
name in C++ has special meaning in Carbon.
105+
- [Principle: Prefer providing only one way to do a given thing](/docs/project/principles/one_way.md)
106+
- This proposal specifies that there is only one way to give words special
107+
meaning in Carbon, and one way to resolve issues if that special meaning
108+
conflicts with another desired meaning.
87109

88110
## Future work
89111

0 commit comments

Comments
 (0)