Commit Graph

108 Commits

Author SHA1 Message Date
Nate Cook
ca5c65f93c [stdlib] Nest some additional operators (#9646) 2017-05-17 19:44:08 -07:00
Roman Levenstein
29ad714bb7 Annotate stdlib functions to get a good performance even in resilient mode, when -sil-serialize-all is disabled
This commit mostly improves the performance of arrays and ranges.
It does not cover Strings, Dictionaries and Sets yet.
2017-03-16 19:46:11 -07:00
Slava Pestov
d6c857259d Sema: Diagnose @_fixed_layout when applied to internal types
This attribute is only meaningful for versioned and public types;
private and internal types are always fixed-layout.
2017-01-20 01:22:50 -08:00
Max Moiseev
b7d5ef90b8 Addressing PR comments 2017-01-10 14:30:44 -08:00
Max Moiseev
195691523f [stdlib] Eliminating some 'unsafeBitcast' related warnings 2017-01-10 12:36:22 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Nate Cook
7494e2045e [stdlib] Revise unsafe pointers documentation
This revises and expands upon documentation for the standard library's
unsafe pointer types. This includes typed and raw pointers and buffers,
the MemoryLayout type, and some other top-level functions.
2016-12-14 14:58:24 -06:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Doug Gregor
038558baf1 [Standard library] Address warnings. NFC 2016-11-01 23:10:04 -07:00
Joe Groff
b318763bb7 Add a builtin to generate the ObjC @encode string for a type.
We need the encode string to be able to construct NSValues using the core valueWithBytes:objCType: API. This builtin only works with concrete, @objc-representable types for now, which should be sufficient for a stdlib-internal API.
2016-09-19 11:14:01 -07:00
Joe Groff
2990847df2 stdlib: Add a _bridgeAnyObjectToAny helper.
We want to be robust against unexpected `nil`s when bringing `id`s into Swift as `Any`. Add a function that builds an AnyObject?-in-an-Any when we unexpectedly receive a nil.
2016-08-18 15:09:51 -07:00
Xiaodi Wu
f9435b9ce8 [stdlib] Restore MemoryLayout.*(ofValue:) 2016-08-08 10:46:37 -05:00
Rintaro Ishizaki
091506315b [SE-0101] Implement: Reconfiguring sizeof and related functions into MemoryLayout struct
As of now:

* old APIs are just marked as `deprecated` not `unavaiable`. To make it
  easier to co-operate with other toolchain repos.
* Value variant of API is implemented as public @private
  `_ofInstance(_:)`.
2016-07-30 03:09:28 +09:00
Andrew Trick
0b75ee975e Remove "illegal" UnsafePointer casts from the stdlib.
Update for SE-0107: UnsafeRawPointer

This adds a "mutating" initialize to UnsafePointer to make
Immutable -> Mutable conversions explicit.

These are quick fixes to stdlib, overlays, and test cases that are necessary
in order to remove arbitrary UnsafePointer conversions.

Many cases can be expressed better up by reworking the surrounding
code, but we first need a working starting point.
2016-07-28 20:42:23 -07:00
Joe Groff
2a5b9d6559 Remove now-dead _isBridgedToObjectiveC() declarations in _ObjectiveCBridgeable conformers. 2016-07-28 12:29:47 -07:00
Joe Groff
5d67dbb9bb stdlib: Use FIXME(ABI) tag for comment on transition API. 2016-07-27 13:21:06 -07:00
Andrew Trick
a18d490d6a Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3773)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 14:21:15 -07:00
Andrew Trick
0ed9ee8dee Revert "Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)"
This reverts commit ece0951924.

