Core is a keywordIntroduce a principle that the Carbon language should not encroach on the
developer's namespace. Satisfy this principle by making Core a keyword.
Ongoing design work needs rules for how to expose types such as a primitive array type to Carbon code, and in particular, if we choose to make it available by default, whether that should be accomplished by a keyword or a predeclared identifier.
See the Background section of the added principle.
We choose to not have any predeclared identifiers in Carbon. If a word has special meaning to the language, then that word is a keyword, and a plain identifier with no special meaning is always available using raw identifier syntax.
See the principle document for details of the added principle. In addition, we make one change and one clarification:
Core is changed from being an identifier that happens to be the name of
the Carbon standard library, and happens to be predeclared in every source
file as naming that library, to being a keyword. The keyword can only be
used:
Core package.Core package as part of the language
implementation.Core package, much like the package keyword.The identifier r#Core can be used freely and does not conflict with the
keyword. This includes use of r#Core as the name of a package. Language
constructs that are defined in terms of entities in the Core package refer
specifically to the package named with the keyword Core, not to any
other entity named Core.
The self keyword is now included in the list of keywords. It is already
treated as a keyword by the toolchain.
Core.<name> without
needing to do any name lookup or sophisticated analysis.Core.<name> without concern that Core may have some
different local interpretation.CppThe special package name Cpp that refers to code written in C++ is not made a
keyword by this proposal, but this proposal is also not deciding that it should
not be a keyword. While this name has special meaning to the language, it's
not predeclared in any context, so it's considered to be out of scope. A future
proposal that describes the details of C++ import should determine whether this
name becomes a keyword. Notably, making Cpp a keyword would also allow an
import Cpp declaration to have custom syntax, which may be useful.
MainThe special package name Main that is currently reserved in all package name
contexts is not made a keyword in this proposal either. There would be no
meaning in making it a keyword, as it is never used as a special package name in
Carbon source files. However, we could consider using an empty package name as
the name of the main package, and unreserving the package name Main, if it
becomes a concern that we reserve this name.
We could provide both predeclared identifiers and keywords. Many languages follow this path. However, predeclared identifiers have some problems compared to keywords:
We could reserve words with certain spellings for future use as keywords or as vendor extensions. Some languages do this:
__name__ namespace for certain special names, and by
convention these names are reserved for that purpose.In Carbon we could accomplish this by saying that all words of the reserved forms are keywords, with no meaning ascribed to them yet.
However, we do not have a clear need for such reserved words at this time, and we would not want to use such spellings when we do add language keywords later. Moreover, C++ programs frequently declare reserved words in practice, and we should expect the same in Carbon. Without enforcement, the names are not effectively reserved.
If we find a need at a later time to introduce vendor-specific language
extension keywords, we can revisit this, but should also consider alternatives
such as a k#foo spelling to turn what is normally an identifier into a
(potentially vendor-specific) keyword.