Commit Graph

48 Commits

Author SHA1 Message Date
Dmitri Hrybenko
3ee34efee4 Code completion: complete declarations that are required for declared protocol
conformances

rdar://16539292

This is a hack in visible decl lookup.  The general solution that would also
improve type checker errors would be to make the type checker keep these broken
conformances and syntethize missing declarations to make downstream code type
check.  For that, see:

<rdar://problem/16723339> [QoI] Type checker should not be dropping protocol
conformances explicitly spelled in the source


Swift SVN r16818
2014-04-25 14:03:39 +00:00
Joe Groff
96c09d7179 Renovate name lookup to prepare for compound name lookup.
Make the name lookup interfaces all take DeclNames instead of identifiers, and update the lookup caches of the various file units to index their members by both compound name and simple name. Serialized modules are keyed by identifiers, so as a transitional hack, do simple name lookup then filter the results by compound name.

Swift SVN r14768
2014-03-07 03:21:29 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Joe Groff
98d6fecc99 '.metatype' -> '.Type'
Also, reserve 'type' as a keyword for ensuing syntax changes.

Swift SVN r14375
2014-02-26 04:23:21 +00:00
Jordan Rose
f5eae17dd2 Move VectorDeclConsumer to swift/AST/NameLookup.h.
This started out life as a helper class, but it's been used in multiple places.
Better to just have a single copy.

No functionality change.

Swift SVN r10835
2013-12-05 01:51:12 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Jordan Rose
ec4234bdbc Perform unqualified lookup using the current SourceFile as context.
And, properly treat imports as per-file: when looking up decls through the
TU module, don't pick up every other source file's imports.

This implements our resolution rules:
1. Check the current source file.
2. Check the current module.
3. Check imported modules.

Currently, "import Foo" is treated as a file-private import and
"@reexported import Foo" is treated as a public /and/ module-wide import.
This further suggests that access control is the right tool for re-export
control:

(private) import Foo // current file only
package import Foo   // whole module
public import Foo    // whole world

Swift SVN r9682
2013-10-25 22:21:12 +00:00
Dmitri Hrybenko
8d8b60f973 Code completion: implement result caching per-imported module across muptiple
ASTContexts

This introduces swift::ide::CodeCompletionCache, which is a persistent code
completion result cache.

Right now REPL happens to use it (try importing Cocoa and doing code
completion), and the difference is noticeable.  But completion in REPL is
still slow, because Cocoa goes through the AST Verifier on every completion
(for unknown reasons).

This commit does not implement cache invalidation yet, and it does not use
libcache to evict cache entries under memory pressure.

This commit also introduces two regressions:
- We get fewer Cocoa results that expected.  Module::isModuleVisible in Clang
does not incorrectly reports that that ObjectiveC.NSObject submodule is not
visible from Cocoa.

- We are not implementing the decl hiding rules correctly.  We used to rely on
visible decl lookup to do it for us, but now we have a different data structure
we have real decls from the current module and we have a text-only cache, so we
are forced to reimplement this part of name lookup in code completion.


Swift SVN r9633
2013-10-24 02:13:34 +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
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
Jordan Rose
6e1ed42c07 s/swift::lookupVisibleDecls/swift::lookupVisibleMemberDecls/g
There were two overloads of lookupVisibleDecls: one that performed
unqualified lookup from a particular decl context, the other performing
qualified lookup into a given type from a particular decl context.
They don't really behave the same, so let's give them different names.

Swift SVN r8641
2013-09-25 20:08:09 +00:00
Dmitri Hrybenko
dedffc69b4 Remove a reference to FuncExpr in a comment
Swift SVN r8324
2013-09-17 02:18:57 +00:00
Dmitri Hrybenko
c4f8e59ca4 Cleanup comments on UnqualifiedLookup (FuncExpr is going away)
Swift SVN r8238
2013-09-14 01:54:12 +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
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Dmitri Hrybenko
bc67a82be8 lookupVisibleDecls(): use correct abstractions of lookup kinds
Removes the boolean IsTypeLookup and OnlyInstanceMembers, which were totally
misleading.

This fixes some bugs in lookupVisibleDecls, which allows us to remove
workarounds in code completion, that were not correct in some corner cases.

