Commit Graph

1035 Commits

Author SHA1 Message Date
Jordan Rose
fd48fb3144 Add a mode to Module::forAllVisibleModules that includes private imports.
Also, remove the mode that left the current module out of the callback.
That's easy enough to check for.

No functionality change yet, but groundwork for the next commit (as well
as some possible uses in LLDB).

Swift SVN r12616
2014-01-20 23:25:04 +00:00
Argyrios Kyrtzidis
90fa27f1b6 [AST] Introduce Module::isSystemModule() which is rather self-explanatory.
Swift SVN r12474
2014-01-17 07:33:49 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Doug Gregor
7b0783f985 Move the "gather all substitutions" operation into the AST. SILGen also needs it.
Swift SVN r12142
2014-01-10 22:32:51 +00:00
Jordan Rose
ac2a9c06da When looking for conformances, make sure to check inherited conformances too.
Previously, if we were looking for, say, ForwardIndex conformance on Int,
we would see that Int is a BidirectionalIndex, and that BidirectionalIndex
refines ForwardIndex...but we'd have no way to get a conformance from
BidirectionalIndex (since it's not really BidirectionalIndex that conforms
to ForwardIndex, but rather Int-via-BidirectionalIndex). Change
Module::lookupConformance's helper findExplicitConformance to actually keep
conformance records around and walk those instead of just looking at the
ProtocolDecl's list of adopted protocols.

I don't have a minimal test case for this, but it fixes
<rdar://problem/15691181>, which allows DictionaryIndex to just adopt
BidirectionalIndex and have the ForwardIndex part be inferred. The problem
manifested as a crash in test/stdlib/Dictionary.swift, which just uses a
Dictionary in very basic ways, so I imagine we'll notice if this regresses.

Swift SVN r11521
2013-12-20 22:41:41 +00:00
Jordan Rose
7a30de2efe Disallow inheritance clauses for concrete typealiases.
typealias MyInt: ForwardIndex = Int

There is no real reason to allow this; it's just a static_assert that Int
conforms to ForwardIndex, which would be better spelled some other way.

This only applies to concrete typealiases, i.e. those that simply alias an
underlying type. Associated types can still have both inheritance clauses
and a (default) underlying type.

Swift SVN r11481
2013-12-19 21:13:54 +00:00
Argyrios Kyrtzidis
93c15bed50 [AST] Introduce the ASTPrinter class, and have its callbacks invoked during AST printing.
This provides useful extension points during AST printing.

Swift SVN r11338
2013-12-16 01:26:36 +00:00
Doug Gregor
07c0793e30 Construct the type witnesses of SpecializedProtocolConformance lazily.
A SpecializedProtocolConformance intentionally contains all of the
information we need to synthesize the type witnesses from the
underlying (generic) conformance. Do so lazily rather than eagerly,
because we won't always need all of them.

As a nice side effect, we no longer need to serialize the witnesses of
these specialized protocol conformances, so we can save some space in
the Swift module file.


Swift SVN r11303
2013-12-14 06:20:44 +00:00
Doug Gregor
1b161ff043 Eliminate ProtocolConformance::getTypeWitnesses().
Swift SVN r11301
2013-12-14 05:19:18 +00:00
Dmitri Hrybenko
374aa1d57c AST printing: when printing module interface, explode PatternBindingDecls
The exact pattern that was used to declare a variable is not important from the
module interface point of view.


Swift SVN r11231
2013-12-13 02:19:04 +00:00
Dmitri Hrybenko
11ccb38e06 AST printer: use getDisplayDecls() to find a list of decls to print.
We are still not completely correct in determining which extensions to print,
will fix in future patches.


Swift SVN r10960
2013-12-07 00:54:05 +00:00
Jordan Rose
417b5d3982 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
2013-12-05 01:51:15 +00:00
Jordan Rose
5dda63aa82 Remove LoadedModule, and strip ModuleLoader down to just loading things.
Now that everything is done in terms of FileUnits, we don't need LoadedModule
anymore, and now that FileUnits just use virtual dispatch, we don't need to
indirect through ModuleLoader to distinguish them.

This doesn't quite simplify as much as it could, because the next change is
going to combine TranslationUnit and Module.

Swift SVN r10836
2013-12-05 01:51:12 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Jordan Rose
d0d661164d Move lookupQualified from Module to DeclContext.
Qualified lookup depends not only on the current module but actually the
current file, since imports are file-scoped by default. Currently this only
affects lookup into other modules (e.g. "Foundation.NSString"), but this
could also be used for extension filtering.

