Commit Graph

12650 Commits

Author SHA1 Message Date
Joe Groff
72aa089130 NFC opaque type cleanups
- Add some assertions, and avoid an unnecessary asserting cast
- Replace a no-op access visitor with UNINTERESTING
2019-05-02 20:28:39 -07:00
swift-ci
a97b4c88ce Merge pull request #24430 from DougGregor/property-delegates-implicit-init 2019-05-02 16:24:19 -07:00
Pavel Yaskevich
21216d8ecd [ConstraintSystem] Detect and fix invalid refs in dynamic key path member lookup
KeyPath dynamic member lookup is limited to what key path itself
could do, so let's detect and diagnose invalid references just
like we do for regular key path expressions.

Resolves: rdar://problem/50376224
2019-05-02 15:02:11 -07:00
Pavel Yaskevich
62b2da803c [ConstraintSystem] Improve @escaping parameter diagnostics
Detect difference in escapiness while matching function types
in the solver and record a fix that suggests to add @escaping
attribute where appropriate.

Also emit a tailored diagnostic when non-escaping parameter
type is used as a type of a generic parameter.
2019-05-02 00:40:30 -07:00
Doug Gregor
f34aa79df1 [Property delegates] Implicit initialization for properties with delegates.
When a property delegate type has a default initializer, use that to
implicitly initialize properties that use that delegate and do not have
their own initializers. For example, this would allow (e.g.), delegate
types like the DelayedImmutable and DelayedMutable examples to drop
the explicit initialization, e.g.,

```
  @DelayedMutable var foo: Int
```

would be implicitly initialized via

```
  $foo = DelayedMutable()
```

This is a simplistic implementation that does not yet propertly handle
definite initialization.

Fixes rdar://problem/50266039.
2019-05-01 23:17:16 -07:00
Pavel Yaskevich
943d89136c [ConstraintLocator] NFC: Add isForGenericParameter accessor 2019-05-01 18:22:31 -07:00
Slava Pestov
20dd808774 Merge pull request #23413 from slavapestov/phase-out-nscoding-hack-deployment-target
IRGen: Don't eagerly initialize NSCoding conformers on startup on new deployment targets
2019-05-01 21:04:42 -04:00
Slava Pestov
6d7d13fceb IRGen: Disable eager initialization of NSCoding adopters on newer targets
If a class does not have a custom @objc name, objc_getClass() can find
it at runtime by calling the Swift runtime's metadata demangler hook.

This avoids the static initializer on startup. If the class has a
custom runtime name we still need the static initializer unfortunately.

Fixes <rdar://problem/49660515>.
2019-05-01 17:43:58 -04:00
Doug Gregor
bf2c4d951b Prevent less-visible properties with delegates from affecting memberwise initializer
When a property with an attached delegate has less-than-internal visibility
and is initialized, don’t put it into the memberwise initializer because
doing so lowers the access level of the memberwise initializer, making it
fairly useless.

Longer term, it probably makes sense to have several memberwise initializers
at different access levels, so adding an initialized `private var` make
the memberwise initializer useless throughout the rest of the module.

Addresses rdar://problem/50266245.
2019-05-01 14:10:56 -07:00
Slava Pestov
3b6ec6c651 IRGen: Move some deployment target checks to LangOptions 2019-05-01 15:13:12 -04:00
Pavel Yaskevich
e0f81a8efc Merge pull request #24407 from xedin/diag-explicit-calls-via-fixes
[ConstraintSystem] Diagnose missing explicit calls in assignment
2019-05-01 10:44:01 -07:00
Doug Gregor
4e86c8ff52 Merge pull request #24403 from DougGregor/constraint-solver-trailing-closure-pruning
[Constraint solver] Reject trailing closures matching non-closure-parameters
2019-05-01 06:45:24 -07:00
Pavel Yaskevich
b82a8c544d [ConstraintSystem] Diagnose missing explicit calls in assignment
If the source of the assignment is a function type which has
a result that could be converted to expected destination type,
let's diagnose that as missing call if such function doesn't
have any parameters.
2019-05-01 01:40:11 -07:00
Doug Gregor
a1af0e45cb [Constraint solver] Reject trailing closures matching non-closure-parameters.
Enhance call-argument matching to reject trailing closures that match up
with parameters that cannot accept closures at all.

Fixes rdar://problem/50362170.
2019-04-30 23:12:32 -07:00
Pavel Yaskevich
0ad0a844f3 [ConstraintSystem] NFC: Move repairFailure to be a member of ConstraintSystem
That makes it much easier to use various facilities provided by
`ConstraintSystem`.
2019-04-30 16:40:06 -07:00
Brent Royal-Gordon
3494c0bd88 [TypeChecker] Rephrase platforms in availability diagnostics
This does several different things to improve how platforms are described in availability diagnostics:

