Commit Graph

1018 Commits

Author SHA1 Message Date
Slava Pestov
1657060d1e AST: hasType() => hasInterfaceType() 2016-11-29 03:05:30 -07:00
Slava Pestov
09980dd3c1 AST: getType() => getInterfaceType() 2016-11-29 03:05:26 -07:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
c7089ff000 Sema: Add support for extensions of nested generic types 2016-11-03 22:20:30 -07:00
Graydon Hoare
c4e8c52d67 s/isUnavailableInCurrentSwift/isUnavailableInSwiftVersion/, pass version. 2016-10-12 11:20:42 -07:00
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Jordan Rose
3170c65c3d Merge pull request #4925 from jrose-apple/ignore-access-when-you-find-nothing
Add "IgnoreAccessControl" to UnqualifiedLookup.

rdar://problem/27663403
2016-09-23 11:04:56 -07:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
Jordan Rose
9eaaf5d3b8 Add "IgnoreAccessControl" to UnqualifiedLookup.
...and use it when top-level type lookup fails, to produce better
diagnostics.

Really this should be using an option set, or setting flags on the
UnqualifiedLookup instance or something, but I want to cherry-pick
this to the swift-3.0-branch without major disturbances.

More rdar://problem/27663403
2016-09-22 15:09:27 -07:00
Doug Gregor
8ab9989c5f [Name lookup] Remove NL_VisitSupertypes.
Name lookup into a class type always looks into its supertypes; if you
want to look directly into a particular class and its extensions, use
lookupDirect and filter.
2016-09-19 21:19:55 -07:00
practicalswift
b19481f887 [gardening] Fix 67 recently introduced typos 2016-09-16 11:16:07 +02:00
Doug Gregor
ae9c29036a [Scope map] Local types and functions are visible in the enclosing braces.
As in non-local scopes, local types and functions are generally
visible anywhere within enclosing braces, and it is up to capture
analysis to determine whether these entities attempt to capture an
entity that isn't guaranteed to be available.
2016-09-15 15:55:26 -07:00
Doug Gregor
e0893457fb [Scope map] Hack around AST issue involving ill-formed associated types.
DeclContext::getSelfTypeInContext() returns null types in some cases
of broken protocols. Hack around this in the ASTScope-based
unqualified name lookup code for now, with a narrower hack than what
the existing unqualified name lookup is doing (which is even *less*
principled).
2016-09-15 09:16:46 -07:00
Doug Gregor
b0470cf0e2 [Scope map] Disable ASTScope-based name lookup in source files in REPL mode.
The integrated REPL does very funny things with source locations in
source files, because it uses new buffers for each bit of code it
parses, breaking all of the invariants of a source-based data
structure like ASTScope.
2016-09-15 09:16:46 -07:00
Doug Gregor
909de5bd16 [Scope map] Type and abstract function declaration scopes can be continuations.
Rather than trying to specifically model local declarations of
functions and types with a "local declaration" scope, which we
introduced when we saw one of these entities with a local DeclContext,
use a more consistency scheme where:

  1) we always describe a type declaration with a TypeDecl scope and an
  (abstract) function declaration with an AbstractFunctionDecl scope,
  and
  2) either of those scopes can steal the continuation from their
  parent;

This modeling is another step toward supporting top-level code.
2016-09-12 11:35:57 -07:00
Doug Gregor
9821fd519a [Name lookup] getSelfTypeInContext() subsumes getDeclaredTypeInContext(). NFC
Thanks, Slava!
2016-09-09 17:08:42 -07:00
Doug Gregor
eefea8fae0 [Scope map] Handle unqualified name lookup into protocols and protocol extensions properly.
We need to use the 'Self' type, not the nominal type itself.
2016-09-08 14:27:03 -07:00
Doug Gregor
67bf68ae70 [Name lookup] Support lookup of 'self' in lazy property initializers.
Lazy property initializers can refer to 'self' either directly or
implicitly (via references to instance members). Model this in
ASTScope-based unqualified name lookup.