This breaks one name resolution test, but the refactoring in the next
commit changes everything anyway and will restore the test.

Swift SVN r10831
2013-12-05 01:51:07 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
Chris Lattner
ecfba9fb53 Rename getBuiltinValue -> getBuiltinValueDecl since it doesn't
produce a value, it produces a decl.



Swift SVN r10697
2013-12-01 02:13:45 +00:00
Jordan Rose
b43dd09107 All SourceFiles should always remember their buffer IDs, not just imports.
Swift SVN r9946
2013-11-04 23:50:48 +00:00
Chris Lattner
68af974227 Remove 'axle' related code and build machinery. It turns out that we
will not be pursuing this project in the immediate future.



Swift SVN r9901
2013-11-03 16:04:27 +00:00
Dmitri Hrybenko
9e346b6b80 Clean up implicit import code: use SmallVector instead of a plain array
Swift SVN r9716
2013-10-28 18:43:46 +00:00
Jordan Rose
fc88c5dae6 Operators imported in one source file shouldn't affect another one.
Previously we would cache the results of operator lookup whether or not the
operator we found came from an imported module. Since different source files
can have different imports, it's not correct to automatically share operators
from imported modules with all files in the translation unit.

This still isn't fully correct; the current logic prefers operators from
local imports over operators implicitly available from other source files.

Swift SVN r9683
2013-10-25 22:21:14 +00:00
Jordan Rose
28e01f3c3a Eliminate "MainSourceFile" from TranslationUnit in favor of an array.
Anywhere that assumes a single input file per TU now has to do so explicitly.
Parsing still puts all files in a single SourceFile instance; that's next on
the list.

There are a lot of issues still to go, but the design is now in place.

Swift SVN r9669
2013-10-25 17:30:37 +00:00
Jordan Rose
cf31df96c5 Push operator lookup into SourceFile, and simplify the interface.
The operator lookup cache already lived in SourceFile, but we need to be
able to look up operators on a per-SourceFile basis. Different files can
have different imports. The interface previously distinguished between
"no operator found" and "error", but none of the call sites were making
use of this distinction, and indeed some were misusing the return value
(Optional<SomeOperatorDecl *>). Now the lookup functions just return
operator decl pointers, which may be null.

Swift SVN r9668
2013-10-25 17:30:33 +00:00
Jordan Rose
0702acab3d Make SourceFile a DeclContext, but don't actually do anything with it yet.
Swift SVN r9646
2013-10-24 18:59:21 +00:00
Jordan Rose
ec23db6962 Push the TU's lookup cache down to SourceFile.
Also move print() and dump() from TranslationUnit to SourceFile.

Swift SVN r9645
2013-10-24 18:59:18 +00:00
Dmitri Hrybenko
80d753d0ab Portability: use std::make_tuple instead of relying on a libc++ extension (an
implicit constructor in std::tuple)


Swift SVN r9615
2013-10-23 06:17:28 +00:00
Mon Ping Wang
00467ba953 Reintroduce "Add support for Axle library." from 9292. Added an dependency to prevent building the
core and axle core at the same time.


Swift SVN r9309
2013-10-14 07:51:19 +00:00
Joe Groff
cf457d2210 Revert "Add support for Axle library." It breaks the build.
This reverts commit r9292.

Swift SVN r9296
2013-10-13 22:38:22 +00:00
Mon Ping Wang
41aca3e7e6 Add support for Axle library. Please note that AxeBuiltins.gyb will be
expanded soon for the other graphics builtins.


Swift SVN r9294
2013-10-13 19:54:01 +00:00
Jordan Rose
1ecf1fb593 Distribute Module's lookup cache to its subclasses.
Each one has a different kind of lookup cache anyway, and there's no real
reason to have them share storage at the cost of type-safety.

Swift SVN r9242
2013-10-12 00:08:09 +00:00
Jordan Rose
ad75aa5021 Remove -l flag from Swift interim driver.
Being able to pass -l to the driver isn't so interesting, and it's an
extra field that lives on TranslationUnit for no reason. Just remove it.

This doesn't interfere with autolinking, i.e. inferring -l flags based on
imported modules.

Swift SVN r9241
2013-10-12 00:08:06 +00:00
Jordan Rose
ce612d3231 Remove TranslationUnit's HasBuiltinModuleAccess field.
This information is important when a SourceFile is created, and never
again after that.

