Commit Graph

85 Commits

Author SHA1 Message Date
Doug Gregor
26eec21081 Factor out the search for explicit conformances.
Swift SVN r8151
2013-09-12 17:52:27 +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
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
04d157427d Make sure that the dynamic lookup table has the right set of members.
Clean up the "can be accessed by dynamic lookup" predicate so that it
checks for a generic context. We no longer need to do the checking in
name lookup, since this means that the dynamic lookup table won't have
anything we can't use (thanks Jordan!). Drop the [objc] allowance for
members of a generic context: it still leaves us with a very weird
case of messaging something when we can't even figure out the type
that we think the object has.

Extend the walk searching for members to include inner classes within
structs, so we get all of the members globally.



Swift SVN r7799
2013-08-30 20:43:34 +00:00
Jordan Rose
a09343e519 Lock down on exports from TranslationUnit modules.
Previously, export control (via [exported]) only applied to modules that
had been serialized -- anything imported in a TranslationUnit was
automatically considered exported. This was done to make life easier when
dealing with the main source file, but it turns out we're going to want to
load other source files as imports, and export control should work there too.

Now, the module iteration methods (Module::forAllVisibleModules,
namelookup::lookupInModule, etc.) can consider the module being passed as
"top-level", meaning its private imports are visible as well. Otherwise,
proper export control is observed even for imported TranslationUnits.

This required a number of test changes involving Swift adapter modules that
forgot to re-export their Clang modules.

Swift SVN r7783
2013-08-30 17:05:32 +00:00
Jordan Rose
7f20dfd304 Include inner class members in dynamic lookup results.
Per discussion with Doug, there's no reason why this should not work:

  class Outer {
    class Inner {
      func extract() { ... }
    }
  }

  var obj : DynamicLookup = ...
  obj.extract!()