Now we also code complete references to instance functions in static contexts,
but code completion results in this case state the type of the resulting object
incorrectly.


Swift SVN r6396
2013-07-19 23:42:54 +00:00
Dmitri Hrybenko
0fc469e80a lookupVisibleDecls(): now we don't find references to generic types outside of
the containing DeclContext

Fixes a few FIXMEs in code completion where we were providing results that
refer to generic arguments outside of their scope.


Swift SVN r6370
2013-07-19 01:46:30 +00:00
Dmitri Hrybenko
e4b44a6bbb Add a 'current module' parameter to lookupVisibleDecls() so that it can do what
is documented: look up members of a type that are visible from a specific
module.  It does not matter much now, but when we have access control, it will.

Before this change, lookupVisibleDecls() tried to guess the *defining* module
of the type, and gave up if it could not.  It forced us to duplicate some
lookup logic for some types (archetypes and protocol compositions).  Also add a
test that lookup finds members of archetype's superclass, which the original
(duplicated) code did not handle.


Swift SVN r6363
2013-07-18 23:32:16 +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
b418fb23bc [Type validation] Lock down on the use of unbound generic types.
By default, reject references to generic types that are not
accompanied by explicitly-provided generic arguments. For those few
places where we can infer the generic arguments (such as the element
type of a new-array expression), opt-in to allowing unbound generic
types. We expect to opt-in more callers over time, but it's better to
reject eagerly because inferring the generic arguments always requires
extra code.

Fixes <rdar://problem/14161142>.



Swift SVN r6016
2013-07-05 20:45:12 +00:00
Doug Gregor
23fbb4288c Rewrite validation of identifier types.
The newer version is slightly more robust about detecting ambiguities
and reporting problems with generic arguments. It also makes direct
use of TypeChecker::lookupMemberType() when resolving member types and
is better situated for further improvements.


Swift SVN r5977
2013-07-03 21:32:59 +00:00
Doug Gregor
a99df7a7b9 [Name lookup] Eliminate MemberLookup in favor of ASTContext::lookup().
Swift SVN r5888
2013-06-28 22:56:15 +00:00
Doug Gregor
187f80cf60 [Name lookup] Introduce ASTContext::lookup() for name lookup into a type.
This lookup routine takes the place of MemberLookup for AST-level
lookups, which don't consider semantics at all and won't be able to
(for example) perform additional type checking to resolve the
lookup. No functionality change.


Swift SVN r5882
2013-06-28 22:08:42 +00:00
Doug Gregor
2994801448 [Name lookup] Eliminate ConstructorLookup, inlining its behavior
This also eliminates some support routines that are no longer needed
with the new member lookup code.


Swift SVN r5878
2013-06-28 20:38:59 +00:00
Doug Gregor
90d0cf0614 [Name lookup] Make MemberLookup stop filtering out static methods when looking into a type.
That one cannot call a static method is a semantic restriction, not a
behavior of name lookup, and name lookup shouldn't play Sema.


Swift SVN r5869
2013-06-28 15:28:39 +00:00
Joe Groff
8693c5efaa SIL: Emit String-to-NSString conversions.
If -nsstring-is-string is enabled, lower Strings in cc(c) and cc(objc) function types to NSString, and when calling them, insert calls to StringToNSString/NSStringToString to perform the bridging conversion.

This isn't quite ready for prime-time yet, because we still need to emit the inverse bridging for ObjC method thunks, and I haven't tested the IRGen end of things yet.

Swift SVN r5355
2013-05-26 20:29:09 +00:00
Doug Gregor
e20338398e Switch visible-declaration lookup to walking extension lists.
No functionality change, but this is a win for performance and
clarity.


Swift SVN r5224
2013-05-20 18:17:25 +00:00
Doug Gregor
87d2a580a6 Use the ArrayBound protocol for type-checking array bounds.
This only applies to the new type checker. The old type checker still
uses the informal protocol.


Swift SVN r5144
2013-05-10 17:46:58 +00:00
Joe Groff
dc28ebb544 REPL: Don't replPrint metatype w/ instance func.
When checking for a replPrint method, make sure it's not an instance method of a metatype; the signature ends up wrong and we emit bizarre error messages. Fixes <rdar://problem/13036012>.

