Commit Graph

439 Commits

Author SHA1 Message Date
Jordan Rose
68272b15c4 Remove FailedImportModule. A failed import is now represented as an empty TU.
No other functionality change.

Swift SVN r10833
2013-12-05 01:51:10 +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
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
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
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
Jordan Rose
8b6b9b7965 Use 'unsigned' to represent a present input buffer ID.
LLVM's SourceMgr uses 'int' for buffer IDs, but -1 is a special placeholder
value that means "no such buffer". Swift's SourceManager then makes a
distinction between 'unsigned' and 'int' -- an unsigned buffer ID always
refers to an actual buffer, while an int ID may be -1. Respect this in
SourceFile, which uses Optional to represent a "potential" buffer.

Swift SVN r9239
2013-10-12 00:08:01 +00:00
Jordan Rose
7b936e2b85 Remove unfinished notion of "Component" (originally for resilience).
docs/Resilience.rst describes the notion of a resilience component:
if the current source file is in the same component as a module being
used, it can use fragile access for everything in the other module,
with the assumption that everything in a component will always be
recompiled together.

However, nothing is actually using this today, and the interface we
have is probably not what we'll want in 2.0, when we actually implement
resilience.

Swift SVN r9174
2013-10-10 21:41:57 +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
ccce45b981 Improve comments for SourceFile.
Swift SVN r9081
2013-10-09 18:38:30 +00:00
Jordan Rose
266c445b3c Push ASTStage down into SourceFile.
This was only meaningful for TranslationUnit anyway, and it may help
avoid repeating work in the future.

Swift SVN r9079
2013-10-09 18:38:28 +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
09787207fc Push TUKind into SourceFile (as InputKind).
Different SourceFiles in the same module will eventually have different
input kinds (at the very least Main vs. Library).

Swift SVN r9076
2013-10-09 18:38:25 +00:00
Jordan Rose
f5de2e43d7 Push SourceFile into Parser and REPL somewhat.
Swift SVN r9073
2013-10-09 18:38:17 +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
3bb5ae1ef4 ExternalNameLookup: fix the build and address review comments
Swift SVN r9016
2013-10-08 01:20:49 +00:00
Sean Callanan
03e51df72e Added ExternalNameLookup, a mechanism that allows
UnqualifiedLookup to ask an external source for
names.  There are two phases to this external lookup:

- Before consulting globals in other modules,
  UnqualifiedLookup calls lookupOverrides() to see
  if there are any results that should override the
  results from modules.  (N.b.: these should not be
  able to override names that are locally defined.)

- After consulting globals in other modules,
  UnqualifiedLookup as a last resort calls
  lookupFallbacks() to see if there's anything out
  there at all that could serve that name.  This may
  be more computationally expensive.

These hooks are used by LLDB's expression parser to
resolve names for persistent variables (akin to the
existing $0, $1, ... variables) and variables local
to the current frame.


Swift SVN r9014
2013-10-08 00:58:14 +00:00
Argyrios Kyrtzidis
963b6f0579 [serialization] Introduce 'FailedImportModule', which is used to track of when a module file failed to load (e.g. because of missing dependencies).
Swift SVN r8934
2013-10-04 21:29:24 +00:00
Argyrios Kyrtzidis
3e2f360e45 [AST] In the ModuleKind enum class, shorten enumerators by removing 'Module'. No functionality change.
Swift SVN r8933
2013-10-04 21:29:22 +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
f32167d166 [AST] Introduce a walk() method for TranslationUnit.
Swift SVN r8729
2013-09-27 17:24:35 +00:00
Jordan Rose
15bfc8db2b Don't type-check imported decls unless referenced in the source file.
Instead, pass a LazyResolver down through name lookup, and type-check
things on demand. Most of the churn here is simply passing that extra
LazyResolver parameter through.

This doesn't actually work yet; the later commits will fix this.

Swift SVN r8643
2013-09-25 20:08:14 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Doug Gregor
e6076d1caf Move protocol-conformance computation into Module::lookupConformance().
Introduce an AST operation that, given a type and a protocol, determines
whether the type conforms to the protocol and produces the protocol
conformance structure. Previously, this operation was only available
on the type checker, requiring many callbacks from the AST to the type
checker during AST substitution operations (for example).