• Mentions the platform in diagnostics for platform-specific @available(unavailable) attributes.
• Replaces “OS X” with “macOS”.
• Replaces “fooOS application extension” with “application extensions for fooOS”.
• Replaces “on fooOS” with “in fooOS”.

Fixes <rdar://problem/49963341>.
2019-04-30 16:32:43 -07:00
Alexis Laferrière
1119b91e80 Merge pull request #24204 from xymus/structural-type-request
GSB: use a request for the structural type of type aliases
2019-04-30 14:39:39 -07:00
Joe Groff
e7cd0a16d5 Fix node order when we demangle opaque types.
When we formed a mangled name key to look up opaque return type decls during
interface parsing, we were accidentally including the `Global` demangle node
inside the `OpaqueReturnTypeOf` node, which ended up including the `$s` prefix
in the mangling. Other type reconstruction clients like lldb which provided
well-formed mangling trees did not include the Global node, causing the prefix
to get left off and lookups to fail. Fix Sema to remove the Global node before
looking up the opaque type, and have type reconstruction consistently apply the
prefix to the lookup key.
2019-04-30 13:45:35 -07:00
swift-ci
ff208b677f Merge pull request #24363 from DougGregor/is-memberwise-initialized 2019-04-30 11:29:27 -07:00
Pavel Yaskevich
913a1f57fa Merge pull request #24383 from xedin/rdar-49582531
[Diagnostics] Improve missing conformance diagnostics for opaque return
2019-04-30 10:34:12 -07:00
Doug Gregor
96952ea9a2 [AST] Distinguish memberwise-initialized properties for storage vs. declared
The determination of whether a property is memberwise-initialized is
somewhat confused for properties that have synthesized backing properties.
Some clients (Sema/Index) want to see the declared properties, while others
(SILGen) want to see the backing stored properties. Add a flag to
`VarDecl::isMemberwiseInitialized()` to capture this variation.
2019-04-30 10:12:43 -07:00
Pavel Yaskevich
caad4a817b [MiscDiagnostics] Run opaque return checker only if all of the return expressions are correct 2019-04-29 18:42:28 -07:00
Pavel Yaskevich
1f1e8d99d7 [Diagnostics] Improve missing conformance diagnostics for opaque return
New diagnostic framework can already identify contextual failures
related to opaque return types, `RequirementFailure` just needs
to get adjusted to identify correct affected declaration and provide
tailored diagnostic.

Resolves: rdar://problem/49582531
2019-04-29 16:17:45 -07:00
Brent Royal-Gordon
70efa0be1f [TypeChecker] [NFC] Make unreachable case unreachable
A part of swift::diagnoseExplicitUnavailability() that should never run for deprecations looks for them and handles them with “break”. Change this to llvm_unreachable() so we notice if this somehow happens.

This change *should* be NFC; I’m splitting it out from other changes so that bisections can point to it if it causes problems in the future.
2019-04-29 13:25:26 -07:00
Doug Gregor
1a169b91bd Centralize the definition of isMemberwiseInitialized()
This utility was defined in Sema, used in Sema and Index, declared in
two headers, and semi- copy-pasted into SILGen. Pull it into
VarDecl::isMemberwiseInitialized() and use it consistently.
2019-04-29 10:30:38 -07:00
Slava Pestov
c81e525c54 Sema: Clean up top level code handling a little 2019-04-29 10:37:59 -04:00
Doug Gregor
e7ef638285 [Property delegates] Sure synthesized PatternBindingDecl static when needed
Fixes rdar://problem/50201019.
2019-04-27 09:38:34 -07:00
Slava Pestov
a5a902accd Merge pull request #24333 from slavapestov/small-conformance-cleanups
Small conformance checking-related cleanups
2019-04-27 12:11:45 -04:00
Slava Pestov
fa12d85739 AST: Clean up associated type default representation a bit 2019-04-26 21:47:02 -04:00
Slava Pestov
a08c5630c5 Sema: Tidy up conformance synthesis a little 2019-04-26 21:47:02 -04:00
Slava Pestov
ba6582d03f Sema: Remove various calls to getAllConformances() 2019-04-26 21:47:02 -04:00
Jordan Rose
ec4931af46 Merge pull request #24135 from theblixguy/fix/SR-9035
[Typechecker] Allow bridging of Unmanaged to Objective-C for throwing functions
2019-04-26 18:02:16 -07:00
Pavel Yaskevich
3ea2ca222a Merge pull request #24308 from xedin/improve-contextual-diags-for-keypath
[TypeChecker] Improve contextual mismatch diagnostics for key path
2019-04-26 16:35:10 -07:00
nate-chandler
6352764075 Merge pull request #24271 from nate-chandler/nate/49581931-opaque-implicit-return-constraint
Create opaque type constraint for single expr return. [49581931]
2019-04-26 15:27:46 -07:00
Pavel Yaskevich
94977ee175 [TypeChecker] Improve contextual mismatch diagnostics for key path
Detect situations where key path doesn't have capability required
by the context e.g. read-only vs. writable, or either root or value
types are incorrect e.g.

