Commit Graph

4518 Commits

Author SHA1 Message Date
Doug Gregor
938214732a Customize @objc(selector) arity mismatch diagnostic for throwing methods.
The Objective-C method corresponding to a throwing method has an extra
error parameter; note that within the arity mismatch diagnostic to
reduce head-scratching.

Swift SVN r27277
2015-04-14 16:24:25 +00:00
Doug Gregor
68e8c3ac88 Include the error in the Objective-C selector for throwing methods.
When computing an Objective-C selector for a throwing method,
introduce an "error:" selector piece at the location specified by the
foreign error convention. If it's part of the first selector piece,
append "WithError" to the method base name.

Also require the manually-specified @objc(selector) of a throwing
method to include a selector piece for the error parameter.

Swift SVN r27276
2015-04-14 16:24:24 +00:00
Devin Coughlin
d08b98b1ca Sema: Turn on availability checking by default
Enable checking for uses of potentially unavailable APIs. There is
a frontend option to disable it: -disable-availability-checking.

This commit updates the SDK overlays with @availability() annotations for the
declarations where the overlay refers to potentially unavailable APIs. It also changes
several tests that refer to potentially unavailable APIs to use either #available()
or @availability annotations.

Swift SVN r27272
2015-04-14 06:44:01 +00:00
Doug Gregor
272371a3f5 Attach a foreign error convention to @objc methods.
For any @objc method, attach either the foreign error convention we inherit
from an overridden method (if available) or the foreign error
convention we computed as part of @objc validation.

Extend the AST dumper to dump the foreign error convention so that we
can test this.

Swift SVN r27267
2015-04-14 00:35:49 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Doug Gregor
eaeaf5dfd3 Enforce @objc restrictions on throwing methods.
Throwing @objc methods need to get mapped down to the Objective-C
runtime, so check that we can establish a foreign error convention for
them, and complain otherwise.

As a drive-by, don't allow any throwing function types to occur any
place else within @objc declarations.

Swift SVN r27259
2015-04-13 21:30:56 +00:00
Doug Gregor
54011ed7d6 Remove FuncDecl::throws(). NFC
FuncDecl::throws() is misleading because it only tells us whether the
'throws' keyword was present on the declaration. Since source
locations are lost during deserialization, it would give the wrong
result. Nobody was making this mistake now, but it's better not to
leave this trap in the ASTs.

Use AbstractFuncitonDecl::isBodyThrowing() to determine whether a
particular function (or initializer, eventually) can throw.

Swift SVN r27257
2015-04-13 21:30:53 +00:00
Devin Coughlin
978dd3a357 Sema: Check protocol conformances for potential unavailability.
Make sure that a witness declaration is at least as available as
the protocol requirement declaration. This is analogous to requiring that an
override is at least as available as the base declaration.

We don’t use the RequirementMatch machinery to mark a candidate as unsafe but
rather let the witness be chosen and then diagnose for potential unavailability.
That is, potential unavailability will not affect the search for a candidate
witness to a requirement. This is less expressive (users cannot write a protocol
that selects an available implementation) but is more predictable.

Swift SVN r27256
2015-04-13 19:44:47 +00:00
Doug Gregor
9256250273 Fix type checking for a non-throwing function as a subtype of a throwing function.
A non-throwing function can be a trivial subtype of a throwing
function. Encode this rule more directly, introduce some additional
tests to ensure that we get the behavior right where we need exact
matches, and add a failure kind with custom diagnostic for cases where
function types mismatch due to 'throws'.

Swift SVN r27255
2015-04-13 18:39:39 +00:00
Joe Groff
570f08baca Sema: Recognize NSError-to-ErrorType-conformance casts as possible.
Swift SVN r27254
2015-04-13 17:14:49 +00:00
Joe Groff
b03795e5f7 Add a '@convention(xxx)' attribute for specifying function conventions.
This is new attribute we're using to coalesce @thin, @objc_block, and @cc, and to extend to new uses like C function pointer types. Parse the new attribute, but preserve support for the old attributes, and print with the old attributes for now to separate out test changes. Migration fixits and test updates to come. I did take the opportunity here to kill off the '@cc(cdecl)' hack for AST-level function pointer types, which are now only spelt with @convention(c).

Swift SVN r27247
2015-04-13 04:27:02 +00:00
Doug Gregor
997136962e Always open existential types in the type checker.
Consistently open all references into existentials into
opened-existential archetypes within the constraint solver. Then,
during constraint application, use OpenExistentialExprs to record in
the AST where an existential is opened into an archetype, then use
that archetype throughout the subexpression. This simplifies the
overall representation, since we don't end up with a mix of operations
on existentials and operations on archetypes; it's all archetypes,
which tend to have better support down the line in SILGen already.

