Commit Graph

1081 Commits

Author SHA1 Message Date
Doug Gregor
63504e4099 [GSB] Recognize self-derived protocol requirements within a protocol.
When computing the requirement signature of a protocol, eliminate requirement
sources that are self-derived by virtual of using a given requirement of
that protocol to prove that same constraint.
2017-09-18 16:40:03 -07:00
Mohammed M. Ennabah
81ab8a302d changed diagnostics argument name to argument label SR-5857 (#11894)
* changed diagnostics argument name to argument label SR-5857
2017-09-13 19:07:19 -07:00
swift-ci
8c65f6e785 Merge pull request #11751 from DougGregor/gsb-nested-same-type-match 2017-09-12 07:20:33 -07:00
Doug Gregor
1e21d8df8a [GSB] Eliminate self-derived nested-type-name-match constraints..
Nested-type-name-match constraints are odd because they are
effectively artifacts of the GenericSignatureBuilder's algorithm,
i.e., they occur when we have two PotentialArchetypes representing the
same type, and each of those PA's has a nested type based on the same
associated type. Because of this, nested-type-name-match constraints
have no useful requirement sources, so the normal means of detecting
self-derived constraints doesn't suffice, and we end up with
self-derived nested-type-name-match constraints eliminating the
constraints they depend on, causing spurious "redundant same-type
constraint" diagnostics and minimized generic signatures that drop
important requirements.

Handle nested-type-name-match constraints by first keeping them out of
the connected-components algorithm used to compute same-type
constraints within an equivalence class. Then, detect self-derived
nested-type-name-match constraints by determining whether any of the
ancestor potential archetypes are in the same equivalence class... and
redundant with the edge that makes the ancestor potential archetypes
equivalent. Remove such self-derived edges, and treat all other
nested-type-name-match edges as derived, providing a minimized
signature.

Fixes SR-5841, SR-5601, and SR-5610
2017-09-12 06:11:53 -07:00
Itai Ferber
f90827e17b Codable: excluded vars shouldn’t need explicit val
Properties of Codable types which are optional and excluded via the CodingKeys enum should not require an explicit nil assignment, since in all other cases, optional vars get a default value of nil.
2017-09-11 10:29:07 -07:00
John McCall
2d3d6addc0 Delay the validaton of storage accessors until finalization.
The base mutability of storage is part of the signature, so be sure
to compute that during validation.  Also, serialize it as part of
the storage declaration, and fix some places that synthesize
declarations to set it correctly.
2017-09-10 04:56:02 -04:00
Ewa Matejska
21b2073b9e Small update to diagnostics to avoid the word yet 2017-09-07 10:34:34 -07:00
Slava Pestov
19fed22872 Parse: Remove redundant diagnostic
We had two slightly different codepaths to diagnose ': class'
in an inheritance clause where it is not supported.

For generic parameters, we would fix the 'class' to 'AnyObject',
but for associated types we didn't do this. Perform the fix in
all cases where it makes sense and remove one of the two
diagnostics.
2017-09-05 21:53:52 -07:00
Slava Pestov
4468d54ac7 Sema: Diagnose '@objc' protocols containing associated types
Fixes <https://bugs.swift.org/browse/SR-3850>,
<rdar://problem/32634928>.
2017-09-04 21:21:08 -05:00
Slava Pestov
50e7c066f7 Parse: Simpler handling of 'class' in protocol inheritance list
Instead of treating this as its own thing, just parse it as if
the user wrote 'AnyObject'.
2017-09-04 17:52:34 -05:00
Toni Suter
b825cdce4f [Parse] [SR-5674] Add fix-it for computed 'let' declaration (#11527) 2017-08-20 13:38:50 +09:00
Slava Pestov
ef87a5bbfb Sema: Fix crash with invalid 'let' property in protocol
Fixes <rdar://problem/25185722>.
2017-08-16 18:17:38 -04:00
David Zarzycki
f0b1924a19 [Diags QoI] Avoid premature return in checkOwnershipAttr()
This also removes some dead code, where an early assert() ensures that
'strong' is never passed into the function, but then the function later
tries to handle 'strong'.

Finally, use a switch statement for future proofing.
2017-08-09 13:13:36 -04:00
swift-ci
17ddc5802f Merge pull request #10965 from ahoppen/deinit-special-name 2017-08-01 07:50:00 -07:00
Slava Pestov
eb46696baa AST: Fix bogus diagnostic with bad conformance requirements in generic signature
Fixes <rdar://problem/33604221>.
2017-07-31 14:19:19 -07:00
Alex Hoppen
ebd701c4b7 Represent the name of destructors by a special DeclBaseName
No longer use the known identifier `deinit` for destructors. This allows
classes to have functions called `deinit`.
2017-07-28 19:20:02 +02:00
Doug Gregor
a12ec12d6f Merge pull request #11234 from DougGregor/sr-5473
[GSB] Detect self-derived conformances within same-type requirements
2017-07-27 16:17:44 -07:00
swift-ci
18c8dc58ab Merge pull request #11223 from xedin/rdar-33477726 2017-07-27 15:47:11 -07:00
Pavel Yaskevich
242006706e [QoI] Improve diagnostics of unsatisfied generic requirements
Fixes a problem related to presence of InOutType in function parameters
which diagnostics related to generic parameter requirements didn't handle
correctly, and improves diagnostics for unsatisfied generic requirements
in operator applications, which we didn't attempt to diagnose at all.

Resolves: rdar://problem/33477726
2017-07-27 15:06:12 -07:00
Doug Gregor
ed87c343bd [GSB] Detect self-derived conformances within same-type requirement sources.
Detect requirement sources that are internally self-derived for
(e.g.) handling of requirement sources for same-type constraints and
superclass constraints. This eliminates some incorrect warnings about
redundant same-type constraints involving recursive protocols, which
(more importantly) were a symptom of incorrect generic signature
minimization.

Fixes SR-5473.
2017-07-27 15:02:33 -07:00
Doug Gregor
d589cb720f [GSB] Retain minimal conformance sources within self-derived sources.
More correctly fix SR-5485: we were retaining self-derived conformance
sources when we shouldn't, which led to spurious "redundant
conformance" diagnostics and (much worse) incorrect minimized generic
signatures. Now, when we detect a self-derived conformance source,
return the minimal source that will derive the same conformance... and
retain that one if it's new.
2017-07-27 11:06:48 -07:00
Doug Gregor
469e9e08a5 SE-0157: Enable recursive protocol constraints by default.
We don't know if they work in general, but specific cases of recursive
protocol constraints are working, and enabling them doesn't break
anything.
2017-07-26 20:57:24 -07:00
swift-ci
ef1a96df42 Merge pull request #11174 from DougGregor/reprocess-delayed-requirements 2017-07-25 17:32:48 -07:00
Doug Gregor
0a7b977597 [GSB] "Self: P" in requirement signatures aren't self-derived.
When determining whether a conformance requirement source is
self-derived, ignore the top-level "Self: P" requirement in a
requirement signature.

Fixes SR-5485 / rdar://problem/33360699.
2017-07-25 15:02:51 -07:00
Doug Gregor
6177f83f01 [GSB] SE-0157: Reprocess delayed requirements when we need a complete PA.
Whenever we need a complete, well-formed potential archetype,
reprocess any delayed requirements, so that we pick up additional
requirements on that potential archetype.

This relies on us tracking a generation count for the GSB instance as
a whole, which gets bumped each time we add some new requirement or
create a new potential archetype, and only actually reprocessing
delayed requirements when the generation count exceeds the point at
which we last processed delayed requirements.

This gets the most basic recursive protocol constraint working
end-to-end and doesn't seem to break things.
2017-07-25 12:56:50 -07:00
Doug Gregor
f23ee2341e Merge pull request #11158 from DougGregor/jsexport-redundant-inheritance
[GSB/IRGen] Allow redundant inheritance of the JSExport protocol.
2017-07-25 02:17:18 -04:00
Doug Gregor
1b2a2c9b90 [GSB/IRGen] Allow redundant inheritance of the JSExport protocol.
Inheritance of a protocol from JavaScriptCore's JSExport protocol is
used to indicate that the methods and properties of that protocol
should be exported to JavaScript. The actual check to determine
whether a protocol (directly) inherits JSExport is performed via the
Objective-C runtime. Note that the presence of JSExport in the
protocol hierarchy is not sufficient; the protocol must directly
inherit JSExport.

Swift warns about redundant conformance requirements and eliminates
them from the requirement signature (and, therefore, the Objective-C
metadata). This behavior is incorrect for JSExport, because the
conformance is actually needed for this API to work properly.

Recognize a protocol's inheritance JSExport specifically (by
name) when computing the requirement signature of the protocol. When
we find such a redundancy, suppress the "redundant conformance
constraint" diagnostic and add a new (hidden) attribute
@_restatedObjCConformance(proto). The attribute is used only by Objective-C
protocol metadata emission to ensure that we get the expected metadata
in the Objective-C runtime.

Fixes rdar://problem/32674145.
2017-07-24 17:02:34 -07:00
Itai Ferber
4c366d8efe Merge pull request #11045 from itaiferber/codable-class-fixes
Codable Class Fixes
2017-07-24 15:42:45 -07:00
Itai Ferber
071caf263a Additional responses to feedback
* Make Decodable synthesis lazy again
* Remove side effects from assertions
* Assert on superclass failable initializers (and verify via a unit test)
* Fix space typo
* Remove more needless instances of single-element arrays
* Unambiguously refer to init() in unit tests
* Add failable superclass init tests and a test to ensure Decodable fails to be inherited when superclass synthesis fails
* Add tests for structs to ensure they receive no-argument initializers where appropriate
2017-07-24 08:02:19 -07:00
Robert Widmann
28537d9d75 Push __shared through Sema
* Update usage checking to account for __shared parameters as immutable

* Allow pattern type checking to resolve Shared parameters to the appropriate parameter specifiers

* Add the __shared protocol requirement restriction
2017-07-23 21:47:25 -07:00
Itai Ferber
a30e9117e6 Responses to feedback
* Use `isSpecificProtocol` instead of `==`
* Synthesize Encodable implementation lazily
* Don’t mark conformances as Used when they don’t need to be
* Avoid creating explicit one-element arrays
* Use lookupDirect instead of walking AST manually
* Produce diagnostic for Decodable classes whose non-Decodable superclass has a failable init
* Filter lazy vars manually since getStoredProperties() does not always do so
* Amend Decodable class diagnostic text
* Check for enum RawType errors only if the type was already validated
* Update unit tests to match changes
2017-07-20 08:06:21 -07:00
Itai Ferber
f873f5ec41 Add notes to suggest overriding init(from:)
Classes which inherit from Codable classes inherit their Codable implementation (as opposed to synthesizing their own). In cases where they add their own storage, they will fail to inherit their superclass’s init(from:). In this case, we provide a diagnostic suggesting that init(from:) be overridden.
2017-07-20 07:55:09 -07:00
Itai Ferber
eb031e8c86 Don’t prevent default/memberwise init
Some synthesized initializers (specifically, init(from:)) should not prevent the synthesis of a default or memberwise initializer.
2017-07-20 07:55:09 -07:00
Itai Ferber
1f8f1fea50 Allow overriding synthesized Decodable impl.
Classes which receive a synthesized Decodable implementation should be able to subclass non-Decodable classes (if the superclass has an accessible init()) method.

Also improve diagnostics when this is not the case.
2017-07-20 07:55:09 -07:00
Mark Lacey
b37b3ba367 Merge pull request #10950 from rudkx/revert-recursive-protocol-constraints-changes
Revert recursive protocol constraints changes
2017-07-13 23:21:55 -07:00
Itai Ferber
7fd5a82408 Merge pull request #10930 from itaiferber/synthesized-member-lookup
Expose synthesized members in AST lookups
2017-07-13 20:15:30 -07:00
Mark Lacey
5acc14022a Revert "[GSB] SE-0157: Reprocess delayed requirements when we need a complete PA."
This reverts commit ded45a6e1c.

This seems to slow down type checking of Swift.o by more than 3x.
2017-07-13 16:07:01 -07:00
Mark Lacey
ed23eb3761 Revert "SE-0157: Enable recursive protocol constraints by default."
This reverts commit afbdbae9d9.

Commit ded45a6e1c more than triples the
type checking time when building Swift.o, so I am going to revert that ,
and it looks like this needs to be reverted as well if that commit is
reverted.
2017-07-13 16:05:03 -07:00
Itai Ferber
e86428559a Expose synthesized members in AST lookups
Some types and members are synthesized by derived protocol conformances
(e.g. the CodingKeys member type or init(from:)/encode(to:) members
from Decodable/Encodable conformance) — however, they are not visible
in AST lookup if they have not been synthesized.

Exposes a LazyResolver callback for performing member synthesis where
relevant during qualified lookups to synthesize these members on demand
when needed.
2017-07-13 13:27:08 -07:00
Doug Gregor
afbdbae9d9 SE-0157: Enable recursive protocol constraints by default.
We don't know if they work in general, but specific cases of recursive
protocol constraints are working, and enabling them doesn't break
anything.
2017-07-13 13:01:11 -07:00
Doug Gregor
ded45a6e1c [GSB] SE-0157: Reprocess delayed requirements when we need a complete PA.
Whenever we need a complete, well-formed potential archetype,
reprocess any delayed requirements, so that we pick up additional
requirements on that potential archetype.

This relies on us tracking a generation count for the GSB instance as
a whole, which gets bumped each time we add some new requirement or
create a new potential archetype, and only actually reprocessing
delayed requirements when the generation count exceeds the point at
which we last processed delayed requirements.

This gets the most basic recursive protocol constraint working
end-to-end and doesn't seem to break things.
2017-07-12 17:23:23 -07:00
Doug Gregor
70b75491a0 SE-0157: Add a frontend flag -enable-recursive-constraints.
Introduce `-enable-recursive-constraints` to disable the error about
direct recursion within a protocol definition. The implementation of
recursive protocol constraints is incomplete, but might be useful for
experimentation.
2017-07-12 14:55:55 -07:00
Alex Hoppen
2dd670ba8b Add test cases for special subscript name 2017-07-11 19:04:13 +02:00
Doug Gregor
a6516a90c6 [Type checker] Bump warning about unavailable witnesses to an error in Swift 4
Swift 3 allowed a requirement to be satisfied by an unavailable
witness, which doesn't make sense. We've been warning about it in
Swift 3 for a while; make it an error in Swift 4.
2017-07-10 11:40:35 -07:00
Doug Gregor
a570a5a15e [Type checker] Check type equality even for argument tuples in Swift 4.
Replace a where Type-pointer-equality check with what it intended,
i.e., match up ParenTypes at the top level and perform a deeper
equality comparison of the underlying types.

Fixes SR-5166 / rdar://problem/32666189.
2017-06-20 23:49:47 -07:00
Itai Ferber
1c020fcae7 Add unit test to confirm ordering of Codable diags 2017-06-20 14:29:59 -07:00
swift-ci
ffcca776a2 Merge pull request #10398 from DougGregor/gsb-unresolved-types 2017-06-20 06:56:12 -07:00
Doug Gregor
4860607700 [GSB] Record unresolved potential archetypes as delayed requirements.
Whenever we form a potential archetype that is unresolved (because it
names a member wasn't known at the time the potential archetype was
formed), create a corresponding delayed requirement to resolve the
potential archetype. This ensures that all potential archetypes get a
chance to be resolve, fixing the

  nested type should have matched associated type

assertion in rdar://problem/31401161 (and others).
2017-06-19 22:20:21 -07:00
Xi Ge
568c861adc [FixCode] Protocol stubs shouldn't print any @ attributes.
This also addresses @jrose-apple's code review comments.
2017-06-16 16:04:57 -07:00
Itai Ferber
c277aa16b5 Merge pull request #10321 from itaiferber/weak-unowned-codable-conformance
Allow synthesis of Codable for weak/unowned vars
2017-06-16 14:19:52 -07:00