Commit Graph

7976 Commits

Author SHA1 Message Date
swift-ci
f513adada9 Merge pull request #8556 from rudkx/propagate-constraints 2017-04-05 10:22:15 -07:00
Mark Lacey
a1ceecc0ae [Constraint solver] Fix a fix-it formatting issue.
With constraint propagation enabled, we go down a different path in the
solver that results in a type with ParenType wrapped around it. Normally
in diagnostic formatting we would strip these off, but in explicitly
forming a string for a fixit, we need to do it ourself. Hits in
test/Parse/try.swift with constraint propagation enabled.
2017-04-05 08:43:08 -07:00
swift-ci
23989db8b4 Merge pull request #8550 from DougGregor/repeal-conformance-death-tax 2017-04-04 22:55:25 -07:00
Doug Gregor
30ef37cb83 [AST] Eliminate "inherited conformances" from NormalProtocolConformance.
All of this information is recoverable from the more-general,
more-sane signature conformances, so stop
recording/serializing/deserializing all of this extra stuff.
2017-04-04 22:20:50 -07:00
swift-ci
9adf79a370 Merge pull request #8546 from rudkx/propagate-constraints 2017-04-04 19:25:03 -07:00
Roman Levenstein
1106f139f4 Merge pull request #8454 from swiftix/wip-warn-about-unused-generic-params
[type-checker] More correct way to determine if a given generic parameter of a function cannot be inferred because it is not used
2017-04-04 18:51:47 -07:00
Mark Lacey
809ddd0c87 [Constraint solver] Remove invalid assert from constraint propagation.
It turns out that for disjunctions formed for subscripts, we have an
explicit function type (e.g. ($T1)->$T2) for the LHS of the bind
overload constraint, and when a subscript is mixed with an explicit
call (e.g. x[i](2)) we end up with an applicable function constraint
where the RHS is $T2 (which is a function type itself), so this assert
was invalid.

Fundamentally the assert wasn't checking anything important, so it won't
be missed. The important check here is that the applicable function
constraint that we started with is only involved in one disjunction
since we're only returning one.

This shows up in test/Constraints/overload.swift when I run it with
-propagate-constraints enabled:
  func test20886179(_ handlers: [(Int) -> Void], buttonIndex: Int) {
    handlers[buttonIndex](buttonIndex)
  }
2017-04-04 18:45:45 -07:00
Roman Levenstein
7ee43fcf1a Address PR review comments 2017-04-04 11:35:04 -07:00
Joe Groff
638759ac28 SIL: Add a "keypath" instruction for summoning literal keypath objects. 2017-04-04 11:31:15 -07:00
Joe Groff
fc23781906 Sema: First pass at type-checking Swift key paths.
TODO:

- Select the KeyPath subclass corresponding to the write capability of the key path components
- Figure out an issue with unresolved solutions being chosen with contextually-typed keypaths
- Diagnostic QoI
2017-04-04 11:31:15 -07:00
Joe Groff
e3046d6f75 Parsing for native keypaths.
Use `#keyPath2` as a stand-in for the final syntax.
2017-04-04 11:31:15 -07:00
Joe Groff
a5ca6ccd61 Restructure KeyPathExpr to allow more kinds of components.
Expand the representation in anticipation of more kinds of components. NFC intended yet.
2017-04-04 11:31:15 -07:00
Joe Groff
eb5d006e40 Rename ObjCKeyPathExpr -> KeyPathExpr.
We can use the same general shape of expression for native key paths.
2017-04-04 11:31:15 -07:00
Roman Levenstein
657a3c0768 Lazy construct the set of implicitly used generic params 2017-04-04 11:15:02 -07:00
Roman Levenstein
e52962f13a [type-checker] More correct way to determine if a given generic parameter of a function cannot be inferred because it is not used
The overall idea is like this:
- first, collect the generic params that are explicitly used by types of arguments or return type
- then perform a fix-point analysis, where at each step, a set of generic signature’s requirements is checked.
   - If there is a requirement where one of the involved generic params is already proven to be used, then all other generic params from the same requirement are also considered to be implicitly used in the function signature, because they are used to put a requirement on a generic param that is already known to be used in the function signature.

The fix-point iteration is required to handle chains of dependencies between requirements. See the updated test case for an example.

Fixes rdar://29585211
2017-04-04 11:15:02 -07:00
Doug Gregor
ab7cd7fbe4 Enable associated type where clauses in all language modes
We're ready to start experimenting with and rolling out this feature
in earnest.
2017-04-04 10:58:01 -07:00
Doug Gregor
6bf4c461aa [SubstitutionMap] Use conformance access paths to find conformances.
When looking up a particular conformance in a SubstitutionMap, use the
associated generic signature to determine how to find that conformance
(via a conformance access path). Follow that conformance access path
to retrieve the desired conformance.

FIXME: There is still one failure, here

  Constraints/generic_overload.swift