Now, we only call back into the type checker when we hit a case where
we see an explicit conformance in the AST, but the actual
ProtocolConformance object has not yet been built due to lazy type
checking.

Note that we still require a resolver (i.e., a TypeChecker) in a few
places, although we shouldn't need it outside of lazy type
checking. I'll loosen up the restrictions next.

There's a minor diagnostics regression here that will be cleaned up in
a future commit.


Swift SVN r8129
2013-09-12 00:23:19 +00:00
Chris Lattner
55200e5274 Now that Module has its own kind field, drop the various module
discriminators from DeclContext.  This is cleaner and should
enable us to drop the alignment of DeclContext (coming next Jordan!)



Swift SVN r8059
2013-09-09 22:43:11 +00:00
Chris Lattner
53e0f11141 Introduce a new ModuleKind enum to implement RTTI for module downcasting.
No functionality change.



Swift SVN r8053
2013-09-09 21:53:21 +00:00
Argyrios Kyrtzidis
36a469df0b [modules] Introduce Module::getTopLevelDecls() to get the local-in-module top-level decls.
getDisplayDecls() was introduced for ":print_module" and works slightly differently, e.g.
it will return the decls from a shadowed clang module, since we want to display them.

Swift SVN r7909
2013-09-04 20:55:27 +00:00
Argyrios Kyrtzidis
2a6dc12607 [modules] Introduce APIs to get the path for the file that a module came from.
Swift SVN r7890
2013-09-04 01:57:53 +00:00
Doug Gregor
b06e65c3b3 Add the DynamicLookup protocol for lookup across all classes and protocols.
When performing member lookup into an existential that involves the
DynamicLookup protocol, look into all classes and protocols for that
member. References to anything found via this lookup mechanism are
returned as instances of Optional.

This introduces the basic lookup mechanics into the type
checker. There are still numerous issues to work through:
  - Subscripting isn't supported yet
  - There's no SILGen or IRGen support
  - The ASTs probably aren't good enough for the above anyway
  - References to generics will be broken
  - Ambiguity resolution or non-resolution

Thanks to Jordan for the patch wiring up DynamicLookup.


Swift SVN r7689
2013-08-28 21:38:50 +00:00
Sean Callanan
6fd2cd3686 Added the option to TranslationUnit::dump() to
have the output go to a provided ostream.  This
allows it to be used for logging in LLDB.


Swift SVN r7681
2013-08-28 19:57:38 +00:00
Jordan Rose
eef39ff914 Add a :print_module directive to the REPL.
This is basically the same as doing a :print_decl on every decl in the module,
except that it does not print extensions that come from other modules, and
/does/ print extensions and operators that come from this module.

Does not yet work for Clang modules or the Builtin module.

Swift SVN r7601
2013-08-26 23:07:51 +00:00
Jordan Rose
22912bc3b3 Add a -l flag to Swift and use it to provide autolinking information.
The spelling of the flag can certainly be changed; I just wanted to get
something up and running.

Swift SVN r7582
2013-08-26 18:57:48 +00:00
Jordan Rose
7d6d336983 Add autolinking infrastructure to Module and ClangImporter.
...and use it to load frameworks and libraries in immediate modes (-i and
the REPL), replacing a walk of visible modules that checked if any imported
modules were Clang modules.

Swift SVN r7488
2013-08-22 23:20:23 +00:00
Jordan Rose
f1bc7801f4 Rework getReexportedModules to optionally find all imported modules.
...instead of just those that are re-exported. This will be used for
autolinking (and probably few other places).

As part of this, we get two name changes:
  (1) Module::getReexportedModules -> getImportedModules
  (2) TranslationUnit::getImportedModules -> getImports

The latter doesn't just get modules-plus-access-paths; it also includes
whether or not the import is re-exported. Mainly, though, it just didn't
seem like a good idea to overload this name when the two functions aren't
really related.

No tests yet, will come with autolinking.

