Commit Graph

1313 Commits

Author SHA1 Message Date
Doug Gregor
5c831a71ee Revert "[SE-0143] Put conditional conformances behind an "experimental" flag."
This reverts commit b59c30c1af.
2017-12-18 22:54:31 -08:00
Jeffrey MACKO
716457c135 Fix SR-5615 2017-12-16 01:23:36 -05:00
Robert Widmann
1d6f11ab54 Refactor ArrayExpr visitor for better QoI
Also remove mention of the word “contextual” type from the diagnostic
that rewrites array literals into dictionary literals and scale back
the scope of the diagnostic.  This method was catching and
mis-diagnosing too many errors that could better be handled by invalid
conversion diagnostics.
2017-12-15 18:20:36 -05:00
Robert Widmann
d2aa82de1f Merge pull request #12818 from CodaFi/cover-model
Stricter enforcement of the "large space" heuristic
2017-12-14 02:01:17 -05:00
Doug Gregor
cabdf84179 Suggest @objc for overrides of declarations from/in extensions.
The Swift class model does not support overriding declarations where either
the overridden declaration or the overriding declaration are in an extension.
However, the Objective-C class model does, so marking the declaration as
@objc (when possible) will work around the limitation.

Customize the "cannot override declaration in extension" diagnostic to
suggest adding @objc to the overridden declaration in cases where
@objc is permitted. Fixes SR-6512 / rdar://problem/35787914.
2017-12-13 14:54:32 -08:00
Robert Widmann
43f06afef2 Defer analysis of large switch bodies
This presents a regression in diagnostic quality that is definitely
worth it not to lie to SILGen about whether a switch is covered or not.

At the same time, disable SIL’s unreachable diagnostic for ‘default’
clauses which would previously cause a warning to be emitted if the
default was proven to be unreachable.  This analysis is incomplete
anyways and can be done by Sema in the future if we desire.
2017-12-13 16:22:48 -05:00
swift-ci
2514f7061f Merge pull request #13330 from DougGregor/where-clause-ref-typealias-in-protocol 2017-12-07 15:38:53 -08:00
Doug Gregor
879b1802f0 [GSB] Downgrade "neither type in same-type has a generic param" error to warning.
There is nothing specifically wrong with uttering a same-type
constraint in a where clause where both sides are concrete
types. Downgrade this to a warning; we'll check that the concrete
types match (of course), and such a well-formed constraint will simply
be canonicalized away.