Swift SVN r4204
2013-02-26 00:49:25 +00:00
Joe Groff
ddb7ead55c REPL: Contextual completions.
If the completion prefix has a '.' behind it, guesstimate a context expression by lexing backward through an identifier(.identifier)* dotted path, then attempt to parse and typecheck that expression to decide on a base type in which to find completions.

Swift SVN r4063
2013-02-16 20:07:50 +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
b660580f35 Don't permit calling static methods on an instance <rdar://problem/13206762>.
Swift SVN r4033
2013-02-13 19:27:39 +00:00
Doug Gregor
75c8591487 When lookup finds a generic parameter, treat it like a local declaration, not a member declaration.
Swift SVN r3534
2012-12-18 22:50:49 +00:00
Doug Gregor
71a7408d13 Teach name lookup to remove overridden methods in extensions from its results.
While we haven't worked out the details of whether methods in
extensions can be overridden in Swift, it's something that does happen
in Objective-C, so we need to deal with it.

With this change, note that our demo application can both allocate
Objective-C objects with "new" (which John recently fixed) and also
subscript mutable arrays to both read and write.


Swift SVN r3485
2012-12-13 23:19:37 +00:00
Eli Friedman
bef302d2ee Initial attempt at implementing semantic analysis of overriding for classes.
Still a lot of missing pieces, but it mostly works.



Swift SVN r2633
2012-08-15 01:21:35 +00:00
Eli Friedman
6258942b30 Explicitly specify whether we're performing type lookup to the name lookup code, rather than deducing it from the translation phase.
Swift SVN r2312
2012-07-06 01:06:46 +00:00
Eli Friedman
ab2998431c Simplify our handling of tuple elements in the AST and Sema.
Swift SVN r2224
2012-06-21 21:30:57 +00:00
Doug Gregor
efd92be870 Introduce a form of TypeChecker::buildMemberRefExpr() that accepts the
results of member lookup, and eliminate all uses of
MemberLookup::createResultAST(). The AST library should not be
performing this semantic analysis.


Swift SVN r2221
2012-06-21 17:18:47 +00:00
Doug Gregor
f4bdd9ddf3 Introduce support for using static protocol functions within generics.
Swift SVN r2216
2012-06-20 17:59:03 +00:00
Doug Gregor
f847fe4a22 Introduce basic support for type-checking the definitions of generic
functions. This involves a few steps:

  - When assigning archetypes to type parameters, also walk all of the
  protocols to which the type parameter conforms and assign archetypes
  to each of the associated types.
  - When performing name lookup into an archetype, look into all of
  the protocols to which it conforms. If we find something, it can be
  referenced via the new ArchetypeMemberRefExpr.
  - When type-checking ArchetypeMemberRefExpr, substitute the values
  of the various associated types into the type of the member, so the
  resulting expression involves the archetypes for the enclosing
  generic method.

The rest of the type checking essentially follows from the fact that
archetypes are unique types which (therefore) have no behavior beyond
what is provided via the protocols they conform to. However, there is
still much work to do to ensure that we get the archetypes set up
correctly.



Swift SVN r2201
2012-06-19 21:16:14 +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
72e1bed79e Refactoring for constructor lookup.
Swift SVN r2170
2012-06-07 23:33:08 +00:00
Eli Friedman
89e8b73607 A couple minor tweaks to UnqualifiedLookup.
Swift SVN r2111
2012-06-02 00:54:07 +00:00
Eli Friedman
82755cb06c Add a few comments.
Swift SVN r2110
2012-06-01 23:38:09 +00:00
Eli Friedman
d829b3c775 Unify the complete unqualified lookup logic in the UnqualifiedLookup class.
Swift SVN r2109
2012-06-01 23:26:58 +00:00
Eli Friedman
0e7ef8cebb Start refactoring code towards a single complete implementation of unqualified lookup.
Swift SVN r2108
2012-06-01 01:37:44 +00:00
Eli Friedman
29a13e9ae0 Move the NameLookup class into the AST library.
Swift SVN r2101
2012-05-31 22:35:50 +00:00