Commit Graph

3561 Commits

Author SHA1 Message Date
Slava Pestov
6b7647c0a7 Sema: Don't set type of AssociatedTypeDecl until we have an archetype
Otherwise the verifier can crash because hasType() returns true but
getType() gives us a MetatypeType that hits a null pointer in
desugaring.

The computeType() calls appear in a few too many places for my liking;
would be nice to clean this up further or replace everything with
interface types one day.

Fixes <rdar://problem/19606899>.

Swift SVN r30388
2015-07-19 20:57:18 +00:00
Slava Pestov
78bbcce84a Factor out some code duplication with setting EnumElementDecl types, NFC
Swift SVN r30387
2015-07-19 20:57:15 +00:00
Slava Pestov
e748908990 Sema: Don't set type of TypeAliasDecl until we resolve the alias type
This changes the behavior to match NominalTypeDecls, which don't have a type
until everything is set up either. In a few places we construct TypeAliasDecls
from known types directly, and we have to call computeType().

Fixes <rdar://problem/19534837>.

Swift SVN r30386
2015-07-19 20:55:53 +00:00
Doug Gregor
80ce752197 Provide default _code/_domain for any nominal type conforming to ErrorType.
This allows any type to conform to ErrorType without having to
implement any requirements, so the requirements can remain
underscored. Implements rdar://problem/21867608.

Swift SVN r30342
2015-07-17 23:37:57 +00:00
Jordan Rose
cfe20537d6 Dependencies: Make sure we count redeclaration checking as a dependency.
Also, checking protocol conformances doesn't depend on any members, just the type.
We don't track dependencies on types separately from members right now, though,
so instead there's now a dummy dependency on 'deinit'.

Swift SVN r30288
2015-07-16 23:36:35 +00:00
Xi Ge
1ca854d04f Make Decl::isPrivateStdlibDecl() return true if the decl comes from the SwiftShims module.
rdar://20919984

Swift SVN r30230
2015-07-15 22:43:36 +00:00
Slava Pestov
fd141bead9 Sema: Remove unused inExpression parameter from ASTContext::getBridgedToObjC(), NFC
Progress on <rdar://problem/21215099>.

Swift SVN r29968
2015-07-08 06:49:27 +00:00
Doug Gregor
31787b66ee Generalize the "is being type checked" check to consider the type context.
Fixes 22 crashers.

Swift SVN r29948
2015-07-07 23:38:16 +00:00
Slava Pestov
b03a77f13c Sema: Fix some compiler crashes related to ErrorType handling
- NominalTypeDecl::computeInterfaceType() crash when parent decl
  has error type
- createMaterializeForSetPrototype() crash when parent decl
  has error type
- Crashes in ConformanceChecker when decl has error type

Fixes <rdar://problem/21583601>.

Swift SVN r29912
2015-07-04 01:53:36 +00:00
Doug Gregor
87b4eeccf3 Make same-type requirements prefer to be rooted at outer generic parameters.
All archetypes from outer scopes are fixed (as a lame implementation
restriction), so same-type constraints that involve archetypes from
outer scopres should treat the archetypes from outer scopes as the
representative. Do so, and start eliminating the notion of a "primary"
archetype that was preventing this fix from occurring earlier, so that
"all archetypes" and the set of requirements generated from the
archetype builder still line up.

Fixes rdar://problem/19519590.

Swift SVN r29869
2015-07-02 00:08:24 +00:00
Slava Pestov
ee07ddc2bf Sema: Fix crash calling protocol extension methods returning Self on existential
In r26737, Sema was changed to not wrap Self occurring in a protocol
extension in a DynamicSelf. The commit message was rather terse but
I believe this is because the metadata for Self is bound to the static
base type, not the runtime base type.

However, we still need to substitute Self in the return type for the
static base type in the case where the base is an existential,
otherwise we get an open existential type leaking out.

Also remove the default argument for replaceCovariantResultType(),
every call site passed in a value and it seems bad to omit it on
accident.

Fixes <rdar://problem/21433694>.

Swift SVN r29802
2015-06-30 05:36:00 +00:00
Chris Lattner
cb90745826 fix the bounce-back of rdar://19343997, where a fixit isn't adding a space right.
Swift SVN r29775
2015-06-28 18:50:04 +00:00
Jordan Rose
2f83732a5a Static lets are never mutable.
Also, assert that we're not misusing isSetterAccessibleFrom, which was masking
this issue.

