Commit Graph

9116 Commits

Author SHA1 Message Date
Florian Friedrich
e3fa190232 Check for duplicate literal switch cases
This adds a check for duplicate literal switch cases. It covers string, integer and float literals. Corresponding tests were added as well.
2017-07-31 21:19:18 +02:00
Slava Pestov
111adf928a Merge pull request #11244 from slavapestov/remove-requirement-witness-overload-ranking
Sema: Remove requirement/witness ranking
2017-07-28 12:07:04 -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
Kosuke Ogawa
2a18723b55 [gardening] Fix typos (#11245)
* [Gardening] Fix typo: getTopLeveDecls -> getTopLevelDecls

* [Gardening] Fix typo: silModue -> silModule

* [Gardening] Fix typo: Evaludate -> Evaluate

* [Gardening] Fix typo: OptioanlPayload -> OptionalPayload

* [Gardening] Fix typo: confromance -> conformance

* [Gardening] Fix typos

* [Gardening] Fix typo: tpye -> type

* [Gardening] Fix typo: resoved -> resolved

* [Gardening] Fix typo: ahve -> have

* Revert "[Gardening] Fix typo: silModue -> silModule"

This reverts commit ed8c4d0b71.
2017-07-28 10:14:21 -07:00
Slava Pestov
d35cacd45a Sema: Remove witness/requirement ranking
This doesn't appear to be necessary when name lookup
does the right thing.

We don't *want* Sema to consider overload sets
containing both a protocol requirement and a witness,
because this could lead to exponential behavior.
2017-07-28 01:19:24 -07:00
Slava Pestov
bfb252ab39 Sema: Small NFC cleanup for LookupResultBuilder::add() 2017-07-27 23:44:45 -07:00
Slava Pestov
f51a9d022c Sema: Simplify behavior of NameLookupFlags::PerformConformanceCheck flag
I'd like to remove this eventually, but for now I want
to remove this special case check.
2017-07-27 23:44:45 -07:00
Slava Pestov
ac8e0376a2 Sema: Fix requirement/witness disambiguation for subclass existentials
When performing a lookup into a class C, we might find a member of
C that witnesses a requirement in a protocol Q that C conforms to.

In this case, AST name lookup returns both results.

There are two further levels of fitering which can eliminate the
ambiguity:

- Sema name lookup maps requirements to witnesses if the base type
  of the lookup is a nominal type or a class-constrained archetype.

  Imported conformances don't have this mapping recorded, but there's
  another hack in this code path where if a requirement maps to
  itself inside a conformance, it is dropped from the results
  altogether.

- If the duplicate results were not filtered out in Sema name lookup,
  there was another hack in CSRanking which would a witness higher
  than it's requirement when comparing solutions. This doesn't work
  for imported conformances, but usually name lookup filters out
  the duplicate results sooner, which also eliminates the exponential
  behavior from having multiple constraint system solutions.

However, if we have a subclass existential C & P where C conforms
to Q and we find a member of C that witnesses a requirement of Q,
then (C & P) does not conform to Q.

So if the conformance was imported, *both* of the above checks
would fail to disambiguate the witness and requirement, and the
member access would fail to type check.

To make this work with imported conformances, teach Sema name lookup
to extract the superclass from an existential before performing the
conformance check. If the conformance check fails, it means we
found the protocol member via the 'existential' part of the subclass
existential (eg, in our case, a member of P), and we proceed as
before.

Fixes <rdar://problem/33291112>.
2017-07-27 23:18:01 -07:00
Slava Pestov
c28f0f0322 Sema: Remove unnecessary check
It looks like this is covered by the witness lookup below.

Kind of a useless change, but I'm trying to simplify the
LookupResultBuilder as much as I can.
2017-07-27 22:05:11 -07:00
Slava Pestov
b316dfc676 Sema: Fix constructor diagnostics
Noticed by inspection. I don't have a test case.
2017-07-27 22:04:39 -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
Slava Pestov
a7dad09ea5 Merge pull request #11222 from slavapestov/name-lookup-cleanup
Name lookup cleanup
2017-07-26 21:28:09 -07:00
Slava Pestov
db8f2d9c63 Sema: Remove unnecessary code from TypeChecker::lookupMember() 2017-07-26 20:46:47 -07:00
Slava Pestov
9a7f9c3009 Sema: Stop looking at LookupResult::getBase() in filterForEnumElement() 2017-07-26 20:46:31 -07:00
John McCall
0730a27f5b Compute the expression range correctly for substring-to-string fixits.
rdar://33474838
2017-07-26 19:10:55 -04:00
Robert Widmann
04e4c8c9ce Update CSDiag to use the proper InOutType convention 2017-07-26 13:15:19 -07:00
Harlan
a5098e6b69 Generate libSyntax API (#10926)
* Generate libSyntax API

This patch removes the hand-rolled libSyntax API and replaces it with an
API that's entirely automatically generated. This means the API is
guaranteed to be internally stylistically and functionally consistent.
2017-07-25 18:19:58 -07:00
Slava Pestov
05bf408dcd Merge pull request #11153 from slavapestov/introducing-superclass-constraint
Reject superclass constraints that bind existentials to classes
2017-07-24 23:37:24 -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
Slava Pestov
69ca3c7593 Sema: Fix some typos 2017-07-24 22:58:04 -07:00
Slava Pestov
c8cf0a05cf Sema: Simplify matchSuperclassTypes() 2017-07-24 22:58:04 -07:00
Slava Pestov
a3cad02708 Sema: Stricter superclass constraints when opening a generic signature
A generic signature like <T : SomeClass> would create
a subtype constraint between the type variable for T and
SomeClass. This is too loose, because a subclass existential
like 'SomeClass & SomeProto' is a subtype of SomeClass, but
cannot bind to T, because it is not representationally a
single retainable pointer.

Fixes <rdar://problem/32617814>, <https://bugs.swift.org/browse/SR-5142>.
2017-07-24 22:58:04 -07: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
Pavel Yaskevich
780616a651 Merge pull request #11129 from xedin/rdar-32973206
[ConstraintSolver] Prefer same name class properties found on subclass over superclass
2017-07-24 16:14:13 -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
Pavel Yaskevich
96c4bcd411 [ConstraintSolver] Prefer same name class properties found on subclass over superclass
If class property with the same name has been found on both subclass and superclass,
let's always prefer subclass with all else equal, because subclass property
could only be found if requested directly.

Resolves: rdar://problem/32973206
2017-07-24 15:38:58 -07:00
Robert Widmann
35851263b1 Merge pull request #11074 from CodaFi/the-sharing-economy
Staging for __shared and __owned
2017-07-24 10:13:06 -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
swift-ci
43a428c277 Merge pull request #11126 from CodaFi/param-a-rama 2017-07-23 23:49:03 -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
Robert Widmann
b77f2c147c Parse Shared
Add parser support for __shared and __owned as type attributes.  Also, extend parser diagnostics and tests to account for the new type attributes.
2017-07-23 21:47:25 -07:00
Robert Widmann
e5918f70e8 [NFC] Refactor self type computation to return a Param
Remove a user of InOutType::get and flip a few users of
FunctionType::get to pass Params instead of naked input
types.
2017-07-23 21:36:16 -07:00
Slava Pestov
1221bd8f60 Sema/AST: Fix a couple of protocol typealias validation order bugs
We break name lookup circularities by special-casing validation of
type aliases, resolving the underlying type of the type alias before
building the generic environment of the protocol that contains the
type alias.

However doing this gives the type alias an underlying type written
in terms of unresolved DependentMemberTypes which do not map to
associated types.

Attempting to substitute such a type fails.

We worked around this by re-validating type alias members of
protocols when we finally got around to building the protocol's
generic environment. Force this to happen earlier in
substMemberTypeWithBase(), because we need the fully resolved
underlying type in order to perform the substitution.

Also, fix TypeAliasDecl::setUnderlyingType() to only create a new
NameAliasType the first time it is called. In this special case
where it can be called twice with a resolved underlying type the
second time, we should not be creating a new NameAliasType.

There are better fixes possible here, requiring various levels
of refactoring. I'll investigate this soon, but for now this narrow
fix should address the problem with minimal risk.

Fixes <rdar://problem/33189068>.
2017-07-23 17:34:38 -07:00
John McCall
c0b3bf1711 Suppress access enforcement when an l-value is converted to a pointer
just for pointer identity.

The current technique for deciding whether that's the case is *extremely*
hacky and need to be replaced with an attribute, but I'm reluctant to
take that on so late in the schedule.  The hack is terrible but not too
hard to back out in the future.  Anyone who names a method like this just
to get the magic behavior knows well that they are not on the side of
righteousness.

rdar://33265254
2017-07-21 23:40:04 -04:00
Robert Widmann
0862e6c7b4 Merge pull request #11096 from davezarzycki/mutation_diag_qoi
[QoI] Ignore implicit conversions during mutation diagnostics
2017-07-21 13:36:44 -07:00
David Zarzycki
f882873996 [Sema] NFC: Remove dead code
ReferenceStorageTypes are handled elsewhere.
2017-07-21 11:25:49 +01:00
David Zarzycki
1504c2ede7 [QoI] Ignore implicit conversions during mutation diagnostics
This change helps diagnoseSubElementFailure() avoid the unknown error
path in more scenarios.
2017-07-21 10:09:47 +01:00
Joe Groff
bcf282eb0f Merge pull request #11090 from jckarter/second-type-assertion-failures
Sema: Avoid asking for the SecondType of Constraints that don't have them.
2017-07-20 17:20:13 -07:00
Joe Groff
6e9f4dcd62 Sema: Avoid asking for the SecondType of Constraints that don't have them.
Assertions tripped while trying to reproduce SR-5513.
2017-07-20 16:04:30 -07:00
Pavel Yaskevich
4f8872598b [ConstraintSolver] NFC: Add option to control early termination of shrinking phase
Currently we have a number of unsolved disjunctions hard-coded to 5,
which breaks some existing code by terminating shrinking too early.
This patch makes it a command-line option so users have control over
what that threshold can be.

Resolves: rdar://problem/33433595
2017-07-20 12:44:48 -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
Itai Ferber
3d4bef7ec4 Stylistic cleanup 2017-07-20 07:55:09 -07:00
Mark Lacey
3f308b7a99 Merge pull request #11065 from rudkx/improve-debug-constraints
[CS] Dump the number of viable solutions with -debug-constraints.
2017-07-20 00:09:41 -07:00
Slava Pestov
5c9189d357 Merge pull request #11067 from slavapestov/capture-analysis-defer
Sema: Fix capture analysis for 'defer'
2017-07-19 19:09:18 -07:00
Joe Groff
a689b34945 Merge pull request #11061 from jckarter/static-key-path-error
Sema: Don't allow key path literals to refer to static members.
2017-07-19 16:14:50 -07:00
Slava Pestov
58b4ed26b1 Sema: Fix capture analysis for 'defer'
A 'defer' parses as a DeferStmt and an implicit FuncDecl. The
implicit FuncDecl does not have a valid source location, so
be sure to consistently use the outer function's source
location instead.

Fixes <rdar://problem/33353035> / <https://bugs.swift.org/browse/SR-5464>.
2017-07-19 15:33:30 -07:00