Commit Graph

35 Commits

Author SHA1 Message Date
Daniel Duan
4e5dbed41a Test: use StdlibUnittest in BridgeNonVerbatim
Convert tests in BridgeNonVerbatim.swift to use StdlibUnittest.

Also add a function that compares references in StdlibUnittest.
2017-03-29 01:09:53 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01: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
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
Dave Abrahams
2d850421bc [stdlib] Internalize HeapBuffer[Storage], OnHeap
They were never really useful to users, because their APIs were
insufficiently public.  They have been replaced with a single class,
ManagedBuffer<Value,Element>, which is really designed for user
consumption.

Swift SVN r22636
2014-10-09 21:45:44 +00:00
Dave Abrahams
6c07fb4ad1 [stdlib] Revert UnsafePointer casting change
The syntax being reverted added busywork and noise to the common case
where you want to say "I have the right address, but the wrong type,"
without adding any real safety.

Also it eliminated the ability to write UnsafePointer<T>(otherPointer),
without adding ".self" to T.  Overall, it was not a win.

This reverts commits r21324 and r21342

Swift SVN r21424
2014-08-22 21:53:12 +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
Dave Abrahams
1fb0f889d7 [stdlib] Make UnsafePointer conversions explicit
Previously, it was possible to write Unsafe[Mutable]Pointer(x) and have
Swift deduce the pointee type based on context.  Since reinterpreting
memory is a fundamentally type-unsafe operation, it's better to be
explicit about conversions from Unsafe[Mutable]Pointer<T> to
Unsafe[Mutable]Pointer<U>.  This change is consistent with the move from
reinterpretCast(x) to unsafeBitCast(x, T.self).

Also, we've encoded the operations of explicitly adding or removing
mutability as properties, so that adding mutability can be separated
from wild reinterpretCast'ing, a much more severe form of unsafety.

Swift SVN r21324
2014-08-20 23:15:56 +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
Doug Gregor
9f93d94dc6 Eliminate the ~> hack in the type checker I introduced in r20626.
We don't need to permit non-final classes and ForwardIndexTypes
<rdar://problem/17828741>.

Swift SVN r20633
2014-07-28 18:26:29 +00:00
Doug Gregor
3cb58e833a Restrict non-final class protocol conformance when Self is part of the requirement signature.
When a non-final class satisfies a method requirement that returns
Self, it must do so with a method that also returns (dynamic)
Self. This ensures conformance will be inheritable, closing off an
awful type-safety hole <rdar://problem/16880016>. Other
non-contravariant uses of Self in the signatures of requirements cause
the protocol to be unusable by non-final classes.

I had to leave a tiny little gaping hole for the ~> operator, whose
removal is covered by <rdar://problem/17828741>. We can possibly put
this on firm footing with clever handling of generic witnesses, but
it's not important right now.



Swift SVN r20626
2014-07-28 16:15:16 +00:00
Dave Abrahams
478c41fa3c [stdlib] Drop withUnsafe[Mutable]PointerToElements
Now that arrays have withUnsafe[Mutable]BufferPointer, and the buffer
pointers have a baseAddress property, this API is obsolete.

Swift SVN r20347
2014-07-22 23:04:45 +00:00
Dave Abrahams
dfe2ba4d8d [stdlib] const-correct withUnsafePointer APIs
Fixes <rdar://problem/17364737>

Swift SVN r20329
2014-07-22 20:39:59 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Dave Abrahams
2c3ab47cf2 [stdlib] O(1) Array<non-verbatim> round-tripping
Arrays of non-verbatim-bridged types (such as Int, and today's String)
are converted to Objective-C lazily, with the objects created due to
element conversion being autoreleased when necessary.

Fixes <rdar://problem/17360154>

Note: test/SIL/Parser/array_roundtrip.swift was XFAIL'd;
see <rdar://problem/17758203>

Swift SVN r20293
2014-07-22 04:42:47 +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
92d890361f Update references to isUniquelyReferenced in tests
Swift SVN r19600
2014-07-07 10:13:40 +00:00
Doug Gregor
e064416c8f Update the rest of the testsuite for the array syntax change.
Swift SVN r19223
2014-06-26 05:39:25 +00:00
Ted Kremenek
58558fcca3 Rename 'succ' and 'pred' to 'successor' and 'predecessor' respectively.
This is motivated by <rdar://problem/17051606>.

This ends up renaming variables as well, which seems right for
consistency since we use "predicate" as variable name.

Swift SVN r19135
2014-06-24 19:27:19 +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
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
Joe Pamer
1d34a88477 Revert "Fix two problems with implicit conversions: - rdar://problem/16776273, wherein conversions between nil and .None were permitted due to an implicit conversion between nil and COpaquePointer. - rdar://problem/16877526, where we needed to add new equality overloads to handle conversions between nil and .None given the supression of user conversions. (Thanks to Ted for the overloads and test.)"
This reverts commit r18473.

Swift SVN r18477
2014-05-21 00:28:46 +00:00
Joe Pamer
f469d8f1f6 Fix two problems with implicit conversions:
- rdar://problem/16776273, wherein conversions between nil and .None were permitted
due to an implicit conversion between nil and COpaquePointer.
- rdar://problem/16877526, where we needed to add new equality overloads to handle
conversions between nil and .None given the supression of user conversions.
(Thanks to Ted for the overloads and test.)

Swift SVN r18473
2014-05-20 23:53:34 +00:00
Dave Abrahams
200b89291c [stdlib] Array API review: privatize [bB]uffer
Swift SVN r18335
2014-05-18 17:32:00 +00:00
Ted Kremenek
16dea15a24 Hide CocoaArray ('_' to mark as private API).
Swift SVN r18302
2014-05-18 04:03:32 +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
Dave Abrahams
b666651e3f [stdlib] Rename NativeArray => ContiguousArray
Per API review feedback.

Swift SVN r18140
2014-05-15 23:24:09 +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
Dmitri Hrybenko
de9a0c8ff0 stdlib/printing: remove ReplPrintable protocol
It is replaced by debugPrint() family of functions, that are called by REPL.

There is a regression in printing types that don't conform to Printable, this
is tracked by rdar://16898708


Swift SVN r18006
2014-05-13 16:22:56 +00:00
Dave Abrahams
5c3ebfcfb6 [stdlib] test file rename missed in r17722
Swift SVN r17734
2014-05-08 23:33:49 +00:00