Commit Graph

431 Commits

Author SHA1 Message Date
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
Doug Gregor
37df5c430c Update standard library to use [T] array syntax.
Swift SVN r19190
2014-06-25 23:39:20 +00:00
Dmitri Hrybenko
6bb6e1b0b4 stdlib/String: if we can not get a contiguous data buffer out of NSString,
don't call into CoreFoundation to perform UTF-8 transcoding.  CoreFoundation
can replace ill-formed sequences with a single byte, which is not good enough
to implement U+FFFD insertion.  Instead, use the same transcoding routine as
for contiguous buffer.

Pulled out the transcoding routine into a generic function that should be
specialized and simplified for the case when input is UnsafeArray; we should
not be losing efficiency here.

Fixes <rdar://problem/17297055> [unicode] println crashes when given string
with unpaired surrogate



Swift SVN r19157
2014-06-25 13:24:15 +00:00
Jordan Rose
cca27d02a0 Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports
than the average target, and that this contains ALL of them at once.
I also deliberately tried to tag nearly every top-level decl, even if that
was just to explicitly mark things @internal, to make sure I didn't miss
something.

This does export more than we might want to, mostly for protocol conformance
reasons, along with our simple-but-limiting typealias rule. I tried to also
mark things private where possible, but it's really going to be up to the
standard library owners to get this right. This is also only validated
against top-level access control; I haven't fully tested against member-level
access control yet, and none of our semantic restrictions are in place.

Along the way I also noticed bits of stdlib cruft; to keep this patch
understandable, I didn't change any of them.

Swift SVN r19145
2014-06-24 21:32:18 +00:00
Enrico Granata
2ab2e6c07b Change the very cryptic "don't ask" to something more informative
Fixes <rdar://problem/16922703>



Swift SVN r19123
2014-06-24 01:50:02 +00:00
Chris Hanson
5b9b67e900 Revert "Remove XCTest overlay"
We need to actually keep the XCTest support in an overlay for now.

This reverts commit 4a2726862634a553483943baf39a251ac8071e37.

Addresses <rdar://problem/17423669>.

Swift SVN r19101
2014-06-23 21:00:47 +00:00
Doug Gregor
22dc55058e Make bridgeFromObjectiveC return non-optional.
Now that we use bridgeFromObjectiveCConditional to perform conditional
bridging, make bridgeFromObjectiveC handle forced bridging. For the
latter, deferred checking is acceptable.

Almost all of <rdar://problem/17319154>.


Swift SVN r19046
2014-06-20 13:15:41 +00:00
Dmitri Hrybenko
f370ca0746 stdlib: fix a bunch of various Unicode issues, primarily in UTF-8 decoding
In UTF-8 decoder:
- implement U+FFFD insertion according to the recommendation given in the
  Unicode spec.  This required changing the decoder to become stateful, which
  significantly increased complexity due to the need to maintain an internal
  buffer.
- reject invalid code unit sequences properly instead of crashing rdar://16767868
- reject overlong sequences rdar://16767911

In stdlib:
- change APIs that assume that UTF decoding can never fail to account for
  possibility of errors
- fix a bug in UnicodeScalarView that could cause a crash during backward
  iteration if U+8000 is present in the string
- allow noncharacters in UnicodeScalar.  They are explicitly allowed in the
  definition of "Unicode scalar" in the specification.  Disallowing noncharacters
  in UnicodeScalar prevents actually using these scalar values as internal
  special values during string processing, which is exactly the reason why they
  are reserved in the first place.
- fix a crash in String.fromCString() that could happen if it was passed a null
  pointer

In Lexer:
- allow noncharacters in string literals.  These Unicode scalar values are not
  allowed to be exchanged externally, but it is totally reasonable to have them
  in literals as long as they don't escape the program.  For example, using
  U+FFFF as a delimiter and then calling str.split("\uffff") is completely
  reasonable.

