Commit Graph

2520 Commits

Author SHA1 Message Date
kelvin13
ed2552a694 fix merge conflict and update caseless stdlib enums to use synthesized Comparable 2020-01-02 18:40:50 -06:00
Karoy Lorentey
1a9f7afdec [Foundation] Fix Data.count’s setter
Data provides a settable `count` property. Its expected behavior is undocumented, but based on the implementation, it is intended to zero-extend (or truncate) the collection to the specified length.

This does not work correctly if we start with an empty Data and we try to increase the count by a small integer:

```
import Foundation

var d = Data()
d.count = 2
print(d.count) // ⟹ 0 ⁉️

d.count = 100
print(d.count) // ⟹ 100 ✓
```

It looks like this bug was introduced with the Data overhaul that shipped in Swift 5.

(This issue was uncovered by https://github.com/apple/swift/pull/28918.)

rdar://58134026
2019-12-20 23:35:05 -08:00
David Smith
6936d0dc60 Merge pull request #28863 from Catfish-Man/ducking-types-test
Add a test for incorrectly constructing a Set from an NSArray
2019-12-18 17:24:39 -08:00
David Smith
0ce856b06c Add a test for incorrectly constructing a Set from an NSArray 2019-12-18 15:06:22 -08:00
tbkka
fdb1926421 [SR-5289] Teach Mirror how to handle unowned/unmanaged references (#28823)
SR-5289: Teach Mirror how to inspect weak, unowned, and unmanaged refs

Correctly reflect weak, unowned, and unmanaged references
to both Swift and Obj-C types (including existential references to
such types) that occur in both Swift class objects and in Swift
structs.

This includes the specific reported case (unowned reference to an
Obj-C object) and several related ones.

Related changes in this PR:

* Tweak internal bitmap used for tracking ownership modifiers
  to reject unsupported combinations.

* Move FieldType into ReflectionMirror.mm
  FieldType is really just an internal implementation detail
	of this one source file, so it does not belong in an ABI header.

* Use TypeReferenceOwnership directly to track field ownership
  This avoids bitwise copying of properties and localizes some
	of the knowledge about reference ownership

* Generate a top-level "copyFieldContents" from ReferenceStorage.def
  Adding new ownership types to ReferenceStorage.def will now
	automatically produce calls to `copy*FieldContents` - failure
	to provide a suitable implementation will fail the build.

* Add `deallocateBoxForExistentialIn` to match `allocateBoxForExistentialIn`

Caveat:  The unit tests are not as strict as I'd like.  Attempting to make them
so ran afoul of otherwise-unrelated bugs in dynamic casting.
2019-12-17 09:42:52 -08:00
Doug Gregor
23cc0790a7 [Dynamic casting] Fix overrelease on unsuccessful cast to an Error type.
Fixes SR-9207 / rdar://problem/45961622, SR-10478 / rdar://problem/49906841,
and rdar://problem/50665156.
2019-12-16 08:46:33 -08:00
YOCKOW
421af22f6c [Foundation] Add tests for [SR-10689](https://bugs.swift.org/browse/SR-10689).
Cherry-pick from 19017a7af6
2019-12-16 11:44:40 +09:00
Doug Gregor
169dbcdc17 Revert "Disable a test to unblock CI"
This reverts commit 29a6d1066e.
2019-12-13 23:55:13 -08:00
Doug Gregor
905c830c45 [Runtime] Handle Error bridging as a last chance to cast to NSError/NSObject.
Rather than attempting Error bridging early when trying to dynamically
cast to NSError or NSObject, treat it as the *last* thing we do when
all else fails. Push most of this code over into Objective-C-specific
handling rather than #ifdef'd into the main casting logic to make that
slightly more clear.

One oddity of Error/NSError bridging is that a class that conforms to
Error can be dynamically cast to NSObject via Error bridging. This has
always been known to the static compiler, but the runtime itself was
not always handling such a cast uniformly. Do so now,
uniformly. However, this forced us to weaken an assertion, because
casting a class type to NSError or NSObject can produce an object with
a different identity.

Fixes rdar://problem/57393991.
2019-12-13 23:55:13 -08:00
Doug Gregor
8261d6f57e [Test] Go through the runtime for the "as? NSObject" check.
This prevents runtime differences on as? from affecting this test.
2019-12-13 23:55:13 -08:00
Doug Gregor
5ed0641c59 [Runtime] Handle Error-conforming-to-NSObject casting fully.
I missed a case where an Error-conforming class is dynamically casted
to NSObject (via NSError). Fix it.
2019-12-13 23:55:13 -08:00
Mishal Shah
f5b9ed6d50 Merge pull request #28755 from lorentey/OptionSet-remove-back-deployment
[test] OptionSetTest: fix elementary logic error
2019-12-12 17:38:35 -08:00
Karoy Lorentey
0f5b9836b0 [test] OptionSetTest: fix elementary logic error 2019-12-12 12:43:38 -08:00
tbkka
cc8f8e929c SR-7732: Dynamic casting CFError to Error results in a memory leak (#28686)
* SR-7732: Dynamic casting CFError to Error results in a memory leak

The special handling for casting CFError/NSError to Swift Error
type was using cleanup code that didn't correctly handle this case.
This replaces the cleanup code with a more targeted version.

Fixes: SR-7732
Fixes: rdar://problem/40423061

* Whitespace fixes

* Don't rely on localizable strings to verify test behavior.

I've verified this simplified test still leaks with
the original code and does not leak with the fixed code.

* Don't test against old runtimes that predate this fix

* Explicitly test both NSError and CFError
2019-12-12 12:30:21 -08:00
Mishal Shah
7e2c2452ad Disable objc_mangling.swift and SwiftObjectNSObject.swift test on tvOS 2019-12-12 08:32:16 -08:00
swift-ci
b6f778ddf5 Merge pull request #28720 from lorentey/OptionSet-remove-back-deployment 2019-12-11 17:22:16 -08:00
Karoy Lorentey
b31f43c0e3 [test] Modernize test/stdlib/OptionSetTest.swift 2019-12-11 15:03:23 -08:00
Karoy Lorentey
05081eebc3 Merge pull request #28715 from lorentey/OptionSet-remove-back-deployment
[test] Protect OptionSet.remove test with future availability
2019-12-11 15:01:03 -08:00
Karoy Lorentey
b31c55be64 [test] Protect OptionSet.remove test with future availability 2019-12-11 12:43:00 -08:00
Ravi Kandhadai
d154f45f01 [stdlib-private][os log] Add new log methods for each specific logging level.
Also, add aliases for the logging levels for source compatibility with swift-server
side logging. Create a new initializer of Logger that can directly accept an
existing os log object of type `OSLog`. This aids in porting uses of existing
os_log API to the new API.
2019-12-11 11:49:02 -08:00
Ravi Kandhadai
af3aa03e0d Merge pull request #28697 from ravikandhadai/oslog-generic-operator-bug-fix
[Constant Evaluator] Fix a bug in the composition of substitution maps
2019-12-11 09:29:31 -08:00
Ravi Kandhadai
7744720df3 [Constant Evaluator] Fix a bug in the composition of substitution
maps in the handling of partial applies. In particular, when using
substMap.subst(otherSubstMap), ensure that otherSubstMap is not empty.

Also, store the partial-apply instruction in the symbolic closure,
which makes it easier to debug errors in the folding of partial applies.
2019-12-10 20:13:49 -08:00
Karoy Lorentey
2e17867774 Merge pull request #28378 from JacobMao/fix/SR-11283
SR-11283: Amend OptionSet.remove method
2019-12-10 17:41:45 -08:00
Ravi Kandhadai
f705720f1e [os log][stdlib/private] Add extensions for logging NSObjects.
The extensions for supporting NSObjects are in the file:
OSLogNSObjectType.swift. This creates a new dependency for the
OSLogPrototype overlay on the module: ObjectiveC. However,
ObjectiveC is already a dependency for the os module.

This patch includes tests for the NSObject extensions.
In addition, this patch contains a few other minor changes.
1. It makes the `osLog` function public (so that it can be
used by clients directly). 2. It fixes a lifetime-related
bug in the osLog function implementation. 3. It improves
the OSLogPrototypeExecTest suite by refactoring a few
helper functions.
2019-12-09 20:03:50 -08:00
Nate Cook
702fd84957 Use the correct test method 2019-11-26 18:25:49 -06:00
Diego Torres
a76e78d297 Add test to verify lazy filter predicate order 2019-11-26 17:37:58 -06:00
zhuowei
b9c1deff5f [stdlib] fix return type of getNumRuntimeFunctionCounters (#24182)
The return type of getNumRuntimeFunctionCounters is defined as uint64_t in RuntimeInvocationsTracking.cpp, but it has return type Int in RuntimeFunctionCounters.swift.

Found when compiling the stdlib for WebAssembly, as WebAssembly validates return types. uint64_t corresponds to i64, but Int is i32, so the program fails validation.
2019-11-22 13:44:56 -05:00
kelvin13
e4dc295d64 fix conflicts 2019-11-21 12:42:10 -06:00
Doug Gregor
7f50537933 Revert "[Constraint application] Stop optimizing casts in the AST." 2019-11-21 09:19:04 -08:00
Erik Eckstein
29a6d1066e Disable a test to unblock CI
rdar://problem/57393991
2019-11-21 16:23:21 +01:00
Doug Gregor
4907a984b4 Merge pull request #28355 from DougGregor/no-opt-ast-casts
[Constraint application] Stop optimizing casts in the AST.
2019-11-20 22:57:22 -08:00
Ravi Kandhadai
ba7996712a Merge pull request #28350 from ravikandhadai/oslog-exec-test-enable
[OSLogOptimization] Fix a bug in the replaceAllUsesAndFixLifetimes function of the OSLogOptimization pass
2019-11-20 19:38:35 -08:00
Mao ZiJun
f5ef37ab47 added test case for OptionSet's set algebra methods 2019-11-21 11:25:41 +09:00
Doug Gregor
f95f8e9a7b [Test] Go through the runtime for the "as? NSObject" check.
This prevents runtime differences on as? from affecting this test.
2019-11-20 16:53:59 -08:00
Doug Gregor
72ef0b1043 Remove extraneous function from test 2019-11-20 16:26:04 -08:00
Doug Gregor
c8df9cd234 [Test] Introduce appropriate runtime availability check 2019-11-20 16:23:38 -08:00
Doug Gregor
9975572781 [Runtime] Add test for casting an Error type to NSObject 2019-11-20 15:56:24 -08:00
Brent Royal-Gordon
bc5d59ecb7 Revert "[Runtime] Handle dynamic casting to NSObject via error bridging." 2019-11-20 10:38:44 -08:00
Ravi Kandhadai
f319f15655 [OSLogOptimization] Fix a bug in the replaceAllUsesAndFixLifetimes
function of the OSLogOptimization pass that happens when folding a
guaranteed value with a constant (owned) value. The fix inserts the
constant value at the beginning of the borrowed scope of the guaranteed
value rather than at the definition of the guaranteed value.

Update the SIL tests for the new folding pattern and add a test that
catches this bug.

Also, re-enable the OSLogPrototypeExecTest.swift that was disabled
due to this bug.
2019-11-19 11:50:08 -08:00
swift-ci
6d46eb182a Merge pull request #28353 from DougGregor/error-bridge-to-nsobject 2019-11-19 10:24:30 -08:00
Doug Gregor
76591217fe [Runtime] Add test for casting an Error type to NSObject 2019-11-19 08:46:28 -08:00
Michael Gottesman
0567c2af79 Disable test until ownership lowering after diagnostics transition is complete.
I talked with Ravi (the maintainer) about this and he is cool. I am going to
provide a patch that he can review to the oslog specific pass that also
undisables the test.

This test was passing last week when I originally tested it so that suggests the
special optimization pass is pattern matching too specific of a pattern.
2019-11-17 11:33:12 -08:00
Mike Ash
7d4bf753f4 [Test] Don't test demangling of SwiftObject's name, as it's subject to change.
rdar://problem/57163094
2019-11-15 12:56:24 -05:00
Karoy Lorentey
71f5ceeaf8 Fix closing braces lost during conflict resolution 2019-11-13 16:18:38 -08:00
Karoy Lorentey
21922a4333 Merge branch 'master' into accelerate-vDSP-interpolation-tests 2019-11-13 15:50:02 -08:00
Pavel Yaskevich
ef98b39de9 Merge pull request #28141 from xedin/sr-8411
[TypeChecker] Disambiguite cases of implicit pointer conversions with…
2019-11-08 10:18:46 -08:00
Pavel Yaskevich
3feb25c958 [TypeChecker] Disambiguite cases of implicit pointer conversions with optionals
Currently `{inout, array, string}-to-pointer` conversion doesn't
track whether there was a difference in optionality between involved
types which leads to ambiguity when different overload choices
have different optionality requirements.

Let's fix that by increasing a score in cases if pointer type
is itself optional e.g.:

```swift
func foo(_ x: UnsafeMutablePointer<Int>) {}
func foo(_ x: UnsafeMutablePointer<Int>?) {}

foo(&foo) // Should pick the least optional overload choice.
```

Resolves: [SR-8411](https://bugs.swift.org/browse/SR-8411)
2019-11-07 17:00:59 -08:00
Mishal Shah
c2c8cf5903 Disable objc_mangling and SwiftObjectNSObject test for watchOS (56959761) 2019-11-06 16:43:54 -08:00
Luciano Almeida
1184492d25 [Diagnostics] SR-11419 Diagnose protocol stub note in editor mode only (#28101)
* [TypeChecker] Enclosing stubs protocol note within editor mode

* [test] Removing note from test where there is no -diagnostics-editor-mode flag

* Formatting modified code

* [tests] Fixing tests under validation-tests
2019-11-06 07:42:48 -08:00
Hamish Knight
998434f0da Add a -disable-invalid-ephemeralness-as-error flag
Currently this does nothing, as we're warning by
default, but once we error by default, this will
downgrade the diagnostic to a warning.
2019-11-03 08:42:26 -08:00