Swift SVN r7763
2013-08-29 23:09:33 +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
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
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
f736e1711c Check operator declaration binding in the first pass for FuncDecls.
This eliminates the pre-pass we were performing to bind the operator
decls, which was only a pre-pass because we used to bind unresolved
declaration references too early. In the process, fixed some bugs
(e.g., it wasn't checking methods at all) and improved the QoI with
Fix-Its and notes:

t.swift:2:6: error: prefix unary operator missing 'prefix' attribute
func ~~~(x : Float) {}
     ^
     [prefix] 
t.swift:1:17: note: prefix operator found here
operator prefix ~~~ {}
                ^



Swift SVN r7099
2013-08-09 21:01:47 +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
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
Dmitri Hrybenko
bb3d38b727 Clang importer: put the top-level declarations into the correct ClangModule
Before this change, DeclContext of all imported decls was set to the first
imported module.

No tests now, will be tested by future code completion commits.


Swift SVN r6949
2013-08-06 21:06:44 +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
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
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
Dmitri Hrybenko
5e4db6f19c Remove useless dyn_cast
Swift SVN r5537
2013-06-08 01:04:10 +00:00
Doug Gregor
1641477826 Eliminate lookupExtensions() and the extension cache.
This infrastructure has been replaced by the extension list on nominal
declaration, which is simpler and more efficient.


Swift SVN r5225
2013-05-20 18:26:07 +00:00
Jordan Rose
ec1e47cbf0 Thread operator lookup through Module to ModuleLoader...
...even though Swift modules don't provide this lookup yet, and Clang
modules never will.

Swift SVN r5173
2013-05-16 00:23:10 +00:00
Jordan Rose
7bea410369 Introduce a LoadedModule base class for ClangModule and SerializedModule.
This keeps AST insulated from the various module-loading interfaces, which
minimizes special-casing of the differences between ClangModule and the
(upcoming) SerializedModule.

Swift SVN r5096
2013-05-08 18:33:36 +00:00
Jordan Rose
ccae995f61 Use a list of module loaders instead of a single Clang importer.
This paves the way for having a Swift module importer. The eventual goal
here is to eliminate all explicit uses of the Clang module loader, but
I'm not going to push too hard on that for now.

Swift SVN r5092
2013-05-08 18:09:33 +00:00
Joe Groff
ac23437886 Replace infix attributes with operator decl lookup
During name binding, associate func decls with operator decls. When parsing SequenceExprs, look up operator decls to determine associativity and precedence of infix operators. Remove the infix_left and infix_left attributes, and make the infix attribute a simple declared attribute [infix] with no precedence.

Operator decls are resolved as follows:

- If an operator is declared in the same module as the use, resolve to the declaration in the current module.
- Otherwise, import operator declarations from all imported modules. If more than one declaration is imported for the operator and they conflict, raise an ambiguity error. If they are equivalent, pick one arbitrarily.

This allows operator declarations within the current module to override imported declarations if desired or to disambiguate conflicting operator declarations.

I've updated the standard library and the tests. stdlib2 and some of the examples still need to be updated.

Swift SVN r4629
2013-04-07 02:43:03 +00:00
Joe Groff
bd59da3e9e REPL: Find completions from Clang modules.
Integrating Clang's FindVisibleDecls with Swift's by importing every decl created too much per-repl-entry compile time overhead, so as a workaround, just wire completions directly to FindVisibleDecls on the clang translation unit itself. Unfortunately this means we get completions for things Swift can't import yet, but it also means we don't have to wait 30 seconds to compile every entry after doing a completion.

Swift SVN r4061
2013-02-15 22:30:29 +00:00
Joe Groff
7a7e3d5615 REPL: Hook up completions to name lookup.
Implement a 'lookupVisibleDecls' API similar to Clang's that replicates the UnqualifiedLookup logic for walking through a given scope looking for decls. Use it to populate the completion list in the repl.

Still to be done: Clang module lookup via Clang's lookupVisibleDecls, and context deduction from dotted path expressions.

Swift SVN r4056
2013-02-15 20:17:44 +00:00
Doug Gregor
f3857df469 Implement an AST pretty-printer for declarations, under -print-ast.
Swift SVN r3431
2012-12-10 23:21:49 +00:00
Doug Gregor
b27c6d94f1 Implement global, unqualified name lookup into Clang modules.
Currently, we only support C functions with the signature
void(void).


Swift SVN r3203
2012-11-16 19:42:03 +00:00
Doug Gregor
bb26f52585 Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal
Swift syntax for module imports, e.g.,

  import Cocoa

However, to enable importing Clang modules, one needs to point Swift
at a particular SDK with the -sdk= argument, e.g.,

  swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk

and, of course, that SDK needs to provide support for modules.

There are a number of moving parts here. The major pieces are:

CMake support for linking Clang into Swift: CMake users will now need
to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD
to the locations of the Clang source tree (which defaults to
tools/clang under your LLVM source tree) and the Clang build tree.

Makefile support for linking Clang into Swift: Makefile users will
need to have Clang located in tools/clang and Swift located in
tools/swift, and builds should just work.

Module loader abstraction: similar to Clang's module loader,
a module loader is responsible for resolving a module name to an
actual module, loading that module in the process. It will also be
responsible for performing name lookup into that module.

Clang importer: the only implementation of the module loader
abstraction, the importer creates a Clang compiler instance capable of
building and loading Clang modules. The approach we take here is to
parse a dummy .m file in Objective-C ARC mode with modules enabled,
but never tear down that compilation unit. Then, when we get a request
to import a Clang module, we turn that into a module-load request to
Clang's module loader, which will build an appropriate module
on-the-fly or used a cached module file.

Note that name lookup into Clang modules is not yet
implemented. That's the next major step.



Swift SVN r3199
2012-11-16 18:17:05 +00:00
Eli Friedman
9e06964c8a Make the TypeLoc constructor which takes just a type private, and expose a
static method to call it, to make it more explicit what is happening.  Avoid
using TypeLoc::withoutLoc for function definitions; instead, just use an empty
TypeLoc.



Swift SVN r2606
2012-08-10 02:09:00 +00:00
Eli Friedman
d6a4ba90dd Move TypeLocs to a design where a TypeLoc is a struct containing a type plus
location info for that type.  Propagate TypeLocs a bit more through the AST.



Swift SVN r2383
2012-07-20 21:00:30 +00:00
Doug Gregor
c5a1edd1b8 Revert r2372, which is breaking some tests.
Swift SVN r2375
2012-07-19 21:32:22 +00:00
Eli Friedman
fca009f280 TypeLoc-related cleanup: add FIXMEs to the places in validateType that need to
compute sub-TypeLocs, and fix the places that don't need them not to reuse the
parent TypeLoc.



Swift SVN r2374
2012-07-19 04:01:59 +00:00
Eli Friedman
361f931a16 Start propgating TypeLocs from the parser into the AST.
Swift SVN r2372
2012-07-19 02:54:28 +00:00
Eli Friedman
a1a182e3d9 Initial implementation of member operators. Known limitations: currently only works for operators on structs/classes, the lookup rules aren't completely settled,
and we don't actually check whether it's reasonable to declare a given operator as a member.



Swift SVN r2277
2012-06-29 00:47:33 +00:00
Eli Friedman
18dfa5cf7d More refactoring; allow ConstructorLookup to find constructors in classes.
Swift SVN r2171
2012-06-07 23:57:18 +00:00
Eli Friedman
d969aeea39 Switch everything over to new-style constructors. Change name lookup so it doesn't use old-style constructors for construction anymore.
Swift SVN r2168
2012-06-07 21:04:57 +00:00
Eli Friedman
64d67103fa One more small fix for constructor name lookup. Make the auto-generated element-wise constructor use the name "constructor".
Swift SVN r2165
2012-06-07 19:50:18 +00:00
Eli Friedman
e5b4b924a1 More work on constructors. Basic testcases with "constructor" declarations appear to be working, although there's probably more work to be done. (Both old-style and new-style constructors work for the moment.)
Swift SVN r2163
2012-06-07 01:57:57 +00:00