rdar://problem/20193168

Swift SVN r29461
2015-06-17 22:36:02 +00:00
Slava Pestov
9e1f0c3855 Sema: Fix a compiler_crash when the generic signature is invalid
We might still try to call getDeclaredType(), which would
unexpectedly return nullptr.

Swift SVN r29358
2015-06-10 01:18:21 +00:00
Slava Pestov
322f58d8b1 Sema: Tighten up existential vs generic type parameter distinction
Rename existentialConformsToSelf() to existentialTypeSupported(). This
predicate is the "protocol has no Self or associated type requirements"
check, which is a looser condition than self-conformance. This was being
tested to see if the user could refer to the protocol via an existential
type.

The new existentialConformsToSelf() now checks for protocol being @objc,
and for the absence of static methods. This is used as part of the
argument type matching logic in matchType() to determine if the
existential can be bound to a generic type parameter.

The latter condition is stricter, for two reasons:

1) We allow binding existentials to multiple type parameters all sharing
   the same generic type parameter T, so we don't want the user to be
   able to see any static methods on T.
2) There is an IRGen limitation whereby only existentials without witness
   tables can be passed in this manner.

Using the above, the representsNonTrivialGenericParameter() function
has been renamed to canBindGenericParamToExistential(). It now allows
an existential type to be bound to a generic type parameter only under
the following circumstances:

A) If the generic type parameter has no conformances, the match is allowed.

B) If the generic type parameter has at least one conformance, then all
   of the conformances on the generic type parameter must be
   existentialConformsToSelf() (condition 1 above), and all conformances
   on the existential must be @objc (condition 2 above).

Fixes <rdar://problem/18378390> and <rdar://problem/18683843>, and lays
the groundwork for fixing a few other related issues.

Swift SVN r29337
2015-06-07 10:16:21 +00:00
Slava Pestov
ec6b6b586c IRGen: No longer refuses to emit @objc thunks for stuff in generic context
For example, overriding methods in a generic subclass of an @objc
class works.

Swift SVN r29261
2015-06-03 00:01:30 +00:00
Chris Lattner
16b4ad5ce1 Generalize r29106 to handle all of the different kinds of statements that have patterns
in a more robust way.  Also, add testcases for them all.



Swift SVN r29199
2015-06-01 02:52:30 +00:00
Argyrios Kyrtzidis
19933c5b83 [AST] Remove an unnecessary check in Decl::isPrivateStdlibDecl.
Param->hasName() also implies Param->getNameStr() != "_"

Swift SVN r29195
2015-06-01 00:26:44 +00:00
Argyrios Kyrtzidis
658d852f68 [IDE] When printing stdlib interface, hide underscored members of protocols, and subscript
decls that have underscored parameters.

Dmitri verified that the removals after this change are ok.

Swift SVN r29177
2015-05-31 00:41:09 +00:00
Ted Kremenek
aa7f47df9b Revert "IRGen: No longer refuses to emit @objc thunks for stuff in generic context"
Speculatively reverting because the iOS bots are broken.

Swift SVN r29144
2015-05-29 14:11:22 +00:00
Slava Pestov
2eac5bc755 IRGen: No longer refuses to emit @objc thunks for stuff in generic context
For example, overriding methods in a generic subclass of an @objc
class works.

Swift SVN r29139
2015-05-29 06:19:08 +00:00
Doug Gregor
2dc383d4ec Allow constrained extensions to any generic type.
This permits, e.g., extending Array for all Hashable T's. However, it
does not permit extending Array for T == String. Part of
rdar://problem/21142043.

Swift SVN r29107
2015-05-28 18:39:23 +00:00
Doug Gregor
c15b2e246f Revert "Diagnose property ownership mismatches for protocol witnesses/requirements."
This reverts r29097; we might want something more
incomprehensible^Wnuanced here for Objective-C.

Swift SVN r29105
2015-05-28 16:21:26 +00:00
Doug Gregor
1b26e1a581 Diagnose property ownership mismatches for protocol witnesses/requirements.
Swift SVN r29097
2015-05-28 05:31:03 +00:00
Chris Willmore
52d441ba61 Have a bit per PatternBindingEntry saying whether the corresponding
initializer has been type-checked, rather than a bit for the entire
PatternBindingDecl.

<rdar://problem/21057425> Crash while compiling attached test-app.

