Commit Graph

463 Commits

Author SHA1 Message Date
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
Jordan Rose
a35f7cbd4b Thread [exported] through TranslationUnit and the Serialization library.
This still doesn't do anything yet.

Swift SVN r7051
2013-08-08 19:09:21 +00:00
Jordan Rose
841e3f4bd4 Properly ignore declarations not within the access path of a scoped import.
We now handle this correctly:
  import struct aeiou.A
  import struct aeiou.E

  var _ : aeiou.O // error

Swift SVN r7046
2013-08-08 17:38:24 +00:00
Jordan Rose
49fc1ba334 Implement proper shadowing rules for unqualified lookup.
This includes proper rules for function overloads (i.e. shadowing by type)
and allowing type lookup to find a type even if it has the same name as
a non-type.

lookupVisibleDecls does not use this behavior yet.

Swift SVN r7016
2013-08-07 22:57:05 +00:00
Jordan Rose
027565a9a9 Implement proper shadowing rules for qualified lookup.
This required a general reworking of the algorithm for qualified name lookup.
Originally, qualified lookup only applied to a module -- not to its exports.
This meant that "Cocoa.NSWindow" would fail, so that was changed to grovel
through all exported modules looking for decls if the top-level module didn't
provide any.

Now, we actually do a breadth-based search, stopping at each level if decls
are provided for a given name. We also now prefer scoped imports to unscoped
imports, so "import abcde" and "import struct asdf.D" will result in a
(qualified) reference to 'D' being unambiguous.

Not working yet:
 - Shadowing for unqualified lookup.
 - Shadowing by types, so that overloads from this module can merge with
   overloads from its exports.

Swift SVN r7014
2013-08-07 22:56:49 +00:00
Jordan Rose
9d5c803aff Enable specific-decl imports.
Note that the import kind is not checked yet; this is effectively our old
behavior for "import swift.print".

Infrastructure: move Module::forAllVisibleModules out-of-line, and add
makeStackLambda to STLExtras for using a non-escaping lambda with
std::function.

Swift SVN r6852
2013-08-02 21:00:41 +00:00
Jordan Rose
f03245a206 Fix up a bunch of filtering-by-decl-access-path.
Mostly cleanup, a few filled-in FIXMEs to filter out decls that don't match
the access path name.

Swift SVN r6850
2013-08-02 21:00:28 +00:00
Adrian Prantl
2332517e36 Debug info: Fix an invalid pointer deref.
Swift SVN r6812
2013-08-01 18:47:58 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Joe Groff
507c41dc7b Reformat comment so it stops spewing -Wdocumentation warnings.
Swift SVN r6755
2013-07-30 22:33:32 +00:00
Chris Lattner
9f3a0f37f7 fix -Wdocumentation warning.
Swift SVN r6736
2013-07-30 04:43:27 +00:00
Adrian Prantl
2306563aa2 Debug info: emit the module name for types declare in a swiftmodule.
Swift SVN r6734
2013-07-30 01:17:02 +00:00
Jordan Rose
acce3767db Introduce Module::forAllVisibleModules, and use it where useful.
This iterates over a module's exports, transitively, in an unspecified
but deterministic order. This is useful for any sort of lookup and for
managing transitive inclusion. It also allows us to remove the hack in
Sema for loading a Clang module's adapter module, and just rely on the
previous commit.

