Commit Graph

21 Commits

Author SHA1 Message Date
Ben Cohen
345879429b [stdlib] Take several underscored stdlib functions private (#18134)
* Make _sanityCheck internal

* Make _debugPrecondition internal

* Make Optional._unsafelyUnwrappedUnchecked internal.

* Make _precondition internal

* Switch Foundation _sanityChecks to assertions

* Update file check tests

* Remove one more _debugPrecondition

* Update Optimization-with-check tests
2018-07-24 18:26:19 -07:00
Ben Cohen
05b63ebffb Replace (x as? Y) != nil with x is Y 2016-11-17 11:26:36 -08:00
practicalswift
fa7fbdb8b0 [gardening] Remove redundant nil-initialization of optional variable
From the Swift documentation:

"If you define an optional variable without providing a default value,
 the variable is automatically set to nil for you."
2016-09-18 07:40:07 +02:00
Max Moiseev
9fc37efee4 [test] renaming test/1_stdlib to just test/stdlib 2016-09-01 16:51:43 -07:00
Jordan Rose
e83c117c30 [test] Hack: run stdlib tests first to start long-running tests earlier.
This decreases total testing time by over a minute on my old Mac Pro.
It probably has much less effect on systems with fewer cores, but shouldn't
be any worse there.

Swift SVN r22745
2014-10-15 01:30:51 +00:00
Jordan Rose
1c0d8c9c13 [test] Add an interpreter mode to the tests.
This takes all %target-run-simple-swift and %target-run-stdlib-swift
invocations and runs them using the interpreter instead. To enable this
mode, pass --param=interpret to lit.py; you can add this flag to the
LLVM_LIT_ARGS CMake setting (which defaults to "-sv").

This doesn't support separated %target-build / %target-run steps, nor
does it work with StdlibUnittest (which uses posix_spawn to run its
subtasks). But it's a start.

<rdar://problem/17938202>

Swift SVN r21391
2014-08-21 23:50:15 +00:00
Doug Gregor
c593d49b08 Rework the _ObjectiveCBridgeable to use inout parameters rather than returns.
The _forceBridgeFromObjectiveC and _conditionallyBridgeFromObjectiveC
requirements of the _ObjectiveCBridgeable protocol previously returned
Self and Self?, respectively, where 'Self' is the value type that is
bridged. This use of returns is fairly hostile to the idea of calling
the witnesses for these requirements from the C++ part of the runtime,
leading to "interesting" tricks with OpaqueExistentialContainer that
made it hard to use these witnesses within the dynamic casting
infrastructure.

Replace the returns with inout Self? parameters, which are far easier
to deal with in the C++ part of the runtime. Despite the churn because
we're changing the _ObjectiveCBridgeable protocol, this is NFC.

Swift SVN r20934
2014-08-02 01:03:41 +00:00
Dave Abrahams
9a13a7148b [stdlib] Consolidate bridging protocols
Squash _[Conditionally]BridgedToObjectiveC into one protocol.  This
change results in simpler bridging code with fewer dynamic protocol
conformance checks, and solves the nasty naming/semantics problem that
resulted from having _ConditionallyBridgedToObjectiveC refining
_BridgedToObjectiveC.

Also, rename things so they're more symmetrical and less confusing.

Swift SVN r20664
2014-07-29 01:30:27 +00:00
Joe Pamer
94dac129d4 Remove the BooleanType conformance from optional types (rdar://problem/17110911)
To limit user confusion when using conditional expressions of type Bool?, we've decided to remove the BooleanType (aka "LogicValue") conformance from optional types. (If users would like to use an expression of type Bool? as a conditional, they'll need to check against nil.)

Note: This change effectively regresses the "case is" pattern over types, since it currently demands a BooleanType conformance. I've filed rdar://problem/17791533 to track reinstating it if necessary.

Swift SVN r20637
2014-07-28 19:20:39 +00:00
Dmitri Hrybenko
4c4f83fb52 stdlib: underscore-prefix requirements of _BridgedToObjectiveCType and
_ConditionallyBridgedToObjectiveCType protocols

rdar://17283639


Swift SVN r20079
2014-07-17 09:42:19 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Dmitri Hrybenko
62c772ad6a stdlib: hide Objective-C bridging implementation details
Swift SVN r19595
2014-07-07 09:46:07 +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
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
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
Arnold Schwaighofer
da6d9152b6 Differentiate between user assertion and preconditions and the like
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
2014-05-16 20:49:54 +00:00
Doug Gregor
df4429fc5d Perform the class-or-ObjC-existential checks first in the runtime bridging entrypoints.
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
2014-05-16 05:18:34 +00:00
Dmitri Hrybenko
f183e493bf stdlib/bridging: bridgeFromObjectiveC() can fail to bridge the Objective-C
object to the desired type.  Model this with an optional return type.


Swift SVN r18077
2014-05-14 19:49:22 +00:00
Dmitri Hrybenko
eb9c3a406d stdlib/runtime: implement bridgeFromObjectiveC()
Swift SVN r18070
2014-05-14 13:40:46 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Joe Groff
f6d4485a3c stdlib/runtime: Create an _ObjCBridgeable protocol and 'bridgeAny' runtime function.
For container bridging, implement a '_bridge<T>' function that converts a Swift value to AnyObject using a runtime check for its _ObjCBridgeable conformance, crashing if one doesn't exist.

Swift SVN r14645
2014-03-04 16:50:11 +00:00