which appears to be because we either have the wrong generic signature
for the override case or we are looking in the wrong map.
2017-04-04 10:58:01 -07:00
Doug Gregor
4eeb53f7a6 Check conformances against the requirement signature using module lookup.
When we are checking the conformance of a nominal type to a particular
protocol, we check each of the requirements in the requirement
signature, substituting in our Self type and (by extension) type
witnesses. However, when we're trying to fulfill requirements for
associated types (which might be mapped to concrete types), perform
the conformance lookup in the module of the conformance itself---not
the SubstitutionMap, which can't possibly have them at this point.

Fixes rdar://problem/31041997.
2017-04-04 10:58:01 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Slava Pestov
5efe9e8134 Sema: Fix latent bug in TypeChecker::checkGenericArguments()
We were passing an already-substituted type to subst().

This is about to become an error, so fix the code to do
the right thing.
2017-04-03 20:41:31 -07:00
Mark Lacey
ea224b9d8e Merge pull request #8525 from rudkx/propagate-constraints
[Constraint solver] Constraint propagation, disabled by default.
2017-04-03 20:19:34 -07:00
Mark Lacey
0cd57bd481 [Constraint solver] Constraint propagation, disabled by default.
This is an initial implementation of the constraint propagation pass,
disabled by default at the moment as it does not currently pass all
tests.

I have other changes that I'll hold off on for now because they are
incomplete. Without those changes, this pass doesn't really achieve
much, so this is really just a checkpoint on some progress and not
something really worth trying out at this point.
2017-04-03 19:05:27 -07:00
swift-ci
117e5f0611 Merge pull request #8496 from DougGregor/se-0160-objc-nonobjc-extensions 2017-04-03 01:04:47 -07:00
practicalswift
288cb35b36 Merge pull request #8495 from practicalswift/gardening-20170402
[gardening] Remove unused variables and methods. Fix \t. Use isa<T>(). Typos.
2017-04-03 09:58:44 +02:00
Doug Gregor
e1a470008e [SE-0160] Allow @nonobjc on extensions of classes. 2017-04-03 00:23:13 -07:00
Doug Gregor
52314d70d3 [SE-0160] Allow @objc on extensions of classes. 2017-04-02 23:47:24 -07:00
Slava Pestov
c1c54d1462 Sema: Fix materializeForSet for members of extensions of imported classes
An assertion I added recently to check property overrides in
the ASTVerifier uncovered some bugs in this area:

- We did not synthesize a materializeForSet for properties
  defined in extensions of imported classes unless they
  witnessed a protocol requirement.

  This triggered an assertion if the property had an
  override that was checked before the protocol conformance,
  since the override's materializeForSet would not be marked
  as an override of the base materializeForSet.

- materializeForSet for properties defined in extensions would
  statically dispatch the getter and setter instead of dynamically
  dispatching. This is incorrect since we statically dispatch
  to the materializeForSet in this case, and we can in fact
  override it in a subclass.

Fixes <rdar://problem/31334272>.
2017-04-02 23:43:41 -07:00
Slava Pestov
e1ad85b082 Sema: Don't synthesize materializeForSet if Optional type is missing
This fixes a regression in one of the SIL crashers.
2017-04-02 23:43:41 -07:00
practicalswift
787023b132 [gardening] Use foo && .isa<T>() instead of .dyn_cast_or_null<T>(foo) if the result is not needed 2017-04-02 16:04:57 +02:00
Toni Suter
09a56c16fd [SR-4347] default to Any? instead of Any if there is a nil literal 2017-04-02 13:26:13 +02:00
Toni Suter
3d116799d6 Merge branch 'master' into SR-4347 2017-04-01 20:35:34 +02:00
Doug Gregor
bbe3e92da3 [SE-0160] Add @objcMembers attribute and infer it on XCTestCase. 2017-03-31 21:54:03 -07:00
Doug Gregor
49d9e8c625 [SE-0160] Warn var/subscript using deprecated @objc and explicit accessor @objc
Warn about cases where a storage declaration (property or subscript)
has an accessor with an explicit @objc, but for which the storage
declaration itself is only @objc due to deprecated @objc inference.
2017-03-31 21:54:02 -07:00
Doug Gregor
38d95dccc5 [SE-0160] Don't model explicit 'dynamic' as deprecated @objc inference.
When the 'dynamic' modifier is explicitly written on a declaration, it
requires the Objective-C runtime. In Swift 3, this (directly) implies
'@objc'. In Swift 4, it requires that the '@objc' be written
explicitly. Hence, a Swift 3 -> Swift 4 migration will always retain
the @objc-ness of the entry point, so we don't need to treat it as
"inferred".
2017-03-31 21:54:01 -07:00
Doug Gregor
9f68290880 [SE-0160] Diagnose overrides of members in extensions using deprecated @objc.
Overriding of members introduced in class extensions depends on the
presence of an Objective-C entrypoint. When we override such a
member---which used the deprecated @objc inference rule and occurs in
a class extension, where non-@objc methods currently cannot be
overridden---warn about the use of explicit @objc.
2017-03-31 21:54:01 -07:00
Doug Gregor
cf93bebb9c [SE-0160] Improve diagnostics for -warn-swift3-objc-inference.
Split the warning into two warnings, because we want different Fix-It behavior.

