Commit Graph

66 Commits

Author SHA1 Message Date
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
db13bcb22e Fix typos. 2015-12-26 14:11:42 +01:00
Ted Kremenek
953ad5350b Revert "Revert "Unify FindLocalVal across UnqualifiedLookup and lookupVisibleDecls.""
This reverts commit r30528.

This is not the source of our project regressions.

Swift SVN r30537
2015-07-23 15:01:15 +00:00
Ted Kremenek
685f2e3800 Revert "Unify FindLocalVal across UnqualifiedLookup and lookupVisibleDecls."
This reverts commit r30525.

This appears likely to be causing build regressions with guard statements on our test projects.

Swift SVN r30528
2015-07-23 05:39:20 +00:00
Jordan Rose
8a2e338e5a Unify FindLocalVal across UnqualifiedLookup and lookupVisibleDecls.
They had already diverged even before my last commit. Let's not have that
happen again!

This re-fixes code completion for bindings declared in top-level guard
statements.

More rdar://problem/21928533

Swift SVN r30525
2015-07-23 04:42:09 +00:00
Slava Pestov
6992dfc5d1 AST: Start unifying UnqualifiedLookup and lookupVisibleDecl()
For now, just update NameLookup's FindLocalVal to use a
VisibleDeclConsumer just like lookupVisibleDecl().

A subsequent patch will continue removing duplicated code
now that this is place.

This fixes compiler crashers where we were not handling
declarations with duplicate names (which of course is an
error, diagnosed elsewhere).

Swift SVN r29913
2015-07-04 01:53:38 +00:00
Doug Gregor
ca29fd9ea3 Start cleaning up member name lookup.
Fold the witness-mapping code and deduplication logic into the main
lookup path, so we don't end up performing redundant lookups. Delay
the removal of overridden and shadowed declarations until after we've
done witness mapping, so we're not wasting effort the first time
around. NFC except for a small performance optimization.

Swift SVN r29060
2015-05-27 05:51:43 +00:00
Doug Gregor
0749486302 Let unqualified lookup find members of protocols and extensions thereof.
Members of protocols found via unqualified name lookup are mapped to
their corresponding witnesses, as we do for qualified name
lookup. This is the bulk of the compiler changes for
rdar://problem/20509152. Performing this mapping for unqualified name
lookup of types will follow.

Swift SVN r28333
2015-05-08 23:22:13 +00:00
Doug Gregor
5c2d1232ee Stop classifying results in UnqualifiedLookupResult.
We're still doing too much work to form these unqualified lookup
results that should really move into semantic analysis, but this is
the NFC part we need now.

Swift SVN r28331
2015-05-08 23:22:05 +00:00
Doug Gregor
edbb75eef8 Eliminate the 'Module' variant from UnqualifiedLookupResult.
Make unqualified lookup always provide a declaration for the things it
finds, rather than providing either a module or a declaration. Unify
various code paths in our type checker now that module declarations
come in with the other declarations.

Swift SVN r28286
2015-05-07 21:10:55 +00:00
Jordan Rose
35f5c885cb The lookup context for lookupInModule and lookupVisibleDeclsInModule is required.
This determines whether or not testable declarations are visible.

Part of rdar://problem/17732115

Swift SVN r26845
2015-04-02 02:57:39 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Jordan Rose
51b273b113 Add a flag to UnqualifiedLookup to say that a lookup is known-private.
...and thus does not affect downstream files...

...and adopt it in several places:
- when looking up the default type for a literal (test included)
- when looking up the first component in an IdentTypeRepr (test included)
- when deciding which ~= to use in a switch (test forthcoming)
- when a protocol has an operator function requirement (test forthcoming)
- when validating @NSApplicationMain and @UIApplicationMain
- when an enum element shows up unqualified in a switch
- several places where it doesn't matter because we're looking something up
  in the standard library.

Part of rdar://problem/15353101

Swift SVN r23670
2014-12-04 00:35:08 +00:00
Jordan Rose
5c8803a5c4 Remove the last uses of UnqualifiedLookup::forModuleAndName.
This API didn't take accessibility into account in a useful way, and
usually did a more general search than what was actually needed. We've
gradually been replacing uses of it with either more safe or more direct
APIs, including a regular UnqualifiedLookup, DeclContext::lookupQualified,
or Module::lookupValue. Now it's gone.

No functionality change.

Swift SVN r23449
2014-11-19 22:28:32 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
67536dbb8a Respect access control in visible decl lookup (and code completion).
<rdar://problem/17648922>

Swift SVN r19963
2014-07-14 23:02:41 +00:00
Jordan Rose
5b80dc3d44 Respect accessibility for scoped imports.
"import var Foo.bar" should error if "Foo.bar" is not public.

Swift SVN r19747
2014-07-09 22:10:20 +00:00
Jordan Rose
a7b563855e Add a mode in which access control is respected for module-scope lookups.
This applies to both qualified and unqualified lookups, and is controlled
by the -enable-access-control and -disable-access-control flags. I've
included both so that -disable-access-control can be put into specific tests
that will eventually need to bypass access control (e.g. stdlib unit tests).
The default is still -disable-access-control.

Swift SVN r19146
2014-06-24 21:32:21 +00:00
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