Commit Graph

3150 Commits

Author SHA1 Message Date
Greg Parker
590d41c00a [runtime] enhanced and refactored recently added Mutex abstraction (Merge pull request #1950 from shawnce/SR-946_rw)
[runtime] enhanced and refactored recently added Mutex abstraction
2016-04-26 16:18:12 -07:00
Slava Pestov
ee0e44ae71 Runtime: Fix memory management snafu in swift_EnumCaseName()
I don't have a good way to test for leaking a box. Once I come up
with one, I will write a test for this patch as well as the earlier
patch "Runtime: Tweak Mirrors for resilience".

Fixes <rdar://problem/25797038>.
2016-04-21 17:58:10 -07:00
Han Sangjin
bf9413316e stdlib/cygwin: Modified SwiftGlibc for Cygwin and some fix
'import SwiftGlibc' is now work in Cygwin.
Add workaround about USER_LABEL_PREFIX for Clang bug.
2016-04-18 07:49:57 +09:00
Greg Parker
86faf7c15d [runtime] Don't install libswiftRuntime.a
libswiftRuntime.a is an internal object file. Its contents are incorporated
into libswiftCore.dylib and libswiftCore.a.

rdar://25353757
2016-04-15 19:15:27 -07:00
practicalswift
0927538208 [gardening] Fix file header formatting. 2016-04-14 22:26:44 +02:00
Anna Zaks
eac72f078c [runtime] Add implementation of _swift_strlcpy
This safer function is missing on Linux.
2016-04-14 11:01:57 -07:00
Anna Zaks
4ba7e418cb [runtime] Fortify the swift_demangle API.
Remove the reference to String, which leaks internal implementation details,
check for invalid inputs, and make the API more flexible. Remove the similar
Swift API, since it provides no additional value.
2016-04-14 11:01:57 -07:00
swift-ci
728d21a00d Merge pull request #1442 from SwiftAndroid/master 2016-04-12 23:30:17 -07:00
Zhuowei Zhang
7c502b6344 Port to Android
This adds an Android target for the stdlib. It is also the first
example of cross-compiling outside of Darwin.

Mailing list discussions:

1. https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151207/000171.html
2. https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000492.html

The Android variant of Swift may be built using the following `build-script`
invocation:

```
$ utils/build-script \
  -R \                                           # Build in ReleaseAssert mode.
  --android \                                    # Build for Android.
  --android-ndk ~/android-ndk-r10e \             # Path to an Android NDK.
  --android-ndk-version 21 \
  --android-icu-uc ~/libicu-android/armeabi-v7a/libicuuc.so \
  --android-icu-uc-include ~/libicu-android/armeabi-v7a/icu/source/common \
  --android-icu-i18n ~/libicu-android/armeabi-v7a/libicui18n.so \
  --android-icu-i18n-include ~/libicu-android/armeabi-v7a/icu/source/i18n/
```

Android builds have the following dependencies, as can be seen in
the build script invocation:

1. An Android NDK of version 21 or greater, available to download
   here: http://developer.android.com/ndk/downloads/index.html.
2. A libicu compatible with android-armv7.
2016-04-12 19:26:21 -04:00
practicalswift
c760f6dfbf [gardening] Add whitespace: "foo,bar" → "foo, bar" 2016-04-12 22:31:46 +02: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
practicalswift
fa40ad2f0c [gardening] "Objective C" → "Objective-C" 2016-04-09 12:22:18 +02:00
Greg Parker
41b12e7929 [runtime] Fix ObjC SwiftObject's header so it matches HeapObject.
rdar://25476641 and SR-1096.
2016-04-09 01:59:20 -07:00
Greg Parker
9a94aa5a82 [runtime] Remove a workaround in SwiftObject for an old clang bug.
Reverts the functionality of b50293b2, but leaves that commit's tests in place.
2016-04-09 01:51:58 -07:00
AnnaZaks
5d34f6629e Merge pull request #2076 from apple/asan
Add experimental support for Thread Sanitizer
2016-04-06 14:45:44 -07:00
Greg Parker
709951e82e [runtime] Fix a leak when a cast from an existential fails.
rdar://25011739.
2016-04-06 14:42:33 -07:00
Shawn Erickson
a0452be947 [runtime] enhanced and refactored recently added Mutex abstraction
- added read / write lock support
- added non-fatal error support to allow use of mutex in fatal error reporting pathway
- isolated pthread implementation to it own header/cpp file pair
- expanded unit tests to cover new code as well as better test existing mutex
- removed a layer of complexity that added no real value
2016-04-06 13:02:37 -07:00
Anna Zaks
f49e6ad8dd Fix a data race in the conformsToProtocol method.
This bug was reported by TSan.
2016-04-06 11:54:01 -07:00
Slava Pestov
03cdc17b19 stdlib: Rewrite _getClassPlaygroundQuickLook() in Swift
The C++ code was very fragile in terms of ABI dependencies and broke
when the standard library was built with -enable-resilience.

The actual reason it broke is that case numbering changes when
resilience is enabled, but instead of messing with that, it seemed
more logical to rewrite this routine in Swift instead, to avoid
ABI dependencies altogether.

This requires using the "shadow protocol" trick to call NSNumber
methods, since we cannot import NSNumber from the stdlib.
2016-04-05 00:29:49 -07:00
Slava Pestov
9ce9784180 Runtime: Tweak Mirrors for resilience
Make _MagicMirrorData @_fixed_layout, but not the concrete mirror
implementations.

To make the calling convention work in resilient builds, make the
runtime entry points into top-level functions that take a
_MagicMirrorData, instead of adding @_silgen_name attributes on
methods.

This involves changing the convention on the 'owner' parameter
from +0 to +1.

Also, there was a memory leak in the old enum code that I noticed
by inspection. We would copy the enum value into a box, strip
the enum tag bits, take the box contents but never free the box
itself.

The fix isn't very satisfying either -- we have to modify the
source enum in-place to strip tag bits, then we copy it into a
box having the right payload type, and add the tag bits back.
At least this way, we can free the box after.
2016-04-04 00:05:01 -07:00
Slava Pestov
7c0bd2f660 Runtime: Fix problems with nil-to-nil casts
We have a special rule that Optional<T>.none successfully dynamically casts
to Optional<U>.none for any T and U. However the implementation was incorrect
if the source and destination types had a different size. We would initialize
the source to nil, and then copy to the result.

The correct implementation is to initialize the result using the result
payload type directly, and not call _succeed() at all.

Fixes <https://bugs.swift.org/browse/SR-1056>.
2016-03-31 17:21:20 -07:00
swiftix
fa0d270a69 Merge pull request #1909 from swiftix/wip-non-atomic-apis
Provide non-atomic versions of many reference counting operations.
2016-03-31 14:26:02 -07:00
Ben Langmuir
f8287f4376 Revert "Runtime: Fix problems with nil-to-nil casts"
This was causing test failures in -optimize mode (build-sript -o).

This reverts commit e72caad3d7.
2016-03-31 08:59:49 -07:00
swift-ci
379f2b9723 Merge pull request #1773 from froody/objc_export 2016-03-30 16:45:53 -07:00
Roman Levenstein
5d22a59e01 Provide non-atomic versions of many reference counting operations.
Provide the same guarantees regrading the barriers as the atomic versions.
2016-03-30 16:43:05 -07:00
Slava Pestov
e72caad3d7 Runtime: Fix problems with nil-to-nil casts
We have a special rule that Optional<T>.none successfully dynamically casts
to Optional<U>.none for any T and U. However the implementation was incorrect
if the source and destination types had a different size. We would initialize
the source to nil, and then copy to the result.

The correct implementation is to initialize the result using the result
payload type directly, and not call _succeed() at all.

Fixes <https://bugs.swift.org/browse/SR-1056>.
2016-03-30 14:24:58 -07:00
Tom Birch
e2e3672786 [Runtime] Use OBJC_EXPORT for compatibility
objc uses OBJC_EXPORT when defining these symbols, the declarations should match
2016-03-30 13:30:32 -07:00
practicalswift
bbef13a050 [gardening] Fix recently introduced typo: "attribtue" → "attribute"
[gardening] Fix recently introduced typo: "delinated" → "delineated"

[gardening] Fix recently introduced typo: "abstactions" → "abstractions"

[gardening] Fix recently introduced typo: "cannoted" → "cannot"

[gardening] Fix recently introduced typo: "accomodate" → "accommodate"

[gardening] Fix recently introduced typo: "bulding" → "building"

[gardening] Fix recently introduced typo: "abstactions" → "abstractions"

[gardening] Fix recently introduced typo: "intiializers" → "initializers"
2016-03-30 18:20:53 +02:00
Dmitri Gribenko
82509cbd74 Merge pull request #1731 from shawnce/SR-946
SR-946 - Unify mutexes in the Swift runtime
2016-03-29 08:56:39 -07:00
Han Sangjin
2637639eef stdlib/cygwin: Fix finding NT header in DLL.
In PE-COFF formatted file, the offset of NT header can be greater than 0xFF. MS library defines it as LONG (32bit signed integer) in struct _IMAGE_DOS_HEADER.
2016-03-28 12:12:00 +09:00
Ted Kremenek
1e97da25b4 Reverts commit 8a000457b6.
Backing out the metadata change broke Linux.
2016-03-25 22:13:28 -07:00
Ted Kremenek
8a000457b6 Speculatively revert "Only define resilient metadata and VWTs as constant when they don't"
This reverts commit 893d1dc523.

This looks like a likely culprit that broke tests on the iOS Simulator:

 Failing Tests (6):
     Swift :: IRGen/class_resilience.swift
     Swift :: IRGen/concrete_inherits_generic_base.swift
     Swift :: IRGen/enum_resilience.swift
     Swift :: IRGen/foreign_types.sil
     Swift :: IRGen/nested_types.sil
     Swift :: IRGen/struct_resilience.swift
2016-03-25 21:55:30 -07:00
John McCall
9e5ce49765 Only define resilient metadata and VWTs as constant when they don't
need to be modified by the runtime, and only actually store to them
when that would change anything.

Unfortunately, Linux is considerably better than Darwin at shaking
these bugs out because Darwin will leave global data mutable after
resolving relocations in it.
2016-03-25 00:18:14 -07:00
John McCall
0ffb7278bc Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.

Includes a fix since the earlier commit to make enum metadata
writable if they have an unfilled payload size.  This didn't show
up on Darwin because "constant" is currently unenforced there in
global data containing relocations.

This patch requires an associated LLDB change which is being
submitted in parallel.
2016-03-24 15:10:31 -07:00
Slava Pestov
aa3700826e Runtime: Small cleanup to fix function order, NFC 2016-03-24 00:50:38 -07:00
John McCall
abba7f0c8b Revert "Only use metadata patterns for generic types; perform other"
This reverts commit 41efb3d4d3.
LLDB has too many tendrils into our metadata.
2016-03-23 20:26:43 -07:00
John McCall
41efb3d4d3 Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.
2016-03-23 17:04:04 -07:00
Andrew Trick
1bd9dc97b4 SR-912: Runtime exception casting an Any nil to an Optional.
This is a simple runtime fix for the following case:

func cast<U>(t: Any) -> U {
  return t as! U
}
cast(nil as Int?) as Int?
2016-03-22 17:47:05 -07:00
Shawn Erickson
3292124f87 [runtime] - switched most runtime code to use swift::Mutex and swift::Condition (see SR-946) 2016-03-20 22:56:48 -07:00
Shawn Erickson
2f84220712 [runtime] added Mutex, Condition, and Scoped locks for use by Swift runtime (see SR-946) 2016-03-20 22:56:24 -07:00
Doug Gregor
9c530f1d93 [Runtime] Add witness-table parameters to _ObjectiveCBridgeable witnesses.
The witness-table parameters got added to all witnesses as part of the
resilience work, but the hardcoded witness table in the runtime's
dynamic-casting infrastructure didn't get updated. Nothing seems to be
relying on these right now, so we cannot actually *test* it, but I've
verified that the types line up.
2016-03-18 16:30:53 -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
Saleem Abdulrasool
13a2ef3b4b runtime: improve portability and simplify aliases
clang and gcc provide a preprocessor macro called `__USER_LABEL_PREFIX__` which
provides the user label prefix for the specific target that the translation unit
is being built for.  Rather than trying to reconstruct the logic in place via
various checks, fallback to the compiler to provide this information.  Although
this limits the compilers (MSVC does not provide this preprocessor macro
definition), the only supported compiler ATM is clang, and it has provided this
definition for some time now.

This addresses the FIXME that was associated with the user label prefix being
applied under specific cases.

NFC.
2016-03-17 10:05:07 -07:00
Erik Eckstein
e1b94885a2 runtime: add a new runtime function swift_setDeallocating.
It's to be used by code produced by the ReleaseDevirtualizer.
As the function is only used for non-escaping objects, the deallocating bit is set non-atomically.
2016-03-15 12:56:54 -07:00
Ted Kremenek
2ded9fe444 Merge pull request #1466 from tinysun212/pr-common-inspect-dylib
Refactor code duplication in inspecting dylibs
2016-03-14 21:12:54 -07:00
practicalswift
11dba6f361 [gardening] Fix recently introduced typo: "acccessing" → "accessing"
[gardening] Fix recently introduced typo: "definately" → "definitely"
2016-03-11 16:03:06 +01:00
Peter Cooper
7ec0e7348f Add more calls to the objc runtime for getting an object’s ISA.
Be more conservative in terms of masking ISAs.  This reduces tight coupling with the objc runtime.  This commit adds the required calls to IRGen and the runtime, and a test case to make sure IRGen is correct.
2016-03-10 15:07:20 -08:00
Max Moiseev
02006f20bc Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-09 16:05:03 -08:00
Michael Gottesman
1b7ecf5fc7 Fix the leaks checker bot.
Sadly it looks like someone took down my leaks checking bot a couple of months
ago. =--(. This updates the code to compile with Swift today.
2016-03-08 18:31:11 -08:00
Doug Gregor
3fb06d7442 [Swift runtime] Deallocation of partial class instances for Objective-C-derived classes.
Teach swift_deallocPartialClassInstance how to deal with classes that
have pure Objective-C classes in their hierarchy. In such cases, we
need to make sure a few things happen:

1) We deallocate via objc_release rather than
swift_deallocClassInstance.
2) We only attempt to find an execute ivar destroyers for
Swift-defined classes in the hierarchy
3) When we hit the most-derived pure Objective-C class, make sure that we
only execute the dealloc of that class and not any of the subclasses
(which would end up trying to destroy ivars again).

Fixes rdar://problem/25023544.
2016-03-08 16:47:57 -08:00