This is a lot of changes in a single commit; the primary reason why they are
lumped together is the need to change stdlib APIs to account for the
possibility of UTF decoding failure, and this has long-reaching effects
throughout stdlib where these APIs are used.


Swift SVN r19045
2014-06-20 13:07:40 +00:00
Doug Gregor
fd62de4373 Use bridgeFromObjectiveCConditional where we want conditional bridging.
More of <rdar://problem/17319154>.


Swift SVN r19038
2014-06-20 07:41:50 +00:00
Chris Hanson
7d1cf3d107 Remove XCTest overlay
The XCTest support for Swift is now built as part of XCTest.framework
itself, so the overlay is no longer necessary.

Addresses <rdar://problem/17383462>.

Swift SVN r19016
2014-06-19 22:08:52 +00:00
Doug Gregor
2e3863b211 Introduce _ConditionallyBridgedToObjectiveC.bridgeFromObjectiveCConditional.
This entry point is used in conditional downcasts (as?) to attempt to
bridge from an Objective-C class down to a specific native type (e.g.,
array, dictionary), bridging all elements eagerly so that it can
produce nil if the bridging would fail.

This is the scaffolding for <rdar://problem/17319154>, and makes the
example there work, but there is much more cleanup and optimization to
do.



Swift SVN r18999
2014-06-19 14:48:00 +00:00
Chris Lattner
62cad3dce8 add a "..<" operator, which is an alias for ".." and switch the stdlib to use it.
Until I have a chance to update the testsuite, we'll accept both.



Swift SVN r18998
2014-06-19 05:42:29 +00:00
Pete Cooper
653a9d2d99 Create builtin's for math functions exposed as LLVM intrinsics. Use these builtin's in the wrappers for functions such as sqrt(Float) and cos(Double). rdar://problem/16709244
Swift SVN r18968
2014-06-18 00:27:13 +00:00
Ted Kremenek
7d5a8aa5cc Use 'NSColor' instead of 'AnyObject' in argument to 'init' with 'colorsAndLocations'.
Swift SVN r18950
2014-06-17 07:01:17 +00:00
Doug Gregor
c19b92e4b3 Rename array downcast entry points to have "conditional" in the name.
s/_arrayCheckedDownCast/_arrayDownCastConditional/g
s/_arrayBridgeFromObjectiveC/_arrayBridgeFromObjectiveCConditional/g



Swift SVN r18930
2014-06-16 15:06:04 +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
Chris Lattner
371efa74d7 r18747 (which changed how we import macros that expand to nil) regressed on some GCD macros that are widely
used.  Fix this by adding them to the GCD overlay.  A more general solution is tracked in rdar://17245039,
but that isn't on the critical path right now.


Swift SVN r18916
2014-06-15 20:44:57 +00:00
Doug Gregor
b039880a01 Revert r18906 "Make Dictionary bridgeFromObjectiveC return nil if bridging fails" while we discuss it.
Swift SVN r18908
2014-06-15 16:59:25 +00:00
Doug Gregor
dd8c668aa8 Import NSDictionary as Dictionary<NSObject, AnyObject>
Fixes <rdar://problem/16870626>.


Swift SVN r18907
2014-06-15 10:44:23 +00:00
Doug Gregor
d3d2092ac0 Make Dictionary bridgeFromObjectiveC return nil if bridging fails.
This allows conditional downcasting (e.g., via as? or is) to fail
without trapping. Noticed by inspection.


Swift SVN r18906
2014-06-15 08:53:22 +00:00
Jordan Rose
5f4db71fc5 Remove KVOContext from the Foundation overlay.
We're recommending people just go with a global variable.

<rdar://problem/17272837>