Swift SVN r9240
2013-10-12 00:08:04 +00:00
Argyrios Kyrtzidis
22be594617 [AST] Making the walking parent the TU when walking a SourceFile.
Swift SVN r9137
2013-10-10 14:51:38 +00:00
Argyrios Kyrtzidis
65fd2eed43 [IDE] Provide 'walk' method in SourceEntityWalker for SourceFiles.
Swift SVN r9136
2013-10-10 14:51:37 +00:00
Jordan Rose
0d2ccf7cb3 Adopt SourceFile in name-binding.
Swift SVN r9105
2013-10-09 22:44:32 +00:00
Jordan Rose
589341ac79 Replace operator StringMaps with Identifier-keyed DenseMaps.
Micro-optimization, but avoids extra indirection and allocation associated
with StringMaps.

Swift SVN r9083
2013-10-09 19:11:21 +00:00
Jordan Rose
e83d0d608a Use Optional for SourceFile::getImportBufferID, instead of a sentinel.
No functionality change.

Swift SVN r9082
2013-10-09 18:45:10 +00:00
Jordan Rose
55d4d05b23 Don't automatically create one SourceFile for every TranslationUnit.
Many places are still relying on having one, though.

Swift SVN r9077
2013-10-09 18:38:26 +00:00
Jordan Rose
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +00:00
Dmitri Hrybenko
6895c34741 Code completion: report "semantic context" for every code completion result
Semantic context describes the origin of the declaration and serves the same
purpose as opaque numeric "priority" in Clang -- to determine the most likely
completion.

This is the initial implementation.  There are a few opportunities to bump the
priority of a certain decl by giving it SemanticContextKind::ExprSpecific
context that are not implemented yet.


Swift SVN r9052
2013-10-09 02:08:05 +00:00
Jordan Rose
c2b00fc2d4 Excise the global TranslationUnit from TypeChecker.
Now that TypeChecker is being used to check all sorts of things (not all
from a single TU), it's not really correct to have a single top-level TU
that gets used everywhere. Instead, we should be using the TU that's
appropriate for whatever's being checked. This is a small correctness win
for order-independent type-checking, but is critical for multi-file
translation units, which is needed for implicit visibility.

This basically involves passing around DeclContexts much more.

Caveat: we aren't smart about, say, filtering extensions based on the
current context, so we're still not 100% correct here.

Swift SVN r9006
2013-10-07 23:47:55 +00:00
Dmitri Hrybenko
4a0c050d81 Store the standard library module name as ASTContext::StdlibModuleName
... instead of repeating it everywhere


Swift SVN r8792
2013-09-30 21:07:35 +00:00
Argyrios Kyrtzidis
4a91e28d11 [AST] For the ASTWalker add Module and Decl as a parent kind, and make ParentTy a class.
Swift SVN r8756
2013-09-29 00:12:11 +00:00
Argyrios Kyrtzidis
f32167d166 [AST] Introduce a walk() method for TranslationUnit.
Swift SVN r8729
2013-09-27 17:24:35 +00:00
Jordan Rose
b11fb61b11 Resolve protocols in extensions whenever the base type is accessed.
This is necessary for checking protocol conformance out of order.

Swift SVN r8651
2013-09-25 20:08:27 +00:00
Doug Gregor
978eaab5c6 Introduce lazy computation of a BoundGenericType's substitutions.
Teach a BoundGenericType to compute its own substitutions, which
allows AST clients to create new bound generic types without the aid
of the type checker. 

This eliminates the TypeChecker::validateTypeSimple() abomination as
well as the need for the BoundGenericType AST validation step. There
is still more cleanup to do in this area.

Note that BoundGenericType::getSubstitutions() now accepts a module
parameter, which is the place from which we will look for
conformances. This is a baby step toward properly modeling the
conformances as part of the bound generic type, and is nowhere near
complete.


Swift SVN r8193
2013-09-13 14:25:36 +00:00
Doug Gregor
2ca2ce9e73 Teach BoundGenericType to compute its own substitutions.
This eliminates the need for the hackish
LazyResolver::resolveUnvalidatedType() entry point, making type
substitution on ASTs far more useful. As part of this, teach it to
handle conformances for existentials and archetypes.


Swift SVN r8169
2013-09-12 22:51:21 +00:00
Doug Gregor
12c365e643 Allow type substitution with a null resolver.
This allows AST clients to perform type substitutions without
requiring a type checker. Test this by performing substitutions within
the AST verifier.


Swift SVN r8166
2013-09-12 21:53:22 +00:00
Doug Gregor
526dbd8231 Propagate explicit-conformance declaration to inherited protocol checks.
Eliminates the redundant diagnostics I introduced in r8127.


Swift SVN r8163
2013-09-12 21:06:03 +00:00