The runtime implementation of 'as T' freaks out in cases involving protocols. This is an expedient workaround that fixes <rdar://problem/16950035>.
Swift SVN r18263
When an NSArray is force-downcast to T[] at an API boundary, we need to
remember that each element needs to be dynamically checked when
accessed. No deferred casts are being generated yet, so NFC
Swift SVN r18243
Turns out we really want to use reinterpretCast when we know it will
work, rather than a checked downcast + forced optional unwrapping. The
latter will only be as fast as the former in -Ofast
Swift SVN r18241
This not only removes some code, but should allow more optimization and
inlining in the common case where the Swift type is a class or @objc
existential such as AnyObject
Swift SVN r18237
I personally like ~(cast)0, but (cast)-1 felt more consistent with LLVM
style; and the waffling before finishing my coffee this morning made the
code wrong. Whoops.
Swift SVN r18221
assert() and fatalError()
These functions are meant to be used in user code. They are enabled in debug
mode and disabled in release or fast mode.
_precondition() and _preconditionFailure()
These functions are meant to be used in library code to check preconditions at
the api boundry. They are enabled in debug mode (with a verbose message) and
release mode (trap). In fast mode they are disabled.
_debugPrecondition() and _debugPreconditionFailure()
These functions are meant to be used in library code to check preconditions that
are not neccesarily comprehensive for safety (UnsafePointer can be null or an
invalid pointer but we can't check both). They are enabled only in debug mode.
_sanityCheck() and _fatalError()
These are meant to be used for internal consistency checks. They are only
enabled when the library is build with -DSWIFT_STDLIB_INTERNAL_CHECKS=ON.
I modified the code in the standard library to the best of my judgement.
rdar://16477198
Swift SVN r18212
Really we want those nullary functions be computed properties using enums.
var _assertConfiguration : _AssertConfiguration {
let assertConfig = Int32(Builtin.assert_configuration())
if assertConfig == 0 {
return .Debug
}
if assertConfig == 1 {
return .Release
}
return .Fast
}
if _assertConfiguration == .Debug {
_fatal_error_message("assertion failed", message, file, line)
}
In my tests the enums were not optimized away. So for the short term leave
these functions as nullary functions.
Swift SVN r18211
Prior to this fix this would fail:
(swift) import Foundation
(swift) extension NSDate { func foo() { println("foo") }}
As the Class for NSDate was not initialized.
<rdar://problem/16934080>
Swift SVN r18206
I've never used 'newlocale' before, so I may be using it wrong.
Also, this may not be 100% thread safe; worst case we create
multiple locale objects when swift_doubleToString() is called
at the same time. We can fix this if we care.
Swift SVN r18201
creating a Dictionary from a dictionary literal
Also fixes rdar://16876745, because once the code moved to using lower-level
interfaces, it became trivial to detect duplicate keys without a performance
hit.
Swift SVN r18193
... unless we actually hit one of the confusing cases involving
multi-dimensional arrays (e.g., Int[]?[]), at which point one needs to
write parentheses <rdar://problem/16737035>.
Swift SVN r18181
We decided that classes and Objective-C existentials are always going
to be bridged verbatim, ignoring any _BridgedToObjectiveC conformances.
While the compiler isn't preventing conformance of a class type to
_BridgedToObjectiveC, we ignore this case and will find a way to lock
it down if _BridgedToObjectiveC loses its underscore.
The motivation here is that (1) we don't really have a use case for a
class that bridges to Objective-C in any way other than just being an
Objective-C class, and (2) the class-or-ObjC-existential check is
ridiculously cheap compared to the
thread-safe-hash-table-over-a-dlsym-call used to find witness tables,
so do the cheap, common check first.
Swift SVN r18177
Once we know that the storage is contiguous we use the new API _NthContiguous.
We can further optimize this code by specializing the access to ascii or UTF-16.
Swift SVN r18167