Skip to content

Commit 417b5d3

Browse files
committed
Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple FileUnits, which provide decls from various file-like sources. I say "file-like" because the Builtin module is implemented with a single BuiltinUnit, and imported Clang modules are just a single FileUnit source within a module. Most modules, therefore, contain a single file unit; only the main module will contain multiple source files (and eventually partial AST files). The term "translation unit" has been scrubbed from the project. To refer to the context of declarations outside of any other declarations, use "top-level" or "module scope". To refer to a .swift file or its DeclContext, use "source file". To refer to a single unit of compilation, use "module", since the model is that an entire module will be compiled with a single driver call. (It will still be possible to compile a single source file through the direct-to-frontend interface, but only in the context of the whole module.) Swift SVN r10837
1 parent 5dda63a commit 417b5d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+521
-629
lines changed

Diff for: docs/LangRef.html

+13-14
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ <h2>Phases of Translation</h2>
134134
are:</p>
135135

136136
<ul>
137-
<li><a href="#lexical">Lexing</a>: A translation unit is broken into tokens
137+
<li><a href="#lexical">Lexing</a>: A source file is broken into tokens
138138
according to a (nearly, /**/ comments can be nested) regular grammar.</li>
139139
<li>Parsing and AST Building: The tokens are parsed according to the grammar
140140
set out below. The grammar is context free and does not require any "type
141141
feedback" from the lexer or later stages. During parsing, name binding for
142142
references to local variables and other declarations that are not at
143-
translation unit (and eventually namespace) scope are bound.
143+
module (and eventually namespace) scope are bound.
144144
</li>
145145
<li><a href="#namebind">Name Binding</a>: At this phase, references to
146146
non-local types and values are bound, and <a href="#decl-import">import
@@ -157,7 +157,7 @@ <h2>Phases of Translation</h2>
157157
</ul>
158158

159159
<p>
160-
FIXME: "import swift" implicitly added as the last import in translation unit.
160+
FIXME: "import swift" implicitly added as the last import in a source file.
161161
</p>
162162

163163
<!-- ********************************************************************* -->
@@ -617,17 +617,16 @@ <h2 id="decl">Declarations</h2>
617617

618618

619619
<!-- ===================================================================== -->
620-
<h3 id="decl-translation-unit">Translation Unit</h3>
620+
<h3 id="decl-top-level">Module-Scope Declarations</h3>
621621
<!-- ===================================================================== -->
622622

623623
<pre class="grammar">
624-
translation-unit ::= <a href="#brace-item-list">brace-item</a>*
624+
top-level ::= <a href="#brace-item-list">brace-item</a>*
625625
</pre>
626626

627627
<p>The top level of a swift source file is grammatically identical to the
628-
contents of a func decl. Some declarations
629-
have semantic restrictions that only allow them within a translation unit
630-
though.
628+
contents of a func decl. Some declarations, however, are restricted to
629+
module scope.
631630
</p>
632631

633632
<!-- _____________________________________________________________________ -->
@@ -644,7 +643,7 @@ <h4 id="brace-item-list">Brace Enclosed Items</h4>
644643
<p>The brace item list provides a sequencing operation which evaluates the
645644
members of its body in order. Function bodies and the bodies of control
646645
flow statements use braces. Also, the <a
647-
href="#decl-translation-unit">translation unit</a> itself is effectively a
646+
href="#decl-top-level">source file</a> itself is effectively a
648647
brace item list, but without the braces.
649648
</p>
650649

@@ -670,9 +669,9 @@ <h3 id="decl-import">import Declarations</h3>
670669
local names, even when they are defined in other modules and namespaces. See
671670
the section on <a href="#namebind">name binding</a> for more
672671
information on how these work. import declarations are only allowed at
673-
translation unit scope.</p>
672+
module scope.</p>
674673

675-
<p>'import' directives only impact a single translation unit: imports in one
674+
<p>'import' directives only impact a single source file: imports in one
676675
swift file do not affect name lookup in another file. import directives can
677676
only occur at the top level of a file, not within a function or namespace.</p>
678677

@@ -731,7 +730,7 @@ <h3 id="decl-extension">extension Declarations</h3>
731730
</pre>
732731

733732
<p>'extension' declarations allow adding member declarations to existing
734-
types, even in other translation units and modules. There are different
733+
types, even in other source files and modules. There are different
735734
semantic rules for each type that is extended.
736735
</p>
737736