Swift SVN r29049
2015-05-27 01:31:28 +00:00
Doug Gregor
98314777f2 Allow a protocol extension to define a default implementation for a requirement of its own protocol.
Based on Dave’s hack, this allows one to define a “default implementation” as, e.g.,

  protocol P {
    func foo()
  }

  extension P {
    final func foo() { … }
  }

Swift SVN r28949
2015-05-23 03:40:41 +00:00
Chris Lattner
b0df3ef35e Improve mutability diagnostics for parameters to add a note inserting/changing
a 'var' modifier on the parameter, e.g.:

x.swift:44:5: error: cannot assign to 'let' value 'a'
  a = 1
  ~ ^
x.swift:43:8: note: change 'let' parameter to 'var' to make it mutable
func f(let a : Int) {
       ^~~
       var
x.swift:48:5: error: cannot assign to 'let' value 'b'
  b = 2
  ~ ^
x.swift:47:8: note: mark parameter with 'var' to make it mutable
func g(b : Int) {
       ^
       var

Also fix a bug where we'd incorrectly suggesting adding 'mutating' to a class
method when assigning to self in some cases.



Swift SVN r28926
2015-05-22 19:13:25 +00:00
Doug Gregor
a6300dfdc5 "Properly" compute the depth of Self in ill-formed protocol declarations.
Rather than always using depth 0 for the Self generic type parameter
of a protocol, which is the correct value in well-formed code,
actually compute the depth based on the context. This maintains the
depth invariants of the AST in ill-formed code, resolving a large
number of crashers (169), including rdar://problem/21042357, and
regresses one crasher.

Swift SVN r28920
2015-05-22 16:28:29 +00:00
Doug Gregor
1d277c1c06 Retain the 'self' type and generic signature in overload signatures.
This information keeps declarations in differently-constrained
protocol extensions separate. Fixes rdar://problem/21060743 and
enables the (N+1)st iteration of the default implementations hack.

Swift SVN r28887
2015-05-21 21:32:45 +00:00
Chris Lattner
8853d19c2b Dramatically improve the diagnostics when a store is invalid, by taking
into account accesibility, assignments to self in a non-mutating
method (consistently), recursive components of an lvalue that makes it 
non-settable, etc.  Now we tell you what the *problem* was, instead of
just whining.

This fixes:
<rdar://problem/19370429> QoI: fixit to add "mutating" when assigning to a member of self in a struct
<rdar://problem/17632908> QoI: Modifying struct member in non-mutating function produces difficult to understand error message

in their full generality.



Swift SVN r28867
2015-05-21 05:53:36 +00:00
Chris Lattner
d6ba8666ca various parts of the compiler are doggedly trying to figure out
whether a getter is mutating or a setter is nonmutating, centralize
it into methods on AbstractStorageDecl, NFC.


Swift SVN r28823
2015-05-20 05:00:13 +00:00
Doug Gregor
74050648de Make @objc enums that conform to ErrorType also conform to _ObjectiveCBridgeableErrorType.
This allows @objc enum error types produced in Objective-C (e.g., via
+[NSError errorWithDomain:code:userInfo:]) to be bridged back to their
original enum types in Swift via pattern matching/catch blocks.

This finishes rdar://problem/20577517.

Swift SVN r28803
2015-05-20 00:16:39 +00:00
Doug Gregor
b8ad66eb18 PrintAsObjC: Print property getter/setter names when they differ from the defaults.
We were printing getter/setter names when the property came from
Objective-C initially, which is incorrect: we should print them when
the names differ from what Objective-C would compute by default. This
finishes rdar://problem/19408726, which was mostly in place a while
ago.

Swift SVN r28783
2015-05-19 20:38:48 +00:00
Doug Gregor
def3b0deb8 Append "AndReturnError" rather than "WithError" to initial error parameters.
Swift SVN r28754
2015-05-19 05:53:32 +00:00
David Farler
dbd78643ce Build fix: Adventure triggers nullptr dereference
Fix a nullptr dereference when looking for a base expression
in a member access. Remove use of Optional<T*>, it wasn't providing
any value versus nullptr checking.

Swift SVN r28648
2015-05-15 23:36:33 +00:00
David Farler
80571cf916 Check base expr when determining mutability of a member
When in an initializer, we allow setting into immutable properties
provided that the type of base in `base.member` matches that of that
initializer's containing type. This was an approximation for allowing
full access into `self` during initialization but this doesn't work when
passing in a different struct of the same type because that struct
should be still be immutable.

Check whether the base of the member access is the implicit self
parameter of the initializer before allowing mutation.

rdar://problem/19814302

Swift SVN r28634
2015-05-15 18:48:54 +00:00
Doug Gregor
b4d7680744 Consider constrained protocol extension signatures in overload signatures.
This allows us to overload properties and subscripts with the same
signature in differently-constrained protocol extensions. Previously,
such overloads would be considered to be erroneous redeclarations.

Swift SVN r28610
2015-05-15 04:47:53 +00:00
Ted Kremenek
62feb5c949 Change @availability to @available.
This came out of today's language review meeting.
The intent is to match #available with the attribute
that describes availability.

This is a divergence from Objective-C.

Swift SVN r28484
2015-05-12 20:06:13 +00:00
Slava Pestov
aa856fc263 Don't allow overloading on @noreturn, @noescape of function parameters
Overloading on the function parameter being 'throws' is still permitted.

Note that the explicit check for overloading on the 'throws' of the
_declaration itself_ was dead code. We were already stripping out the
ExtInfo from the top level function type when building the
OverloadSignature's InterfaceType.

Fixes <rdar://problem/19816831>.

Swift SVN r28482
2015-05-12 18:19:38 +00:00
Doug Gregor
340e4d8f8a Simplify parsing and representation of extension declarations.
Now that we don't have generic parameter lists at arbitrary positions
within the extended type of an extension declaration, simplify the
representation of the extended type down to a TypeLoc along with a
(compiler-synthesized) generic parameter list.

On the parsing side, just parse a type for the extended type, rather
than having a special grammar. We still reject anything that is not a
nominal type (of course), but it's simpler just to call it a type.

As a drive-by, fix the crasher when extending a type with module
qualification, rdar://problem/20900870.

Swift SVN r28469
2015-05-12 16:26:13 +00:00
Argyrios Kyrtzidis
f000fcd383 [IDE] For header interface printing, include macros and module imports.
Swift SVN r28413
2015-05-11 06:48:28 +00:00
Ted Kremenek
9f9bb725cf Rename '_ErrorType' to 'ErrorType'.
Swift SVN r28293
2015-05-07 21:59:29 +00:00
Doug Gregor
2653a6569b Eliminate ModuleExpr; DeclRefExpr is good enough for anyone.
Swift SVN r28285
2015-05-07 21:10:53 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Joe Groff
e7547adabd AST: Initial work to canonicalize generic signatures for mangling.
Currently GenericSignature::getCanonicalSignature isn't able to canonicalize the set of requirements due to fragile dependencies on generic signatures matching AllArchetypes order of their originating GenericParamLists. However, we shouldn't let that stop us from getting the mangling right, so implement a "getCanonicalManglingSignature" that builds the true canonical signature by feeding it into an ArchetypeBuilder and shedding unnecessary constraints. For now, just handle conformance and base class constraints; still to do are same-type constraints.

Swift SVN r28191
2015-05-06 01:29:15 +00:00
Chris Lattner
7927a230ae remove compiler support for let/else. This simplifies PBD back to being
an unconditional binding, yay.


Swift SVN r28101
2015-05-03 22:13:02 +00:00
Doug Gregor
46f760abfb Teach ProtocolDecl not to depend on getProtocols().
Remove a stale API in the process; NFC, part of rdar://problem/18448811.

Swift SVN r27971
2015-04-30 16:13:40 +00:00
Doug Gregor
cf1bb3a8ce Remove the old "delayed protocol conformances" code.
It's in the way of progress; a better solution is coming.

Swift SVN r27970
2015-04-30 16:13:39 +00:00
Doug Gregor
d0282e0d62 Switch the AST printer over to getLocalProtocols().
Swift SVN r27968
2015-04-30 16:13:37 +00:00
Doug Gregor
8a8895de75 Populate the conformance lookup table for a deserialized protocol.
When deserializing a protocol, the conformance lookup table would not
contain entries for the inherited protocols of that protocol. They
were stashed in the "Protocols" array in TypeDecl (which will
eventually go away), but since there are no conformances for a
protocol, the conformance lookup table never got updated.

Nothing important seems to query this now; that will change soon.

Swift SVN r27967
2015-04-30 16:13:35 +00:00