Swift SVN r18837
2014-06-12 19:55:45 +00:00
Greg Parker
fc3794d7e9 <rdar://16978397> Overlay most of the rest of math.h.
Swift SVN r18821
2014-06-12 01:48:00 +00:00
Greg Parker
8548760762 <rdar://16978397> Add overlays for most of tgmath.h.
Swift SVN r18808
2014-06-11 21:56:25 +00:00
Greg Parker
50404f6210 Fix build break in UIViewControllerAdditions.
Swift SVN r18779
2014-06-10 06:16:00 +00:00
Greg Parker
4f467b72f5 Fix build break in XCTest.
Swift SVN r18778
2014-06-10 05:36:31 +00:00
Greg Parker
4880bceda2 <rdar://17086151> Add overlays for open(), openat(), and struct stat.
Swift SVN r18777
2014-06-10 02:43:26 +00:00
Greg Parker
dc5f3c2090 <rdar://16878510> Add definitions of stdin/stdout/stderr to the Darwin overlay.
Swift SVN r18766
2014-06-10 00:33:02 +00:00
Dmitri Hrybenko
a69e341aa2 stdlib/NSString APIs on String: fix a bug and add tests for
rangeOfCharacterFromSet(_:options:range:)

The underlying Objective-C API could return an NSRange of NSNotFound.  Swift's
String.Index can not represent that, so change the API to return an optional
Swift Range<Index> instead.


Swift SVN r18679
2014-05-30 23:07:21 +00:00
Dmitri Hrybenko
df71a47fe4 stdlib/NSString APIs on String: fix two bugs and add more tests
stringWithBytes(_:length:encoding:) was passing an array to Objective-C
incorrectly, and a garbage NSString was being constructed as a result.

Unhide the initializer was accidentally hidden.


Swift SVN r18674
2014-05-30 20:30:57 +00:00
Dmitri Hrybenko
ea7758f40d stdlib/String: implement UTF-8 encoding for Strings that wrap NSStrings for
which Foundation can not give us a UTF-8 encoding in O(1)

rdar://17041741


Swift SVN r18660
2014-05-29 00:41:42 +00:00
Enrico Granata
c44731ac31 B&I updated the builders to a new iOS SDK - the new SDK means that the Unmanaged<> is unwrapped automatically on our behalf
This patch is required to unbreak the build



Swift SVN r18651
2014-05-27 23:53:26 +00:00
Dmitri Hrybenko
470fee7838 stdlib: correct a comment to be more explicit that this is a hack
Swift SVN r18644
2014-05-26 23:49:50 +00:00
Enrico Granata
30341ed401 The B&I-sanctioned iOS SDK does not have the right annotations for this to be automatically unwrapped. The Graphics Context comes back to us as Unamanged<> and we need to manually extract the value out of it. Do so for now
Swift SVN r18643
2014-05-26 23:22:59 +00:00
Enrico Granata
3e1ed25aa7 Add a mirror for UIView
There are a couple caveats to this Mirror, discussed in detail in the radar

Fixes rdar://17029335



Swift SVN r18642
2014-05-26 20:26:57 +00:00
Dmitri Hrybenko
f179e4cbc0 stdlib/Foundation overlay: hide NSSimpleCString
rdar://17024122


Swift SVN r18636
2014-05-26 18:39:26 +00:00
Enrico Granata
0134c6d197 Allow user-defined Swift classes to implement our API for QuickLooks, and have the result of that API be picked up by the Mirrors
This is our public API for how quicklooks work in the debugger, and the plan is to have this same API work in playgrounds as well

Fixes rdar://17023157


Swift SVN r18609
2014-05-24 01:00:46 +00:00
Chris Hanson
3298bebb2c Make XCTestCase.className demangle its result.
XCTest needs a way to get the demangled name of a test case class,
so provide one by overriding NSObject.className.

Addresses <rdar://problem/17010812>.

Swift SVN r18606
2014-05-23 22:07:29 +00:00
Dmitri Hrybenko
fce7a8c4ff stdlib/NSString APIs on String: dataUsingEncoding:allowLossyConversion: can
return nil, change our API and add tests


Swift SVN r18597
2014-05-23 16:38:53 +00:00
Dmitri Hrybenko
c5f21546db stdlib/CString: fix two issues with CString.persist():
1. it crashed on a null pointer;