Swift SVN r7487
2013-08-22 23:20:18 +00:00
Doug Gregor
1ddb34fb71 Factor generic parameters and associated types into their own decl nodes.
Previously, TypeAliasDecl was used for typealiases, generic
parameters, and assocaited types, which is hideous and the source of
much confusion. Factor the latter two out into their own decl nodes,
with a common abstract base for "type parameters", and push these
nodes throughout the frontend.

No real functionality change, but this is a step toward uniquing
polymorphic types, among other things.


Swift SVN r7345
2013-08-19 23:36:58 +00:00
Jordan Rose
048c659a32 Remove useless forwarding methods from LoadedModule.
A part of my mind wanted to skip the kind check in Module's implementation
of these if we already knew we were dealing with a LoadedModule, but the
extra level of indirection is fairly annoying. Just jump straight to the
LoadedModule's owner here.

(We can't use virtual methods because we want Module to stay vtable-free.)

Swift SVN r7337
2013-08-19 22:45:10 +00:00
Jordan Rose
2c7858bfb2 Add an entry point for id-style lookup of a known name.
This will be used to resolve properties and method calls on objects with
dynamic-lookup ("id") type. For now, this is tested in swift-ide-test
by using the -dynamic-lookup-completion option and providing a
-code-completion-token value.

Caveats/TODOs:
- As before, since we're using the global method pool, this isn't scoped by
  module. We could do a per-module filter, but I don't know if that will
  actually buy us much.
- Again, Clang's method pool does not include methods from protocols.
- Lookup by selector name cannot find properties with a customized getter
  name. <rdar://problem/14776565>
- The Clang-side method pool is keyed by selector, but Swift wants to look
  things up by method name, which maps to the first selector piece, so we
  end up having to do a scan of all the selectors in the pool.

Swift SVN r7330
2013-08-19 21:33:33 +00:00
Jordan Rose
5486dd4dba Module::forAllVisibleModules never needs to capture its callback.
...so, add a templated overload that ensures that lambdas aren't copied,
so that callers don't need to add an explicit makeStackLambda().

No functionality change.

Swift SVN r7303
2013-08-16 23:32:43 +00:00
Jordan Rose
2241086363 Add lookupClassMembers for use in id-style dynamic lookup.
With this, we can now get a list of all class members* available in the
current translation unit, which will be necessary for doing id-style
dynamic lookup (inferring which method you're referring to when the base
type is some magic "dynamic lookup" type).

* Including members of protocols, since a class we don't know about could
have implemented the protocol.

Since there is no code currently using this, I've added a new mode to
swift-ide-test to just dump all class members -- what will eventually
happen when you code complete on a dynamic lookup type. This mode will
go away once the other pieces of id-style lookup are in place.

Swift SVN r7287
2013-08-16 20:22:14 +00:00
Jordan Rose
ae67a7719a Cache results of visible decl lookup at top-level in a TranslationUnit.
This is a tradeoff, assuming that lookup in a particular module is less
likely to be repeated than lookup within the current source file. By
storing the cached results with the TU's own local lookup cache, the
results get cleared out when we parse additional decls.

Since this is only used by code completion, there's no performance benefit
for the compiler, or even for swift-ide-test...it's only in repeated lookups
that this will be useful.

Swift SVN r7169
2013-08-12 18:54:59 +00:00
Doug Gregor
0d37a6ee3d Let the type checker decide which protocol members are visible via conforming types.
Deduced associated types are implemented by allowing name lookup into
a type to find the requirements in  the protocols to which that type
conforms. If the protocol conformance produced the witness for the
requirement via deduction (or, eventually, default definitions), we
use the deduced witness; otherwise, the actual declaration within the
type itself is used.

Previously, the AST-level lookup was deciding whether to filter out
protocol requirements based on the conformance information in the
AST. However, this lead to ordering dependencies, because the type
checker doesn't record the conformances in the AST until we've visited
all of the conformances for a given declaration. This lead to an
oddity where one could have one conformance depend on another's
deduced associated type, but only if that conformance was on a later
extension. Fixes <rdar://problem/14685674>.

As part of this, teach the type checker to re-use normal conformances
that get deserialized, rather than creating new ones. Otherwise, we'll
end up with two different copies of the same conformance running
around.


Swift SVN r7075
2013-08-09 01:03:39 +00:00