Start simplifying the code in SILGen by taking away the existential
paths that are no longer needed. I suspect there are more
simplifications to be had here.

The rules for placing OpenExistentialExprs are still a bit ad hoc;
this will get cleaned up later so that we can centralize that
information. Indeed, the one regression in the compiler-crasher suite
is because we're not closing out an open existential along an error
path.

Swift SVN r27230
2015-04-11 03:20:22 +00:00
Doug Gregor
4ec1cb2537 Collapse creation of DynamicMemberRefExprs into the normal member-reference path. NFC
Swift SVN r27229
2015-04-11 03:20:15 +00:00
Devin Coughlin
a4847e9c31 Sema: Recommit "Disallow potential unavailability on stored properties" without Fix-It
For now, disallow potential unavailability on stored properties. We will
eventually want to support this. Unfortunately, doing so will require changes to
definite initialization and (probably) deinitialization.

This is the same as the reverted r27216 except that it does not suggest a FixIt
to make the property lazy.

Swift SVN r27223
2015-04-10 23:19:47 +00:00
Devin Coughlin
54475d66c3 Revert "Sema: Disallow potential unavailability on stored properties."
This reverts r27216. Jordan thinks suggesting a FixIt to make a stored property
lazy is too big of a semantic change.

Swift SVN r27222
2015-04-10 23:19:46 +00:00
Devin Coughlin
38463fac83 Sema: Disallow potential unavailability on stored properties.
For now, disallow potential unavailability on stored properties. We will
eventually want to support this. Unfortunately, doing so will require changes to
definite initialization and (probably) deinitialization.

We can safely support potential unavailability on lazily initialized
properties (and statics), so suggest a Fix-It that adds a lazy attribute when
the property declaration allows for it.

Swift SVN r27216
2015-04-10 22:17:03 +00:00
Joe Groff
7612df1918 Runtime: Rename 'becomeNSError' to 'bridgeErrorTypeToNSError'.
We may want to use optimized ErrorType representations that don't naturally "become" NSErrors, such as tagged-pointer representations of small error enums, or a tagged function pointer to a deferred error type constructor. Rename the runtime function to something a bit more descriptive of its real purpose, not its implementation.

Swift SVN r27209
2015-04-10 17:37:40 +00:00
Devin Coughlin
53fd9fb59c Sema: Finish staging back in availability checking in synthesized functions
Remove the suppression of deprecation and potential unavailability diagnostics in
synthesized functions. We still suppress some explicit unavailability diagnostics -- those
in synthesized functions in synthesized functions that are lexically contained in
declarations that are themselves annotated as unavailable. For these cases, the right
solution <rdar://problem/20491640> is to not synthesize the bodies of these functions in
the first place.

rdar://problem/20024980

Swift SVN r27203
2015-04-10 05:19:04 +00:00
Devin Coughlin
cd79e0ba4d Sema: Suppress explicit unavailability diagnostics in unavailable synthesized functions.
Suppress diagnostics about references to unavailable declarations when all
of the following conditions are met:

(1) the reference is in synthesized code;
(2) the reference is in a synthesized method; and
(3) the reference is inside a declaration marked as unavailable.