```swift
struct S { let foo: Int }
let _: WritableKeyPath<S, Int> = \.foo
```

Here context requires a writable key path but `foo` property is
read-only.
2019-04-26 10:59:01 -07:00
Alexis Laferrière
c27dca3383 Sema: restrict the options to resolve the structural type of type aliases 2019-04-26 10:28:34 -07:00
Slava Pestov
be4e3f23e7 Sema: markAsObjC() no longer needs to resolveDeclSignature()
We used to walk the interface type of the declaration to determine if any
_ObjectiveCBridgeable conformances need to be completed, but we no longer
do that here.
2019-04-25 22:34:00 -04:00
Slava Pestov
324e36f47f Sema: Remove useObjectiveCBridgeableConformances()
THere is no longer any reason to complete ClangImporter-synthesized _ObjectiveCBridgeable
conformances in Sema. SILGen will determine the ones that it needs and will trigger
conformance checking as needed automatically.
2019-04-25 22:33:23 -04:00
Slava Pestov
33b548f8b0 AST: Remove SourceFile::UsedConformances
Sema no longer adds conformances to a per-SourceFile list that it thinks
are going to be "used" by SILGen, IRGen and the runtime. Instead, previous
commits already ensure that SILGen determines the set of conformances to be
emitted, triggering conformance checking as needed.
2019-04-25 22:32:27 -04:00
Pavel Yaskevich
d5fcf1a665 Merge pull request #24274 from theblixguy/fix/computed-prop-fix-it-lazy
[CSDiagnostics] Removes lazy when applying computed property fix-it
2019-04-25 13:22:25 -07:00
Suyash Srijan
24f3f5447b Merge branch 'master' into fix/SR-9035 2019-04-25 19:09:56 +01:00
Alexis Laferrière
09fbdc20cb Sema: intro a request evaluator to get the structural type of type aliases
This request evaluator doesn't rely on the previous execution of
a compilation phase but it caches the result in a compatible way.
2019-04-25 10:21:36 -07:00
Suyash Srijan
20cfa14423 [CSDiagnostics] Removes lazy attributes when applying computed property fix-it 2019-04-25 17:59:07 +01:00
Nate Chandler
f9400be21b Create opaque type constraint for single expr return. [49581931]
Previously, an OpaqueUnderlyingType constraint was created only if the
contextual type purpose was CTP_ReturnStmt.  Now that there is a
distinct CTP for implicit, single-expression returns, an
OpaqueUnderlyingType constraint needs to be created if that is the CTP.
2019-04-25 08:52:46 -07:00
nate-chandler
155a155000 Merge pull request #23251 from nate-chandler/nate/omit-return
Allow return to be omitted from single expression functions.
2019-04-25 08:36:34 -07:00
swift-ci
d24bc38797 Merge pull request #23701 from DougGregor/property-delegates-as-custom-attributes 2019-04-24 22:51:18 -07:00
Doug Gregor
0c26e4349e Underscore the @propertyDelegate attribute to indicate that it's experimental 2019-04-24 21:25:33 -07:00
Slava Pestov
e68a2330fe Merge pull request #24255 from slavapestov/objc-from-witnessed-requirement-ordering
Sema: Fix order dependency in @objc inference from witnessed protocol requirement
2019-04-24 22:12:46 -04:00
Pavel Yaskevich
cdb9fb4a27 Merge pull request #24234 from xedin/sr-10467
[ConstraintSystem] Type of key path expression should be a known `KeyPath` type
2019-04-24 17:04:31 -07:00
Slava Pestov
04ac33dd2b Sema: Fix order dependency in @objc inference from witnessed protocol requirement
If we haven't validated the declaration yet, the 'witnesses @objc
requirement' check would immediately fail. Move the validateDecl()
call to matchWitness() to fix this.

Fixes <rdar://problem/49482328>, <https://bugs.swift.org/browse/SR-10257>.
2019-04-24 17:35:05 -04:00