Note that the modeling of 'self' with the current name lookup
mechanism is broken, so when ASTScope-based unqualified name lookup is
enabled, it fixes SR-2203, rdar://problem/16954496, and the many dupes
of the latter.
2016-09-08 11:24:03 -07:00
Doug Gregor
abf9bfe9d5 [Scope map] Provide scopes for the generic parameters of protocols and extensions. 2016-09-07 16:44:36 -07:00
Doug Gregor
ead78e046f [Scope map] Explicitly model the scope of a function body.
For methods/initializers/deinitializers, modeling the scope of a
function body allows us to correctly introduce instance member lookup
relative to 'self'. Do so so that we can resolve unqualified name
lookup within methods based on the implicit 'self'.
2016-09-06 22:58:18 -07:00
Doug Gregor
2552f41556 [Name lookup] Add a staging flag for ASTScope-based name lookup. 2016-09-06 09:05:11 -07:00
Doug Gregor
68c3f3b1b3 Remove EnableSwift3Private staging option. 2016-08-19 21:53:32 -07:00
Jordan Rose
cd7c802972 Lookup using private discriminators should still find public things. (#4238)
Private and fileprivate declarations have a special "private
discriminator" to keep them from colliding with declarations with the
same signature in another file. The debugger uses this to prefer
declarations in the file you're currently stopped in when running the
expression parser. Unfortunately, the current logic didn't just prefer
declarations in the current file---it /only/ took declarations in the
current file, as long as there weren't zero. The fixed version will
include any declarations in the current file plus any declarations
with 'internal' or broader access.

(Really we shouldn't do this at the lookup level at all; it should
just be a tie-breaker in solution ranking in the constraint
solver. But that would be a more intrusive change.)

rdar://problem/27015195
2016-08-12 09:38:37 -07:00
Slava Pestov
3ebd53d03c AST: Name lookup shouldn't filter out static/instance methods from instance/static context
We do this in a more general way higher up in the constraint
solver. Filtering out methods in name lookup only hurts
diagnostics.

In fact I don't think this behavior was intentional at all,
since the code in question was originally written in 2013
before a lot of the more recent member lookup and diagnostic
code was added.

This does break source compatibility though, but in a minor
way. See the change to the CoreGraphics overlay. Again,
though, I think this was an accident and not intentional.
2016-08-05 14:27:16 -07:00
Mark Lacey
c9ec7e398b Fix crash during type checking when adding members to an extension.
If the extension ended up with ErrorType, we could crash while we
continue trying to process its body adding members.

Just bail out in this case.

rdar://problem/27671033
2016-08-03 22:55:33 -07:00
John McCall
afdda3d107 Implement SE-0117.
One minor revision: this lifts the proposed restriction against
overriding a non-open method with an open one.  On reflection,
that was inconsistent with the existing rule permitting non-public
methods to be overridden with public ones.  The restriction on
subclassing a non-open class with an open class remains, and is
in fact consistent with the existing access rule.
2016-08-02 07:46:38 -07:00
Chris Lattner
156b9bb394 fix a crash on invalid caught by the validation tests. 2016-07-31 19:28:05 -07:00
Chris Lattner
06ee8ef03e fix <rdar://problem/21677702> Static method reference in static var doesn't work 2016-07-31 17:17:39 -07:00
Jordan Rose
6dea23a029 Flip the switch on 'private' and 'fileprivate' (SE-0025).
More tests to come soon. In particular, validation of members used in
protocol conformances is still not correct.
2016-07-28 09:55:23 -07:00
Jordan Rose
508e825ff2 Split 'fileprivate' and 'private', but give them the same behavior.
'fileprivate' is considered a broader level of access than 'private',
but for now both of them are still available to the entire file. This
is intended as a migration aid.

One interesting fallout of the "access scope" model described in
758cf64 is that something declared 'private' at file scope is actually
treated as 'fileprivate' for diagnostic purposes. This is something
we can fix later, once the full model is in place. (It's not really
/wrong/ in that they have identical behavior, but diagnostics still
shouldn't refer to a type explicitly declared 'private' as
'fileprivate'.)

As a note, ValueDecl::getEffectiveAccess will always return 'FilePrivate'
rather than 'Private'; for purposes of optimization and code generation,
we should never try to distinguish these two cases.

This should have essentially no effect on code that's /not/ using
'fileprivate' other than altered diagnostics.

Progress on SE-0025 ('fileprivate' and 'private')
2016-07-25 13:13:35 -07:00
Alex Hoppen
095a68b195 [Sema] Disallow accessing enum elements as instance members
This implements SE-0036.
2016-07-20 19:13:58 +02:00
Alex Hoppen
232fe59b54 [Sema] Don't issue warnings when accessing enum elements as instance members
This removes the logic which issued warnings when accessing enum
elements as instance members (SE-0036), making room for a new
implementation that will issue errors instead.

This reverts commit ae1058a39a.
2016-07-20 16:25:57 +02:00
Doug Gregor
abf73d3bee [Name lookup] Use the overload signature's type for shadowing of var/subscript decls.
For historical reasons, the "name shadowing" computation is only
looking at the type---not even the interface type!---of
declarations. For variables and subscripts, this means that the
context (e.g., a constrained extension) wasn't been considered at all,
leading to declarations from other imported modules being
ignored. Patch up a little bit of this by using the overload
signature's type for variables and subscripts, because I need it for
ErrorProtocol's default implementations.

Longer-term, we should be using the overload signature (or something
very like it) for shadowing, consistently.
2016-07-12 10:53:52 -07:00
Alex Hoppen
ae1058a39a [Sema] Provide warnings when accessing enum elements as instance members as a preparation for SE-0036 2016-07-08 11:17:46 +02:00
Slava Pestov
409af27eb3 Sema: Use DeclContext::getSelfInterfaceType() and DeclContext::getSelfTypeInContext() more, NFC
There are many places where we do the 'if inside a protocol, get the
Self type parameter, otherwise, use the declared type' dance.
We actually have really handy utility methods that encapsulate this,
so let's use them more.
2016-07-02 05:35:15 -07:00
Slava Pestov
7814c47b71 AST: Slightly change meaning of NominalTypeDecl::getDeclaredType()
Consider this code:

struct A<T> {
  struct B {}
  struct C<U> {}
}

Previously:

- getDeclaredType() of 'A.B' would give 'A<T>.B'
- getDeclaredTypeInContext() of 'A.B' would give 'A<T>.B'

- getDeclaredType() of 'A.C' would give 'A<T>.C'
- getDeclaredTypeInContext() of 'A.C' would give 'A<T>.C<U>'

This was causing problems for nested generics. Now, with this change,

- getDeclaredType() of 'A.B' gives 'A.B' (*)
- getDeclaredTypeInContext() of 'A.B' gives 'A<T>.B'
- getDeclaredType() of 'A.C' gives 'A.C' (*)
- getDeclaredTypeInContext() of 'A.C' gives 'A<T>.C<U>'

(Differences marked with (*)).

Also, this change makes these accessors fully lazy. Previously,
only getDeclaredTypeInContext() and getDeclaredIterfaceType()
were lazy, whereas getDeclaredType() was built from validateDecl().

Fix a few spots where the return value wasn't being checked
properly.

These functions return ErrorType if a circularity was detected via
the generic parameter list, or if the extension did not resolve.
They return Type() if the extension cannot be resolved *yet*.

This is pretty subtle, and I'll need to do another pass over
callers of these functions at some point. Many of them should be
moved over to use getSelfInContext(), getSelfOfContext() and
getSelfInterfaceType() instead.

Finally, this patch consolidates logic for diagnosting invalid
nesting of types.

The parser had some code for protocols in bad places and bad things
inside protocols, and Sema had several different bail-outs for
bad things in protocols, nested generic types, and stuff nested
inside protocol extensions.

Combine all of these into a single set of checks in Sema. Note
that we no longer give up early if we find invalid nesting.
Leaving decls unvalidated and un-type-checked only leads to
further problems. Now that all the preliminary crap has been
fixed, we can go ahead and start validating these funny nested
decls, actually fixing some crashers in the process.
2016-06-18 17:15:24 -07:00
Slava Pestov
697652414e Sema: Tighten some screws now that NL_OnlyTypes is in place
This ruins a diagnostic when a local variable shadows a type, but I think
the other reliability improvements that fell out of these changes are
worth it. If we want to bring the diagnostic back, there are better ways
of doing it than the old, somewhat duplicated approach.
2016-06-18 17:05:27 -07:00
Slava Pestov
3127264376 AST: When performing qualified lookup of a member type, filter out non-types earlier
With the previous resolveTypeInContext() patch, a few compiler
crashers regressed with this problem, presumably because we were now
performing lookups in more contexts than before.

This is a class of problems where we would attempt a recursive
validation:

1) Generic signature validation begins for type T
2) Name lookup in type context finds a non-type declaration D nested in T
3) Generic signature validation begins for D
4) The outer generic context of D is T, but T doesn't have a generic
   signature yet