* For the ‘dynamic’ warning, drop the “in Swift 4” part and keep the @objc Fix-It on the main warning. This is always auto-applyable.

* For the inferred-for-members-of-Objective-C-derived-classes warning, drop the “in Swift 4” part. More importantly, split off two notes: one with the @objc Fix-It (Swift 3 behavior) and one with the @nonobjc Fix-It (Swift 4 behavior). This makes it clearer that there is a choice, and neither is “obviously” correct.
2017-03-31 21:54:00 -07:00
Doug Gregor
eb069eeb8d [SE-0160] Address a few more comments from Jordan 2017-03-31 21:53:59 -07:00
Doug Gregor
f4b72f0cfc Minor tweaks per Jordan's review (thanks!) 2017-03-31 21:22:16 -07:00
Doug Gregor
cbaeca2c81 [SE-0160] Require '@objc' on 'dynamic' members in Swift 4. 2017-03-31 21:22:16 -07:00
Doug Gregor
b6fe111c28 [SE-0160] @GKInspectable implies @objc 2017-03-31 21:22:16 -07:00
Doug Gregor
affacac0c9 [SE-0160] @IBInspectable implies @objc 2017-03-31 21:22:16 -07:00
Doug Gregor
ebdfb40ebb [SE-0160] Allow one to enable/disable Swift 3 @objc inference rules.
Introduce flags `-enable-swift3-objc-inference` and
`-disable-swift3-objc-inference` to enable/disable the Swift 3 `@objc`
inference rules. Under `-swift-version 3`, default to the former;
under `-swift-version 4`, default to the latter. For testing purposes,
one can provide either flag in eiher language mode.
2017-03-31 21:22:16 -07:00
Doug Gregor
7dd1c87dd3 [SE-0160] Warn about uses of @objc declarations that used deprecated @objc inference.
When in Swift 3 compatibility mode without
`-warn-swift3-objc-inference`, warn on the *uses* of declarations that
depend on the Objective-C runtime that became `@objc` due to the
deprecated inference rule. This far more directly captures important
uses of the deprecated Objective-C entrypoints. We diagnose:

* `#selector` expressions that refer to one of these `@objc` members
* `#keyPath` expressions that refer to one of these `@objc` members
* Dynamic lookup (i.e., member access via `AnyObject`) that refers to
  one of these `@objc` members.
2017-03-31 21:22:15 -07:00
Doug Gregor
2c1981fe9d [SE-0160] Add an opt-in warning about deprecated @objc inference.
Introduce an opt-in warning (enabled by the frontend option
-warn-swift3-objc-inference) for each declaration for which @objc is
inferred based on Swift 3 rules that no longer apply after SE-0160.
2017-03-31 21:22:15 -07:00
Doug Gregor
afef3421a8 [Type checker] Make the reason for @objc inference more descriptive.
Rather than the nebulous “do not diagnose”, separate out the two reasons for a non-diagnosed @objc: it’s a member of an Objective-C-derived subclass or it’s an accessor for a property.
2017-03-31 21:22:15 -07:00
Doug Gregor
23627b143c [SE-0160] Reorganize shouldMarkAsObjC() to separate out Swift 3 inference. 2017-03-31 21:22:15 -07:00
Doug Gregor
d8c8dd6585 [Conformance checker] Check the requirement signature once we have type witnesses.
The requirement signature concerns the conforming type and its
associated types, so check it once we've resolved all of the type
witnesses---and before we check the other requirements.
2017-03-31 16:59:09 -07:00
Doug Gregor
820d20473a [Type checker] Stop computing *all* conformance access paths in +Asserts builds.
This code was only there while we waited for IRGen to start depending
on conformance access paths, as an assertion. Now, it's just a waste
of time to compute this information for *every* conformance.
2017-03-31 16:59:09 -07:00
Slava Pestov
9a3f0fc527 Sema: Fix for SourceKit crash in inheritsSuperclassInitializers()
Two problems:

1) We were tearing down the type checker too early, before all
   relevant decls in other files had been type checked, so there
   was no LazyResolver available for use in the ASTContext.

   This might explain the crashes coming through
   diagnoseUnintendedObjCMethodOverrides().

2) When a lazy resolver was set in the ASTContext, we were not
   using it in the case where nullptr was passed in as the
   'resolver' parameter to inheritsSuperclassInitializers().

   This might fix the crashes where we were coming in from other
   code paths, but I'm less confident about this case.

Possibly fixes <rdar://problem/29043074>, <rdar://problem/30976765>,
<rdar://problem/31122590>, and <rdar://problem/31286627>, and the
many other similar-looking dupes.
2017-03-31 00:04:17 -07:00
Xi Ge
75e191f5ac AST: Summarize a commonly used call chain in AbstractFunctionDecl. NFC (#8424) 2017-03-30 10:51:10 -07:00