Swift SVN r6699
2013-07-29 18:57:04 +00:00
Jordan Rose
45bad83c54 Add a protected LoadedModule::getOwner to simplify r6519.
(r6159 stashed a LoadedModule's owner in the "LookupCachePimpl" field.)

Swift SVN r6696
2013-07-29 18:56:45 +00:00
Jordan Rose
d9b7c8ad5a Move ClangModule into the ClangImporter library.
This makes it very clear who is depending on special behavior at the
module level. Doing isa<ClangModule> now requires a header import; anything
more requires actually linking against the ClangImporter library.

If the current source file really can't import ClangModule.h, it can
still fall back to checking against the DeclContext's getContextKind()
(and indeed AST currently does in a few places).

Swift SVN r6695
2013-07-29 18:56:35 +00:00
Jordan Rose
8e081367ca Basic implementation of lookupVisibleDecls() for serialized modules.
This involved threading it through ModuleLoader, as with all the other
module-generic callbacks. I plan to collapse a bit of the chaining, but
unfortunately not that much.

This brings back the CodeCompletion tests.

Swift SVN r6527
2013-07-23 23:10:28 +00:00
Jordan Rose
3087e8d5ea Add the notion of "re-exported" modules, and use that where it makes sense.
Rather than automatically re-exporting or not re-exporting every import in
a TranslationUnit, we'll eventually want to control which imports are local
(most of them) and which imports are shared with eventual module loaders.
It's probably not worth implementing this for TranslationUnit, but
LoadedModule can certainly do something here.

Currently, a LoadedModule is even more permissive than a TranslationUnit:
all imports are re-exported. We can lock down on this once we have a
re-export syntax.

Swift SVN r6523
2013-07-23 23:10:17 +00:00
Jordan Rose
110d644297 Provide a skeleton for re-exports from serialized modules...
...and use it for shadowed modules (e.g. the Clang module "Foundation"
referenced by the Swift module "Foundation"), so that we can actually
find "NSString" when building AppKit.

Additionally, record shadowed modules as dependencies, so that they can
be loaded when the adapter module is loaded.

Swift SVN r6522
2013-07-23 23:10:13 +00:00
Jordan Rose
f12f3c29ac Reuse "LookupCache" pointer for a LoadedModule’s owner.
Minor size optimization. No functionality change.

Swift SVN r6521
2013-07-23 23:10:11 +00:00
Argyrios Kyrtzidis
7476762dae Remove IdentifierType from the type system.
Swift SVN r6327
2013-07-17 14:57:38 +00:00
Dmitri Hrybenko
aa46064432 Pass a const ASTContext and const DeclContext whenever possible. This makes it
possible to use lookupVisibleDecls() with a const DeclContext.


Swift SVN r6274
2013-07-15 23:39:00 +00:00
Doug Gregor
61060baf8e Eliminate the type-checking pass that resolves default arguments in tuple types.
Per r6154, this is now dead code. The only places we allow default
arguments will be visited by normal type validation, so there's
nothing specific to do here.


Swift SVN r6157
2013-07-11 18:06:14 +00:00
Doug Gregor
fc1c256ef5 Allow references to deduced associated types.
When checking a type's conformance against a protocol, we can deduce
the values of associated types. Make these associated types visible to
qualified name lookup so that (for example) VectorEnumeratorType does
not need to define the Element type. It is deduced from the signautre
of next(), and made available as, e.g.,
VectorEnumeratorType<Int>.Element through the Enumerator protocol
conformance. Fixes <rdar://problem/11510701>, but with some lingering
dependencies on lazy type resolution (<rdar://problem/12202655>).

Note that the infrastructure here is meant to be generalized to
support default implementations in protocols, but there are several
pieces still not in place.



Swift SVN r6073
2013-07-08 22:32:27 +00:00
Doug Gregor
d237ececbc Move NameLookupOptions t Module.h.
Swift SVN r5922
2013-07-01 14:09:37 +00:00
Doug Gregor
1239757489 [Name lookup] Move ASTContext::lookup to Module::lookupQualified, where it belongs.
No functionality change.


Swift SVN r5921
2013-07-01 14:05:55 +00:00
Chris Lattner
27009ac5bd rework handling of -parse-stdlib to make it orthogonal from the mode we're in,
with the specific goal of making it work with -i.


Swift SVN r5807
2013-06-26 04:17:56 +00:00
Chris Lattner
1040bfec6a In the REPL, allow access to the Builtin module if explicitly imported,
there is no reason to deny it and it could be theoretically useful.


Swift SVN r5779
2013-06-24 16:07:56 +00:00