This results in lldb failues on linux that I can't readily debug.
Backing out until they can be resolved.
2016-07-26 02:50:57 -07:00
Andrew Trick
ece0951924 Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 02:18:21 -07:00
Joe Groff
10a0eb1c13 Merge pull request #3710 from jckarter/turn-on-id-as-any
Turn on id as any
2016-07-25 18:58:27 -07:00
Andrew Trick
3542ea3e68 Fix AutoreleasingUnsafeMutablePointer assignment. (#3727)
Fix the implementation to obey the memory model by
using `withMemoryRebound`.

Also move toward using `Unsafe` not `Opaque`.
2016-07-25 10:01:41 -07:00
Joe Groff
b1fb1fa3ea Runtime: Handle bridging from ObjC objects to Any or boxed types. 2016-07-25 06:01:21 -07:00
Joe Groff
32b50c624d stdlib: Remove _isBridgedToObjectiveC from _ObjectiveCBridgeable.
All generic bridgeable types can bridge for all their instantiations now. Removing this ferrets out some now-unnecessary traps that check for unbridgeable parameter types.
2016-07-25 06:01:21 -07:00
Patrick Pijnappel
2728bd0145 [stdlib] Standardize function signature spacing 2016-07-23 11:51:32 +10:00
Joe Groff
02640fc1bc Runtime: Look through existentials when bridging to id. 2016-07-12 19:21:13 -07:00
Slava Pestov
16f60d8064 SILGen: Add bridging support for id-as-Any.
- Previously we didn't know how to bridge address-only types.  Add some
  plumbing for this. Not fully general yet, but with a bit more work we
  could allow resilient value types to adopt _ObjectiveCBridgable, too.
  For now, this is just intended to support the id-as-Any work.

- Specifically when going from a type without any other known bridging
  strategy, emit a call to the new `_bridgeAnythingToObjectiveC` entry
  point from the previous commit.
2016-07-12 14:34:25 -07:00
Slava Pestov
67f7e773dd Runtime: Add preliminary _swift_bridgeUnknownToObject() entry point. 2016-07-12 13:49:39 -07:00
Dmitri Gribenko
d591f9cf7a stdlib: remove most uses of @warn_unused_result, which does nothing now
I kept the one on sorted(), because that one requires a less trivial
change.
2016-05-19 18:39:39 -07:00
Trent Nadeau
6e327b4ddb Updated stdlib to use @discardableResult and _ = . 2016-05-11 22:53:37 -04:00
John McCall
50d58b2732 Add a lot of calling-convention annotations to the standard library / runtime.
The general rule here is that something needs to be SWIFT_CC(swift)
if it's just declared in Swift code using _silgen_name, as opposed to
importing something via a header.

Of course, SWIFT_CC(swift) expands to nothing by default for now, and
I haven't made an effort yet to add the indirect-result / context
parameter ABI attributes.  This is just a best-effort first pass.

I also took the opportunity to shift a few files to just implement
their shims header and to demote a few things to be private stdlib
interfaces.
2016-05-04 10:31:23 -07:00
Mark Lacey
e03d334b68 Use Builtin.unreachable() in unavailable functions.
Saves a bit of code size in the standard library by eliminating some
static strings and function calls.

rdar://problem/25767016
2016-05-02 21:30:25 -07:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Jordan Rose
6dd1f0a5f9 [stdlib] Apply @_fixed_layout to various stdlib and overlay types
This is a staging attribute that will eventually mean "fixed-contents"
for structs and "closed" for enums, as described in
docs/LibraryEvolution.rst.

This is pretty much the minimal set of types that must be fixed-layout,
because SILGen makes assumptions about their lowering.

If desired, some SILGen refactoring can allow some of these to be
resilient. For example, bridging value types could be made to work
with resilient types.
2016-04-01 13:07:18 -07:00
Slava Pestov
7b91cbd551 stdlib: Add @_versioned attributes needed for resilient build 2016-04-01 13:07:18 -07:00
Doug Gregor
1889ea2657 Remove the default implementation of _ObjectiveCBridgeable._unconditionallyBridgeFromObjectiveC.
SILGen can't handle it yet, so pull it out until SILGen is fixed.
2016-03-24 17:10:26 -07:00
Doug Gregor
67dad6041c [Runtime] Use the _ObjectiveCBridgeable._ObjectiveCType type witness directly.
This lets us eliminate the _getObjectiveCType() value witness, which
was working around the lack of proper type witness metadata in witness
tables. Boilerplate -= 1.
2016-03-18 16:11:38 -07:00
Max Moiseev
03cbb49982 [stdlib] _stdlibAssert => _debugPrecondition 2016-03-17 12:16:19 -07:00
Doug Gregor
1d90b044fb Really reinstate "[SILGen] Implement NSString -> String bridging through _ObjectiveCBridgeable."
This reverts commit 052d2d0a69.

The only actual issue with the original change was a missing change to
the UIApplicationMain SILGen test, which needs to build SILGen
overlays to execute properly; -enable-source-import doesn't suffice.
2016-03-15 15:44:07 -07:00
Doug Gregor
052d2d0a69 Revert "Reinstate [SILGen] Implement NSString -> String bridging through _ObjectiveCBridgeable."
This reverts commit b25019c259. The
builders are failing in ways that are clearly related to my changes
but I'm unable to replicate locally.
2016-03-15 15:00:31 -07:00
Doug Gregor
b25019c259 Reinstate [SILGen] Implement NSString -> String bridging through _ObjectiveCBridgeable.
This reverts commit 01fe7e4848.
2016-03-15 11:38:06 -07:00
Doug Gregor
01fe7e4848 Revert "[SILGen] Implement NSString -> String bridging through _ObjectiveCBridgeable."
This reverts commit aa9cc23743.
2016-03-15 06:52:27 -07:00
Doug Gregor
aa9cc23743 [SILGen] Implement NSString -> String bridging through _ObjectiveCBridgeable.
Introduce a new entrypoint to _ObjectiveCBridgeable,
_unconditionallyBridgeFromObjectiveC, which handles unconditional
bridging from an optional Objective-C object (e.g., an NSString) to
its bridged Swift type. Use it in SILGen to perform NSString -> String
bridging rather than the custom entry point.

Another small step toward generalized bridging.
2016-03-14 11:17:46 -07:00
Daniel Duan
276370b599 [stdlib] apply SE-0040 to stdlib 2016-03-11 16:01:41 -08:00
Max Moiseev
a49dab6bf8 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-29 12:08:52 -08:00
Daniel Duan
2bc78b8c09 [stdlib] update for 'inout' adjustment (SE-0031) 2016-02-26 12:02:29 -08:00
Max Moiseev
78ba5d5f3f [stdlib] Requires in comments changed to Precondition 2016-02-19 18:57:26 -08:00
Max Moiseev
40b1a0b7e0 [stdlib] all sorts of require renamed back to precondition 2016-02-19 18:21:29 -08:00
Dmitri Gribenko
dd75aed67a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-17 14:40:05 -08:00
Dmitri Gribenko
efaa39ea79 stdlib: add first argument labels and some other changes to conform to API guidelines 2016-02-15 23:47:54 -08:00