Commit Graph

4105 Commits

Author SHA1 Message Date
Joe Groff
f0c2ce454d Sema: Reject objc-ness in extensions to CF types.
CF types don't have real class objects (yet...), so there's nowhere to introduce ObjC metadata for methods or protocol conformance. Let's reject them in Sema. It's still reasonable to extend CF types with pure Swift methods, and this works now. <rdar://problem/17569520>

Swift SVN r19589
2014-07-07 00:03:35 +00:00
Jordan Rose
19e0ce96a0 [Accessibility] Public classes may not have private superclasses.
In theory there's nothing wrong with this, but it makes it hard to see what
operations a class supports, and there's no obvious way to go to its nearest
public superclass.

Note that we have a similar issue with protocols, since private protocols can
refine public protocols, and then public classes can conform to private
protocols---the indirect conformance won't be listed in the inheritance
clause, but it is a public conformance nonetheless.

Swift SVN r19588
2014-07-06 22:23:06 +00:00
Jordan Rose
4c438ec5d0 [Accessibility] A public enum cannot have a private raw type.
While this could be useful, a raw type implies a conformance to
RawRepresentable, and private methods cannot be used to satisfy conformances
of public types to public protocols.

Swift SVN r19587
2014-07-06 22:07:29 +00:00
Jordan Rose
0fac468f47 [Accessibility] Public protocols cannot refine private protocols.
Otherwise, how is an implementer to know all the requirements?

Swift SVN r19584
2014-07-06 20:44:31 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Jordan Rose
40e9cd8e43 Check 'public(set)' modifiers a little more.
- Setters cannot (in this release) have more accessibility than getters.
- The modifiers don't make sense for constants and read-only vars/subscripts.

Swift SVN r19548
2014-07-04 01:53:48 +00:00
Jordan Rose
8080ca6820 [Accessibility] Public functions/initializers may not use private types.
Also, don't diagnose accessibility violations on implicit decls. Every now
and then the compiler needs to bend the rules, such as when providing an ==
implementation for a local enum.

Swift SVN r19519
2014-07-03 17:45:36 +00:00
Argyrios Kyrtzidis
234a79ae32 [Sema] Correct the text of a diagnostic.
Swift SVN r19518
2014-07-03 17:18:26 +00:00
Jordan Rose
43ca8fcd83 [Accessibility] Check requirements and default definitions of associated types.
We could actually allow the default definition of an associated type to have
less accessibility than the requirement, but then we'd also have to check
that that type wasn't being used where it wasn't accessible. Since we infer
associated types anyway, it's probably not worth it.

Swift SVN r19493
2014-07-02 23:54:51 +00:00
Manman Ren
2b2330bf5b [attribute] rename @noinline to @inline(never).
Add support for parsing inline(never), it can be easily expanded to
handle inline(always).

rdar://17527111


Swift SVN r19447
2014-07-02 01:27:05 +00:00
Jordan Rose
62a96d7ff4 [Accessibility] Check the index and element types of subscripts.
Swift SVN r19446
2014-07-02 01:07:30 +00:00
Jordan Rose
169238e146 [Accessibility] Check type accessibility for variables with inferred types.
We'd rather check the explicit type, because we can give a better diagnostic,
but we still need to check inferred types as well.

Swift SVN r19438
2014-07-01 23:42:06 +00:00
Jordan Rose
3412be23bf [Accessibility] Collapse two diagnostics into one, and drop the typealias name.
The diagnostic is printed at the declaration site; it's obvious which
typealias it is.

Swift SVN r19437
2014-07-01 23:42:05 +00:00
Jordan Rose
f746b8c6dd [Accessibility] Public variables cannot have private types.
This does not yet handle variables with inferred types, since those don't
have TypePatterns.

There is some nasty propagation of @public into the stdlib because of this
one, mainly because Foundation needs access to some of the implementation
details of Array and Dictionary. We may want to try to improve this later
(or just build Foundation with -disable-access-control if it comes to that).

Swift SVN r19432
2014-07-01 22:30:53 +00:00
Jordan Rose
f13a5af044 [Accessibility] A typealias cannot be more accessible than its underlying type.
This actually lays the groundwork for checking the TypeLocs for all sorts
of decls, but let's start with typealiases.

Swift SVN r19428
2014-07-01 20:46:30 +00:00
Jordan Rose
d545ac1623 [Accessibility] @required initializers must be as accessible as the type.
Swift SVN r19383
2014-06-30 23:38:36 +00:00
Jordan Rose
748efed913 [Accessibility] Protocol witnesses must be as accessible as the protocol.
...unless the type has less accessibility than the protocol, in which case
they must be as accessible as the type.

This restriction applies even with access control checking disabled, but
shouldn't affect any decls not already marked with access control modifiers.