This, combined with prior work to infer availability annotations for synthesized
methods should eliminate the spurious diagnostics we have seen (e.g.,
rdar://problem/20154926) for references to unavailable types without the hammer
of suppressing all references to unavailable declarations in synthesized
functions. The right thing to do here is to not synthesize the bodies of these
functions in the first place. I've filed <rdar://problem/20491640> to track
this.

We will continue to emit an error for references to unavailable declarations
in non-implicit code, even if the reference is inside a declaration marked
unavailable.

Swift SVN r27197
2015-04-10 02:07:24 +00:00
Doug Gregor
5f4bea74e1 Open existential uses of dynamic-Self methods and initializers in the constraint solver.
Previously, we were only opening the existentials as part of
constraint application, which involved some ugly, redundant code. This
should be NFC because it's just moving the existential opening
operation earlier, but it's a step toward opening up all existential
references.

Swift SVN r27190
2015-04-09 23:58:55 +00:00
Doug Gregor
85b89ba112 Tighten up our handling of erasure of opened existentials. NFC
Swift SVN r27189
2015-04-09 23:58:54 +00:00
Devin Coughlin
d61dd21bfe Fix 80-column and indentation violations. NFC.
Swift SVN r27184
2015-04-09 22:20:24 +00:00
Devin Coughlin
8c50f67120 Sema: Factor out common logic for finding enclosing declaration availability
A common operation for availability checking is determining whether some
lexically enclosing declaration matches a condition. This commit factors
out that logic. NFC.

Swift SVN r27181
2015-04-09 21:56:22 +00:00
Roman Levenstein
d1698ba1cb Use a _bridgeable suffix for newly introduced fast bridging functions. NFC.
Dave explained that stdlib usually uses the suffix notation in such cases. This change follows his advice.

Swift SVN r27177
2015-04-09 20:59:42 +00:00
Doug Gregor
762d1d9474 Opened existential metatypes always involve members.
Swift SVN r27172
2015-04-09 18:09:04 +00:00
Doug Gregor
7fc1ac61ab Revert "Kill the sequence number in OpenedExistential."
This reverts r27106; we're going to need this for recovery.

Swift SVN r27170
2015-04-09 15:51:03 +00:00
Doug Gregor
6755aaf6b9 Revert "Simplify constraint application now that open-existentials are more local."
This reverts r27107; we're going to need this code for recovery.

Swift SVN r27169
2015-04-09 15:51:01 +00:00
Joe Pamer
e4f7fee4f4 When gathering "linked" expressions to determine a favored constraint, consider top-level literals to be fair game.
This unblocks standard library work by preventing us from going exponential when extending existing struct types to have failable initializers. (rdar://problem/20336356)
On my laptop, it also results in a 7% end-to-end improvement in the time it takes to run our unit tests under DebugAssert (previously: 591.63s, now: 552.64s). Though, as usual, YMMV.

Swift SVN r27156
2015-04-09 01:54:34 +00:00
Devin Coughlin
e6344938c3 Sema: Disallow potential unavailability on script-mode globals
In source files that are in script mode, global variable initialization
expressions are eagerly executed. For this reason, disallow @availability
attributes having 'introduced=' on script-mode globals.

I had to rejigger a fair number of potential unavailability tests because they
weren't written with this distinction in mind.

Swift SVN r27137
2015-04-08 21:29:14 +00:00
Chris Lattner
72312b972a reject refutable PBD's in non-local contexts. They are only allowed in
function bodies, top level code, closures, etc, not as properties.


Swift SVN r27115
2015-04-08 00:58:37 +00:00
Doug Gregor
d6dad48548 Simplify constraint application now that open-existentials are more local.
Remove some unnecessary boilerplate when working with ExprRewriter and
eliminate some closeExistential() call sites that are no longer
useful. NFC.

Swift SVN r27107
2015-04-07 23:22:06 +00:00
Doug Gregor
26ffdc7ace Kill the sequence number in OpenedExistential.
Because we're binding opened existentials early now, we no longer need
to be able to sort them to bind them late. NFC

Swift SVN r27106
2015-04-07 23:22:05 +00:00
Doug Gregor
595fb8c94f Introduce lvalue open-existential expressions and start using them.
Place OpenExistentialExprs for references to lvalue subscripts or properties
(in protocol extensions) via existentials just outside of the member
or subscript reference, rather than far outside the expression. This
gives us a tighter bound on the open-existential expressions without
introducing the post-pass I was threatening.

OpenExistentialExprs just outside of lvalue member/subscript are
themselves lvalues. Resurrect John's OpenOpaqueExistentialComponent to
handle the opening of a (materialized) existential lvalues as an
lvalue path component. This has the nice effect of codifying the
formal access rules for opened existentials as well as handling inout
on opened existentials appropriately.

Big thanks to John for talking through the model with me and leaving
dead code around for me to use.

Swift SVN r27105
2015-04-07 23:22:05 +00:00
Roman Levenstein
a762fb2b94 Teach bridgeFromObjectiveC to make use of the knownConditionallyBridgeFromObjectiveC/knownForceBridgeFromObjectiveC
If a conformance to _BridgedToObjectiveC is statically known, generate a more efficient code by using the newly introduced library functions for bridging casts.
This covers the cases arising from the source code, but does not cover any casts resulting from SIL optimizations. Those will be covered by the subsequent commit.

This change is to stay in CSApply for now. But the plan is to make the bridged casts optimization a guaranteed optimization. Once it is done, there is no need to lower the bridged casts in a special way inside Sema, because they all can be handled by the optimizer in a uniform way. This would apply to bridging of Error types too.

Swift SVN r27101
2015-04-07 22:53:56 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Doug Gregor
82f634624c Handle uses of mutating methods of protocol extensions on existentials.
To properly deal with mutating methods on protocol extensions accessed through an existential (such as a property or subscript setter), open the existential as an lvalue so that its value can be mutated. 

As part of this, make sure we form any OpenExistentialExprs at the top level of the expression if we didn't manage to build them sooner. This is a fairly ad hoc approach that I am not happy with (these could probably be placed better with a post-pass), but the cost of opening too early is fairly minimal.

Swift SVN r27068
2015-04-07 06:01:19 +00:00
Doug Gregor
5406878a7f Don't synthesize materializeForSet for members of protocol extensions.
They aren't dynamically dispatched contexts.

Swift SVN r27067
2015-04-07 06:01:17 +00:00
Doug Gregor
cdd5850707 Simplify the tracking of opened existentials in CSApply. NFC
Swift SVN r27065
2015-04-07 06:01:15 +00:00
Doug Gregor
7d6f2accd9 Improve use of properties/subscripts of protocol extensions via existentials.
Improves the placement of open-existential expressions when accessing
a property or subscript declared in a protocol extension. We need to
delay until the load occurs when the property/subscript has a usable
setter.

Swift SVN r27064
2015-04-07 06:01:14 +00:00
Jordan Rose
182ef27f95 [ClangImporter] Handle __attribute__((availability(swift, unavailable))).
This is the new and improved version of
__attribute__((annotate("swift1_unavailable"))), with the "improved" being
specifically that the 'availability' attribute supports a message.

This requires a corresponding Clang commit.

Swift side of rdar://problem/18768673.

Swift SVN r27053
2015-04-07 02:40:22 +00:00
Chris Willmore
d3a977d824 <rdar://problem/20402026> Remove scope entry/exit log entries
Don't emit scope entry/exit logging code in instrumentation for
playgrounds if -playground-high-performance option is passed.

Swift SVN r27046
2015-04-06 22:09:20 +00:00
Joe Groff
56de5fb95e SIL: Drop unnecessary bits from SILFunctionType::ExtInfo.
"Autoclosure" is uninteresting to SIL. "noescape" isn't currently used by SIL and we shouldn't have it until it has a meaningful effect on SIL. "throws" should be adequately represented by a SIL function type having an error result.

Swift SVN r27023
2015-04-05 17:35:28 +00:00
Joe Groff
4821f594bb SIL: Separate SILFunctionType::Representation and ExtInfo from AST FunctionTypes.
The set of attributes that make sense at the AST level is increasingly divergent from those at the SIL level, so it doesn't really make sense for these to be the same. It'll also help prevent us from accidental unwanted propagation of attributes from the AST to SIL, which has caused bugs in the past. For staging purposes, start off with SILFunctionType's versions exactly the same as the FunctionType versions, which necessitates some ugly glue code but minimizes the potential disruption.

Swift SVN r27022
2015-04-05 17:04:55 +00:00
Chris Lattner
fb87132f72 significantly simplify the BoolPattern AST representation and logic surrounding it.
The SILGen code could be further simplified, but this is progress at least.  NFC.


Swift SVN r27011
2015-04-05 04:52:38 +00:00
Chris Lattner
93198d4b92 rework type checking of 'else' blocks in let/else so that we know the enclosing
funcdecl in the right cases, enabling the use of 'return' in the else.



Swift SVN r27007
2015-04-05 04:01:06 +00:00
Devin Coughlin
bbdcf580ee Sema: Add @availability attributes when synthesizing materializeForSet accessors.
Synthesize implicit @availability attributes to make sure that a synthesized
materializeForSet accessor is available enough to access the underlying storage and its
getter and setter.

These synthesized attributes could trigger redundant diagnostics when a subclass gives
overriding getters or setters non-contravariant availability. We detect when this
happens and suppress the redundant diagnostics.

This commit also improves availability diagnostics in synthesized code. We now respect
synthesized @availability annotations on containing DeclContexts when determining the
potential OS versions that could be executed at invalid SourceLocations.

Swift SVN r27002
2015-04-05 03:02:20 +00:00
Devin Coughlin
8b5f6fec60 Rename '#os' to '#available'
The API review list found it confusing that if #os() and #if os() looked so similar, so
change the availability checking query to be spelled #available:

if #available(iOS >= 9.0, *) {
  ...
}

Swift SVN r26995
2015-04-04 23:33:13 +00:00
Joe Groff
66ae68bcc3 Sema: Allow ErrorType-conforming types to be explicitly coerced 'as NSError'.
Swift SVN r26993
2015-04-04 22:38:04 +00:00
Joe Groff
a15d93ff09 Sema: Handle ErrorType synthesis for empty enums.
A "switch" can't be empty, so special-case the 'code' implementation for an empty ErrorType to just return zero. It doesn't really matter what the value is since the enum can't be instantiated.

Swift SVN r26992
2015-04-04 22:37:59 +00:00
Chris Lattner
eb922cd0c2 type check the 'else' body of a let/else.
Swift SVN r26989
2015-04-04 21:30:52 +00:00