This aids the migration of IndexDistance from an associated type to
Int.
2017-12-07 14:44:35 -08:00
Jordan Rose
7c707ce97c For 'lazy', make "cannot override with a stored property" a warning (#13304)
Previous versions of Swift accidentally treated lazy properties as
computed properties because of how they were implemented. Now that we
check this correctly, we've broken source compatibility. Downgrade the
error to a warning in this case.

(Arguably we could /allow/ overriding with a stored property. The
original concerns were that you could accidentally end up with extra
storage you didn't need, and that observing accessors would behave
differently based on whether or not the property was overriding. But
there's at least no ambiguity for 'lazy', which can't have observing
accessors today.)

rdar://problem/35870371
2017-12-06 13:41:07 -08:00
Mark Lacey
73a492dc4f For Swift 3/4 mode, do not treat IUOs in illegal positions as Optionals.
Instead, just emit a deprecation warning and suggest switching to Optionals.

The old behavior caused several projects to break, so before we change
the behavior here we need to investigate whether we can mitigate most
of those breaks.
2017-12-04 16:15:13 -08:00
Jordan Rose
8f8f00012a Merge pull request #12834 from jrose-apple/restrict-cross-module-struct-initializers-2
Implementation of SE-0189 "Restrict cross-module struct initializers to be delegating"

rdar://problem/34777878
2017-11-30 13:32:45 -08:00
Doug Gregor
b59c30c1af [SE-0143] Put conditional conformances behind an "experimental" flag.
Conditional conformances aren't quite ready yet for Swift 4.1, so
introduce the flag `-enable-experimental-conditional-conformances` to
enable conditional conformaces, and an error when one declares a
conditional conformance without specifying the flag.

Add this flag when building the standard library (which will vend
conditional conformances) and to all of the tests that need it.

Fixes rdar://problem/35728337.
2017-11-28 16:01:51 -08:00
Mark Lacey
8b55a0f61b SE-0054: Rework diagnostics for IUOs and revise Swift 3 /4 semantics.
For Swift 3 / 4:

Deprecate the spelling "ImplicitlyUnwrappedOptional", emitting a warning
and suggesting "!" in places where they are allowed according to
SE-0054.

In places where SE-0054 disallowed IUOs but we continued to accept them
in previous compilers, emit a warning suggesting "Optional" or "?"  as
an alternative depending on context and treat the IUO as an Optional,
noting this in the diagnostic.

For Swift 5:

Treat "ImplicitlyUnwrappedOptional" as an error, suggesting
"!" in places where they are allowed by SE-0054.

In places where SE-0054 disallowed IUOs, emit an error suggestion
"Optional" or "?" as an alternative depending on context.
2017-11-18 11:41:53 +09:00
Slava Pestov
e659befcf3 Sema: Clean up wording in some attribute-related diagnostics 2017-11-15 16:26:13 -08:00
Joe Groff
4b401e257a Merge pull request #12835 from jckarter/key-path-type-checking
Sema: Fixes for KeyPath type checking.
2017-11-14 13:10:44 -08:00
Erik Eckstein
8033476b64 Function-level optimization attributes.
For now these are underscored attributes, i.e. compiler internal attributes:
@_optimize(speed)
@_optimize(size)
@_optimize(none)

Those attributes override the command-line specified optimization mode for a specific function.
The @_optimize(none) attribute is equivalent to the already existing @_semantics("optimize.sil.never") attribute
2017-11-14 11:25:02 -08:00
Jordan Rose
ca1979c920 Improve diagnostics for setting a 'let' property in a delegating init 2017-11-09 18:08:01 -08:00
Joe Groff
73d2e9a47f Sema: Fixes for KeyPath type checking.
When testing KeyPathApplication constraints, we would keep going after rejecting a concrete KeyPath application by trying PartialKeyPath and AnyKeyPath, even though that's not what we want, since any key path application expression can type check with an AnyKeyPath. We would then miscompile by building the AST such that we applied the mismatched key path expression directly to the base. We also didn't handle expressions where the base was a subtype of the key path's base type correctly—the conversion means the base can't be written through in this situation, and we hardcoded the concrete-to-existential case instead of handling general conversions. Fix these problems, and add an AST verifier for KeyPathApplicationExprs to help catch problems in the future. Fixes SR-6300 | rdar://problem/35368903.
2017-11-09 11:57:23 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Doug Gregor
c94d1cd31a [Type checker] The term "layout constraint" is confusing; don't use it.
Within the compiler, we use the term "layout constraint" for any
constraint that affects the layout of a type parameter that has that
constraint. However, the only user-visible constraint is "AnyObject",
and calling that a layout constraint is confusing. Drop the term
"layout" from diagnostics.

Fixes rdar://problem/35295372.
2017-11-02 12:03:09 -07:00
Doug Gregor
2a5ba95316 [Parser] Allow both @noescape and @autoclosure in SIL mode.
When printing SIL, we end up printing both @noescape and @autoclosure. It's
not technically wrong (just redundant), so allow it when parsing the SIL
back.
2017-11-01 14:02:21 -07:00
Doug Gregor
945ac3de0a Revert " Re-enable parse_stdlib tests." 2017-11-01 06:59:35 -07:00
swift-ci
c89e49091a Merge pull request #12700 from DougGregor/reenable-parse-stdlib-test 2017-11-01 01:36:07 -07:00
Doug Gregor
3e70db943c [Parser] Allow both @noescape and @autoclosure in SIL mode.
When printing SIL, we end up printing both @noescape and @autoclosure. It's
not technically wrong (just redundant), so allow it when parsing the SIL
back.
2017-10-31 23:39:18 -07:00
Slava Pestov
bcb874b446 Sema: Refactor type witness checking a bit 2017-10-31 19:35:31 -07:00
Slava Pestov
82999d8177 Sema: Don't allow @_inlinable or @_versioned to be applied to dynamic declarations 2017-10-31 13:37:20 -07:00
Doug Gregor
5947ae9c00 Merge pull request #12645 from DougGregor/conformance-near-miss
Warn on “near-misses” when defaults are used for protocol witnesses.
2017-10-27 23:01:59 -07:00
Mark Lacey
f9b82bccb7 Ban IUOs in illegal positions harder under Swift 5 and later.
SE-0054 specified that the use of implicitly unwrapped optionals was
limited to just a few places, but the implementation at the time did not
completely ban the other uses. This is another attempt to do so, but
it's only on for compilations in Swift 5 mode and later.

For earlier versions, we fall back on the existing implementation.

Fixes: rdar://problem/27707015
2017-10-26 22:21:36 -07:00
Mark Lacey
e07a7362cf Add a warning that ImplicitlyUnwrappedOptional is deprecated in 4+.
Per SE-0054, implicitly unwrapped optional is not a distinct type in the
type system, but rather just the notion that certain Optionals (denoted
by the sigil "!" rather than "?") can be implicitly unwrapped.

This is a first step in the direction of implementing this notion by
emitting a warning if the type is spelled out.
2017-10-26 18:09:26 -07:00
Doug Gregor
493d4da667 Warn on “near-misses” when defaults are used for protocol witnesses.
When a particular nominal type or extension thereof declares conformance
to a protocol, check whether that type or extension contains any members
that *nearly* match a defaulted requirement (i.e., a requirement that 
is satisfied by something in a protocol extension), but didn’t match
for some reason and weren’t used to satisfy any other requirement of
that protocol. It’s intended to catch subtle mistakes where a default
gets picked instead of the intended member.

This is a generalization of the code we’ve had for @objc optional
requirements for a long time.

Fixes rdar://problem/24714887.
2017-10-26 17:04:46 -07:00
gregomni
7073eb15a4 Disallow override of dynamic Self return type with non-dynamic in a subclass
unless that subclass is final.
2017-10-18 13:07:04 -07:00
Huon Wilson
ec6c83aa44 [Sema] Check conditional conformances for generic function calls early.
This allows for better (although not perfect) diagnostics, and more guarantees
of correctness.
2017-10-10 20:17:42 -07:00
Huon Wilson
041b14175c [Sema] Remove restriction on conditional conformances. 2017-10-10 19:17:31 -07:00
Slava Pestov
d866ebf8f4 Merge pull request #11744 from gspiers/bugfix/SR-479-ownership-in-protocols
[SE implementation] Ownership keyword removal in protocols
2017-10-10 00:08:57 -07:00
Slava Pestov
7cbd0c0b37 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 19:53:51 -07:00
Jordan Rose
192b523a8e Revert "Fix issue with 'Self' metadata when class conforms to protocol with default implementations" (#12344)
It broke the 32-bit iOS simulator, and possibly the 64-bit simulator as well. Reverts 5618553.
2017-10-09 10:02:48 -07:00
Slava Pestov
80ada27707 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 00:53:03 -07:00
Greg Spiers
c5d6e17d85 Do not allow ‘weak’ and ‘unowned’ keywords for property declarations in protocols. 2017-10-01 12:43:48 +01:00
Graydon Hoare
e063767091 [Diagnostics] s/may/must/ in 'may not have operator requirements' 2017-09-29 16:09:23 -04:00
Graydon Hoare
81aecb6a54 [Diagnostics] s/may/must/ in 'may not be applied to' 2017-09-29 16:09:23 -04:00
Graydon Hoare
b0cc5c9113 [Diagnostics] s/may/must/ in 'may not have observers' 2017-09-29 16:09:23 -04:00
Graydon Hoare
6c64f86720 [Diagnostics] s/may/must/ in 'may not be used on an already-lazy global' 2017-09-29 16:09:23 -04:00
Graydon Hoare
84418a5155 [Diagnostics] s/may/must/ in 'may not be used on a computed property' 2017-09-29 16:09:23 -04:00
Graydon Hoare
3d8cc2f66a [Diagnostics] s/may/must/ in 'may not be used on subscript parameters' 2017-09-29 16:09:23 -04:00
Graydon Hoare
0539cc5836 [Diagnostics] s/may/must/ in 'may not be used on variadic parameters' 2017-09-29 16:09:23 -04:00
Graydon Hoare
131e85fbf1 [Diagnostics] s/may/must/ in 'may not contain stored properties' 2017-09-29 16:09:23 -04:00
Graydon Hoare
17aa7aa910 [Diagnostics] s/may/must/ in 'may not be declared mutating' 2017-09-29 16:09:23 -04:00
Graydon Hoare
867224dbde [Diagnostics] s/may/must/ in 'may not be declared both' 2017-09-29 16:09:23 -04:00
Graydon Hoare
5d7d1201d4 [Diagnostics] s/may/must/ in 'may not be indexed with' 2017-09-29 16:09:23 -04:00
Graydon Hoare
f4df23eefb [Diagnostics] s/may/must/ in 'may not be juxtaposed' 2017-09-29 16:09:23 -04:00