Swift SVN r19382
2014-06-30 23:38:35 +00:00
Chris Lattner
4c09cc591a implement rdar://17501765 - Swift should warn about immutable default initialized values
Swift SVN r19342
2014-06-30 15:33:28 +00:00
Doug Gregor
5a08a69ebc Remove NewArrayExpr entirely; reject "new" expressions in the parser.
Swift SVN r19293
2014-06-27 15:57:48 +00:00
Doug Gregor
f0159f40a1 Ban the "new" syntax for creating an array <rdar://problem/16951969>.
We haven't been advertising this syntax much, and it's closure form
was completely broken anyway, so don't jump through hoops to provide
great Fix-Its here. 


Swift SVN r19277
2014-06-26 23:51:47 +00:00
Doug Gregor
55ca3b01f3 Parse dictionary type sugar [K : V].
Handle parsing of dictionary type sugar into its own type
representation, including both type and expression contexts.

This is the first part of <rdar://problem/17460972>; we still need a
sugared Type node.


Swift SVN r19239
2014-06-26 16:57:42 +00:00
Joe Groff
a87e9fa40c Make the diagnostic for unsupported existentials more accurate and helpful.
Better to describe how the protocol can be used than how it can't. Also include a mention of Self type requirements as a source of non-existentiability.

Swift SVN r19207
2014-06-26 01:02:03 +00:00
Ted Kremenek
c91ffb63a5 Tweak "is unavailable" diagnostic to include full declaration name.
This makes many of the diagnostics far more useful for diagnosing
what is really unavailable.

Swift SVN r19201
2014-06-26 00:50:41 +00:00
Manman Ren
863138ead7 [noinline diagnostic] allow noinline on Func Decl only.
Also move noinline attribute to use the new infrastructure i.e SIMPLE_DECL_ATTR,
per feedback from Dmitri.

rdar://15882816


Swift SVN r19188
2014-06-25 23:17:43 +00:00
Jordan Rose
f6912b431b Validate which decls can have accessibility attributes.
Swift SVN r19141
2014-06-24 21:32:06 +00:00
Ted Kremenek
5ddc49da83 Change '@objc' to require importing 'Foundation', not just 'ObjectiveC'.
Implements <rdar://problem/16466543>.

Swift SVN r19128
2014-06-24 06:04:20 +00:00
Jordan Rose
db3914e94b Disallow conforming to ObjC protocols with requirements that can't be imported.
For example, variadic ObjC method requirements.

<rdar://problem/17366999>

Swift SVN r19121
2014-06-24 01:23:06 +00:00
Jordan Rose
c6226159c5 Allow class properties to be @objc, and expose them as class methods.
<rdar://problem/17164696>

Swift SVN r19117
2014-06-24 01:23:02 +00:00
Joe Groff
954f746b92 SILGen: Implement pointer-to-pointer conversions.
Perform pointer-to-pointer argument conversions with the help of the _convertPointerToPointerArgument stdlib helper function.

Swift SVN r19105
2014-06-23 23:22:02 +00:00
Doug Gregor
2b8923e3ef Allow "isa" patterns to downcast collections and bridge through Objective-C classes.
When checking an isa pattern that requires either collection
downcasting or bridging through an Objective-C class (e.g., 
"is String" or "is Dictionary<String, Int>"), form a conditional
downcast and place it in an expression pattern.