The right way to break such cycles is to implement the iterative
decl checker design. However when the recursion is via name lookup,
we can try to avoid the problem in the first place by not validating
non-type declarations if the client requested a type-only lookup.

Note that there is a small semantic change here, where programs that
were previously rejected as invalid because of name clashes are
now valid. It is arguable if we want to allow stuff like this or not:

class A {
  func A(a: A) {}
}

or

class Case {}
enum Foo {
  case Case(Case)
}

However at the very least, the new behavior is better because it
gives us an opportunity to add a diagnostic in the right place
later. The old diagnostics were not very good, for example the
second example just yields "use of undeclared type 'Case'".
In other examples, the undeclared type diagnostic would come up
multiple times, or we would generate a cryptic "type 'A' used within
its own definition".

As far as I understand, this should not change behavior of any existing
valid code.
2016-06-11 16:27:43 -07:00
Jordan Rose
b443fa5416 Avoid warning about an exhaustive switch over an option set. NFC. 2016-05-24 18:34:01 -07:00
Doug Gregor
684e8a5ca6 [Name lookup] Don't allow unavailable-in-current-Swift declarations to shadow available ones.
The unavailable-in-current-Swift declarations introduced by the Clang
importer to help with migrating Swift 2.x code to Swift 3's naming
cause problems with unqualified name lookup when they shadow, e.g.,
types. The biggest problem in practice is with "URL", which is a
common Cocoa property name (in Swift 2) that becomes "url" in Swift 3,
but the old name conflicts with the Foundation value type "URL".