@@ -3727,7 +3726,7 @@ <h3 id="namebind_typevalue_lookup">Name Lookup for Type and Value Names</h3>
37273726
<li>Search the current scope tree for a local name. Local names cannot be
37283727
forward referenced.</li>
37293728
<li>Bind to names defined in the current component, including the current
3730-
translation unit. TODO: is this a good thing? We could require explicit
3729+
module. TODO: is this a good thing? We could require explicit
37313730
imports if we wanted to.</li>
37323731
<li>Bind to identifiers that are imported with an import directive. Imports
37333732
are searched in order of introduction (top-down). The location of an
@@ -3785,7 +3784,7 @@ <h2 id="stdlib">Standard Library</h2>
37853784
the library.</p>
37863785

37873786
<p>All of this code is published by the 'swift' module, which is
3788-
implicitly imported into each translation unit, unless some sort of pragma
3787+
implicitly imported into each source file, unless some sort of pragma
37893788
in the code (attribute on an import?) is used to change or disable this
37903789
behavior.</p>
37913790

Diff for: docs/Literals.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ How about cases where there is no context? ::
106106
var str = "abc"
107107

108108
Here we have nothing to go on, so instead the type checker looks for a global
109-
type named ``StringLiteralType`` in the current translation unit, and uses
109+
type named ``StringLiteralType`` in the current module-scope context, and uses
110110
that type if it is actually a StringLiteralConvertible type. This both allows
111111
different standard libraries to set different default literal types, and allows
112112
a user to *override* the default type in their own source file.

Diff for: include/swift/AST/ASTContext.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ namespace swift {
6363
class Module;
6464
class ModuleLoader;
6565
class NominalTypeDecl;
66-
class TranslationUnit;
6766
class TupleTypeElt;
6867
class EnumElementDecl;
6968
class ProtocolDecl;
@@ -166,7 +165,7 @@ class ASTContext {
166165
llvm::StringMap<Module*> LoadedModules;
167166

168167
/// The builtin module.
169-
TranslationUnit * const TheBuiltinModule;
168+
Module * const TheBuiltinModule;
170169

171170
/// The standard library module.
172171
mutable Module *TheStdlibModule = nullptr;

Diff for: include/swift/AST/Decl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1042,11 +1042,11 @@ class PatternBindingDecl : public Decl {
10421042

10431043
/// TopLevelCodeDecl - This decl is used as a container for top-level
10441044
/// expressions and statements in the main module. It is always a direct
1045-
/// child of the body of a TranslationUnit. The primary reason for
1046-
/// building these is to give top-level statements a DeclContext which is
1047-
/// distinct from the TranslationUnit itself. This, among other things,
1048-
/// makes it easier to distinguish between local top-level variables (which
1049-
/// are not live past the end of the statement) and global variables.
1045+
/// child of a SourceFile. The primary reason for building these is to give
1046+
/// top-level statements a DeclContext which is distinct from the file itself.
1047+
/// This, among other things, makes it easier to distinguish between local
1048+
/// top-level variables (which are not live past the end of the statement) and
1049+
/// global variables.
10501050
class TopLevelCodeDecl : public Decl, public DeclContext {
10511051
BraceStmt *Body;
10521052

Diff for: include/swift/AST/DeclContext.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,9 @@ class alignas(8) DeclContext {
234234
LazyResolver *typeResolver,
235235
SmallVectorImpl<ValueDecl *> &decls) const;
236236

237-
/// getASTContext - Return the ASTContext for a specified DeclContext by
237+
/// Return the ASTContext for a specified DeclContext by
238238
/// walking up to the enclosing module and returning its ASTContext.
239-
ASTContext &getASTContext();
240-
const ASTContext &getASTContext() const {
241-
return const_cast<DeclContext *>(this)->getASTContext();
242-
}
239+
ASTContext &getASTContext() const;
243240

244241
/// \returns true if traversal was aborted, false otherwise.
245242
bool walkContext(ASTWalker &Walker);

Diff for: include/swift/AST/ExternalNameLookup.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class ExternalNameLookup {
3131
virtual ~ExternalNameLookup() = default;
3232

3333
/// ExternalNameLookup is consulted at two times during name
34-
/// lookup. This is the first time: after all names in the
35-
/// TranslationUnit have been checked but before external
34+
/// lookup. This is the first time: after all names in a
35+
/// source file have been checked but before external
3636
/// Modules are checked. The results in the ResultVector will
3737
/// be consulted first. Return true if results have been added
3838
/// to RV.

0 commit comments

Comments
 (0)