With this change, we can test for these cases (with "is") but we can't
capture the value produced on success (e.g., for "let str as
String"). This is a first small step toward <rdar://problem/17408934>.


Swift SVN r19070
2014-06-21 22:46:15 +00:00
Chris Lattner
91e658488a fix <rdar://problem/17200672> Let in protocol causes unclear errors and crashes
We were correctly rejecting 'let' decls in a protocol if it had a get/set specifier,
but not if a stored let.


Swift SVN r19034
2014-06-20 05:08:54 +00:00
Jordan Rose
727a7eb77a Attributes: Use class names in the DAK_* enum instead of attribute spellings.
This allows for single attributes that can be spelled multiple ways.
No functionality change.

Swift SVN r18993
2014-06-18 23:28:28 +00:00
Joe Groff
5c09ca5ee5 Sema: Don't allow protocols to be used as non-self-conforming existential types.
These types are often useless and confusing to users who expect to be able to use Sequence or Generator as types in their own right like in C# or Java. While we're here, relax the rules for self-conformance to admit methods returning 'Self'. Covariant return types should not actually prevent a protocol type from conforming to itself, and the stdlib makes particular use of protocols with 'init' requirements which implicitly return Self.

Swift SVN r18989
2014-06-18 23:01:55 +00:00
Chris Lattner
60fc0e6cd2 Implement <rdar://problem/16951729> nil should be a literal type
This is all goodness, and eliminates a major source of implicit conversions.
One thing this regresses on though, is that we now reject "x == nil" where
x is an option type and the element of the optional is not Equtatable.  If
this is important, there are ways to enable this, but directly testing it as
a logic value is more straight-forward.

This does not include support for pattern matching against nil, that will be
a follow on patch.



Swift SVN r18918
2014-06-15 22:59:03 +00:00
Joe Groff
ac903bf943 IRGen: Make our use of spare bits in heap objects tagged-pointer-safe.
Don't use spare bits on platforms that use ObjC tagged pointers when an enum payload involves a class-constrained existential, archetype, or ObjC-defined class type. If a payload is of a Swift-defined class type, we can still assume it's a real pointer and use its spare bits. Add an @unsafe_no_objc_tagged_pointer attribute that can be applied to protocols to denote that existentials bounded by that protocol can use spare bits; this is necessary to preserve the layout of bridged Array and Dictionary types, which should not be bound to tagged pointer types in practice (fingers crossed). Fixes <rdar://problem/16270219>.

Swift SVN r18781
2014-06-10 17:07:47 +00:00
Jordan Rose
02ef6d6554 Update the "missing SDK" note now that the compiler is almost always in Xcode.
"xcrun -sdk macosx swift" is much easier than
"swift -sdk $(xcrun --show-sdk-path --sdk macosx)"

Swift SVN r18758
2014-06-09 21:29:08 +00:00
Doug Gregor
8fa087311c Allow parentheses to suppress the "forced downcast will never produce nil" warning.
Addresses <rdar://problem/17017851>.


Swift SVN r18731
2014-06-06 06:13:47 +00:00
Doug Gregor
0476b98d98 Ban the use of "as?" to coerce one value to another; it only makes sense for checked casts.
Addresses <rdar://problem/17029506>.


Swift SVN r18730
2014-06-06 05:39:31 +00:00
Doug Gregor
fb2f72ab48 Eliminate type checker support for forced contextual downcasting via "expr!".
We removed this feature when we changed casting syntax, but left it in
the type checker to help migrate code via a Fix-It. We no longer need
it.



Swift SVN r18729
2014-06-06 05:10:15 +00:00
Doug Gregor
705a89ed3f Improve diagnostic for the "forced downcast" diagnostic.
Swift SVN r18630
2014-05-25 23:57:15 +00:00
Doug Gregor
c1de0bf27f Suggest "as T" rather than "!" for implicit downcast fixes <rdar://problem/17029454>.
Swift SVN r18626
2014-05-25 19:48:44 +00:00
Joe Pamer
c81e822ef5 Add some logic to the type checking process to prevent stack overflows while type checking certain kinds of self-referential declarations. This addresses rdar://problem/1641865, rdar://problem/16994520 and host of other radars that have been filed over the past several months.
Post-WWDC, we need to update the type checking process to make these kinds of infinite loops impossible without checking special flags.

Swift SVN r18598
2014-05-23 18:19:29 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Doug Gregor
9ca563e807 Reject casts to an implicitly unwrapped optional type.
This bans the syntax

  x as T!

because the user probably wanted "(x as T)!", but the parsing makes
more sense as "x as (T!)". When complaining about this syntax, provide
notes with Fix-Its for both parenthesizations, and recover as if the
user took the first one, which is by far more common. 

Addresses <rdar://problem/16952768>.


Swift SVN r18435
2014-05-19 22:40:21 +00:00
Joe Pamer
e4e472bf09 When emitting diagnostics for failed constraints, favor conformances with fewer unsubstituted type variables. (rdar://problem/16892723)
Swift SVN r18388
2014-05-19 04:29:15 +00:00
Jordan Rose
acda73702d @IBOutlet can only be applied to mutable properties.
Swift SVN r18373
2014-05-19 00:11:21 +00:00
Doug Gregor
5783d0b313 Revert r19185: Add T* syntactic sugar type for UnsafePointer<T>.
Swift SVN r18255
2014-05-17 16:43:46 +00:00
Doug Gregor
806daf3a87 Add T* syntactic sugar type for UnsafePointer<T>.
This is the basic plumbing for <rdar://problem/16912508>.


Swift SVN r18195
2014-05-16 15:30:26 +00:00
Chris Lattner
cf55f7edd5 fix:
<rdar://problem/16264989> property not mutable in closure inside of its willSet
and:
<rdar://problem/16826319> willSet immutability behavior is incorrect

by changing how we handle immutability of an observing property within its willSet.
Instead of trying to model it as an rvalue, just model it as an lvalue (which it is)
and diagnose the problem with a warning in MiscDiagnostics.



Swift SVN r18184
2014-05-16 06:32:33 +00:00
Joe Groff
b34abd4d8d Diagnose @objc_block types that aren't representable in ObjC.
We can't compile blocks that aren't representable in ObjC, and they wouldn't be very useful, so reject them. Fixes <rdar://problem/16746132>.

Swift SVN r18171
2014-05-16 04:19:32 +00:00