Fixes <rdar://problem/26236989>.
2016-05-19 10:08:08 -07:00
John McCall
8f44e70b21 Stop passing around these flags as an unsigned. 2016-05-17 15:26:26 -07:00
Ted Kremenek
942e524285 Revert "SE-0036: Requiring Leading Dot Prefixes for Enum Instance Member Implementations" (#2477) 2016-05-11 11:02:37 -07:00
Alex Hoppen
0e8c69c56f [SE-0036]: Requiring Leading Dot Prefixes for Enum Instance Member Implementations 2016-05-07 22:39:26 +02:00
Doug Gregor
c3197631ff [Name lookup] Filter declarations found via dynamic lookup based on accessibility. 2016-04-06 16:14:43 -07:00
Slava Pestov
552a6ad1b7 Sema: Remove some dead code for "delayed members", NFC
This was added at some point to make 'import Foundation' faster in the REPL.
What we really care about though is not delaying synthesis of the rawValue
accessors (those are synthesized on demand anyway), but delaying the
conformance check to RawRepresentable.
2016-03-16 18:35:31 -07:00
Daniel Duan
efe230774b [AST] rename some isXXX methods to getAsXXX
There's a group of methods in `DeclContext` with names that start with *is*,
such as `isClassOrClassExtensionContext()`. These names suggests a boolean
return value, while the methods actually return a type declaration. This
patch replaces the *is* prefix with *getAs* to better reflect their interface.
2016-02-11 16:23:40 -08:00
Doug Gregor
9a0241bb3b SE-0022: Address Jordan's review comments about #selector. 2016-01-28 12:09:57 -08:00
Doug Gregor
1a830fa541 SE-0022: Deprecate string-literal-as-selector in favor of #selector.
Introduce Fix-Its to aid migration from selectors spelled as string
literals ("foo:bar:", which is deprecated), as well as from
construction of Selector instances from string literals
(Selector("foo:bar"), which is still acceptable but not recommended),
to the #selector syntax. Jump through some hoops to disambiguate
method references if there are overloads:

    fixits.swift:51:7: warning: use of string literal for Objective-C
         selectors is deprecated; use '#selector' instead
      _ = "overloadedWithInt:" as Selector
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          #selector(Bar.overloaded(_:) as (Bar) -> (Int) -> ())

In the cases where we cannot provide a Fix-It to a #selector
expression, we wrap the string literal in a Selector(...) construction
to suppress the deprecation warning. These are also easily searchable
in the code base.

This also means we're doing more validation of the string literals
that go into Selector, i.e., that they are well-formed selectors and
that we know about some method that is @objc and has that
selector. We'll warn if either is untrue.
2016-01-28 10:58:27 -08:00
Chris Lattner
8654282bee fix 28239-swift-declcontext-lookupqualified.swift, module lookup can be done
without access control now by diagnostics.
2016-01-25 22:08:43 -08:00
Chris Lattner
c11cbfb88c Merge pull request #827 from practicalswift/circular-class-inheritance
[swiftc] Add assertion: Avoid endless loop in case of circular class inheritance
2016-01-01 11:17:45 -08:00