2. it crashed on a non-ASCII strings.

rdar://17016284


Swift SVN r18594
2014-05-23 15:18:21 +00:00
Dmitri Hrybenko
04dae74cd6 stdlib: correct comment
Swift SVN r18592
2014-05-23 13:07:46 +00:00
Dmitri Hrybenko
83f7bdc30e stdlib/NSString APIs for String: allow a nil locale to be passed to
capitalizedStringWithLocale(_:)


Swift SVN r18591
2014-05-23 09:51:30 +00:00
Doug Gregor
f305cd7946 Look through bridgeFromObjectiveC calls to find forced casts within optional injections.
Fixes <rdar://problem/17003302>.


Swift SVN r18563
2014-05-22 15:47:13 +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
Dave Abrahams
0f9edadc41 [stdlib] String API Review: NSString API
Many changes in how we're presenting the NSString APIs on String, most
notably that we now traffic in String.Index and Range<String.Index>
rather than Int and NSRange.  Also we present NSString initializers that
can fail only as factory functions, and factory functions that can't
fail only as init functions.

About 25% of the API changes here have been reviewd by the Foundation
guys, and testing is, as it has always been, admittedly spotty.  Dmitri
is going to be writing some more comprehensive tests.

Swift SVN r18553
2014-05-22 04:21:55 +00:00
Joe Pamer
1d34a88477 Revert "Fix two problems with implicit conversions: - rdar://problem/16776273, wherein conversions between nil and .None were permitted due to an implicit conversion between nil and COpaquePointer. - rdar://problem/16877526, where we needed to add new equality overloads to handle conversions between nil and .None given the supression of user conversions. (Thanks to Ted for the overloads and test.)"
This reverts commit r18473.

Swift SVN r18477
2014-05-21 00:28:46 +00:00
Joe Pamer
f469d8f1f6 Fix two problems with implicit conversions:
- rdar://problem/16776273, wherein conversions between nil and .None were permitted
due to an implicit conversion between nil and COpaquePointer.
- rdar://problem/16877526, where we needed to add new equality overloads to handle
conversions between nil and .None given the supression of user conversions.
(Thanks to Ted for the overloads and test.)

Swift SVN r18473
2014-05-20 23:53:34 +00:00
Greg Parker
e2ca13c993 <rdar://16529903> Make UIViewController's nib search find Swift class names.
UIViewController is able to find nib files that have names derived from the 
UIViewController subclass's name. This change modifies UIViewController's 
lookup so it is able to find nib files for Swift class names.


Swift SVN r18470
2014-05-20 23:14:52 +00:00
Dmitri Hrybenko
8910632338 stdlib/Dictionary: allow NSDictionary to be bridged to Dictionary<K, V> non-verbatim
Dictionary's isBridgedToObjectiveC() was overly restrictive.  This went
unnoticed because the tests were using internal Dictionary APIs to construct
the desired state, instead of going thourgh casts.

rdar://16973429


Swift SVN r18454
2014-05-20 16:06:52 +00:00
Doug Gregor
5c532d6111 Introduce a fast path for Array.bridgeFromObjectiveC()
We were using the bridged non-verbatim path
(_arrayBridgeFromObjectiveC) for bridged-verbatim types. While that
path can do the right thing (and does when the standard library's
internal checking is turned off), it's unnecessarily inefficient.

Swift SVN r18418
2014-05-19 14:18:39 +00:00
Doug Gregor
57f75b7448 Implement bridging from NSNumber to Int/UInt/Float/Double/Bool.
This makes fun bridging like

  var obj: AnyObject! = [3.14159, 2.71828, 0] as Double[]
  if let intArr = obj as Int[] {
    println("Array of doubles as ints is \(intArr)")
  }

"work", given that NSNumber is the common class type through which we
are bridging.




Swift SVN r18398
2014-05-19 07:33:15 +00:00