mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports than the average target, and that this contains ALL of them at once. I also deliberately tried to tag nearly every top-level decl, even if that was just to explicitly mark things @internal, to make sure I didn't miss something. This does export more than we might want to, mostly for protocol conformance reasons, along with our simple-but-limiting typealias rule. I tried to also mark things private where possible, but it's really going to be up to the standard library owners to get this right. This is also only validated against top-level access control; I haven't fully tested against member-level access control yet, and none of our semantic restrictions are in place. Along the way I also noticed bits of stdlib cruft; to keep this patch understandable, I didn't change any of them. Swift SVN r19145
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
func minElement<
|
||||
@public func minElement<
|
||||
R : Sequence
|
||||
where R.GeneratorType.Element : Comparable>(range: R)
|
||||
-> R.GeneratorType.Element {
|
||||
@@ -22,7 +22,7 @@ func minElement<
|
||||
return result
|
||||
}
|
||||
|
||||
func maxElement<
|
||||
@public func maxElement<
|
||||
R : Sequence
|
||||
where R.GeneratorType.Element : Comparable>(range: R)
|
||||
-> R.GeneratorType.Element {
|
||||
@@ -36,7 +36,7 @@ func maxElement<
|
||||
|
||||
// Returns the first index where value appears in domain or nil if
|
||||
// domain doesn't contain the value. O(countElements(domain))
|
||||
func find<
|
||||
@public func find<
|
||||
C: Collection where C.GeneratorType.Element : Equatable
|
||||
>(domain: C, value: C.GeneratorType.Element) -> C.IndexType? {
|
||||
for i in indices(domain) {
|
||||
@@ -47,7 +47,7 @@ func find<
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertionSort<
|
||||
@public func insertionSort<
|
||||
C: MutableCollection where C.IndexType: BidirectionalIndex
|
||||
>(
|
||||
inout elements: C,
|
||||
@@ -94,7 +94,9 @@ func insertionSort<
|
||||
/// Partition a non empty range into two partially sorted regions and return
|
||||
/// the index of the pivot:
|
||||
/// [start..idx), pivot ,[idx..end)
|
||||
func partition<C: MutableCollection where C.IndexType: RandomAccessIndex>(
|
||||
@public func partition<
|
||||
C: MutableCollection where C.IndexType: RandomAccessIndex
|
||||
>(
|
||||
inout elements: C,
|
||||
range: Range<C.IndexType>,
|
||||
inout less: (C.GeneratorType.Element, C.GeneratorType.Element)->Bool
|
||||
@@ -136,7 +138,9 @@ func partition<C: MutableCollection where C.IndexType: RandomAccessIndex>(
|
||||
}
|
||||
|
||||
|
||||
func quickSort<C: MutableCollection where C.IndexType: RandomAccessIndex>(
|
||||
@public func quickSort<
|
||||
C: MutableCollection where C.IndexType: RandomAccessIndex
|
||||
>(
|
||||
inout elements: C,
|
||||
range: Range<C.IndexType>,
|
||||
less: (C.GeneratorType.Element, C.GeneratorType.Element)->Bool
|
||||
@@ -145,7 +149,9 @@ func quickSort<C: MutableCollection where C.IndexType: RandomAccessIndex>(
|
||||
_quickSort(&elements, range, &comp)
|
||||
}
|
||||
|
||||
func _quickSort<C: MutableCollection where C.IndexType: RandomAccessIndex>(
|
||||
func _quickSort<
|
||||
C: MutableCollection where C.IndexType: RandomAccessIndex
|
||||
>(
|
||||
inout elements: C,
|
||||
range: Range<C.IndexType>,
|
||||
inout less: (C.GeneratorType.Element, C.GeneratorType.Element)->Bool
|
||||
@@ -170,7 +176,7 @@ struct Less<T: Comparable> {
|
||||
}
|
||||
}
|
||||
|
||||
func sort<
|
||||
@public func sort<
|
||||
C: MutableCollection where C.IndexType: RandomAccessIndex
|
||||
>(
|
||||
inout collection: C,
|
||||
@@ -179,7 +185,7 @@ func sort<
|
||||
quickSort(&collection, indices(collection), predecessor)
|
||||
}
|
||||
|
||||
func sort<
|
||||
@public func sort<
|
||||
C: MutableCollection
|
||||
where C.IndexType: RandomAccessIndex, C.GeneratorType.Element: Comparable
|
||||
>(
|
||||
@@ -188,7 +194,7 @@ func sort<
|
||||
quickSort(&collection, indices(collection))
|
||||
}
|
||||
|
||||
func sort<T>(inout array: T[], predecessor: (T, T) -> Bool) {
|
||||
@public func sort<T>(inout array: T[], predecessor: (T, T) -> Bool) {
|
||||
return array.withMutableStorage {
|
||||
a in sort(&a, predecessor)
|
||||
return
|
||||
@@ -198,14 +204,14 @@ func sort<T>(inout array: T[], predecessor: (T, T) -> Bool) {
|
||||
/// The functions below are a copy of the functions above except that
|
||||
/// they don't accept a predicate and they are hardcoded to use the less-than
|
||||
/// comparator.
|
||||
func sort<T : Comparable>(inout array: T[]) {
|
||||
@public func sort<T : Comparable>(inout array: T[]) {
|
||||
return array.withMutableStorage {
|
||||
a in sort(&a)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func sorted<
|
||||
@public func sorted<
|
||||
C: MutableCollection where C.IndexType: RandomAccessIndex
|
||||
>(
|
||||
source: C,
|
||||
@@ -216,7 +222,7 @@ func sorted<
|
||||
return result
|
||||
}
|
||||
|
||||
func sorted<
|
||||
@public func sorted<
|
||||
C: MutableCollection
|
||||
where C.GeneratorType.Element: Comparable, C.IndexType: RandomAccessIndex
|
||||
>(source: C) -> C {
|
||||
@@ -225,7 +231,7 @@ func sorted<
|
||||
return result
|
||||
}
|
||||
|
||||
func sorted<
|
||||
@public func sorted<
|
||||
S: Sequence
|
||||
>(
|
||||
source: S,
|
||||
@@ -236,7 +242,7 @@ func sorted<
|
||||
return result
|
||||
}
|
||||
|
||||
func sorted<
|
||||
@public func sorted<
|
||||
S: Sequence
|
||||
where S.GeneratorType.Element: Comparable
|
||||
>(
|
||||
@@ -247,7 +253,7 @@ func sorted<
|
||||
return result
|
||||
}
|
||||
|
||||
func insertionSort<
|
||||
@public func insertionSort<
|
||||
C: MutableCollection where C.IndexType: RandomAccessIndex,
|
||||
C.GeneratorType.Element: Comparable>(
|
||||
inout elements: C,
|
||||
@@ -293,7 +299,7 @@ func insertionSort<
|
||||
/// Partition a non empty range into two partially sorted regions and return
|
||||
/// the index of the pivot:
|
||||
/// [start..idx), pivot ,[idx..end)
|
||||
func partition<
|
||||
@public func partition<
|
||||
C: MutableCollection where C.GeneratorType.Element: Comparable
|
||||
, C.IndexType: RandomAccessIndex
|
||||
>(
|
||||
@@ -332,7 +338,7 @@ func partition<
|
||||
return i.predecessor()
|
||||
}
|
||||
|
||||
func quickSort<
|
||||
@public func quickSort<
|
||||
C: MutableCollection
|
||||
where C.GeneratorType.Element: Comparable, C.IndexType: RandomAccessIndex
|
||||
>(
|
||||
@@ -361,7 +367,7 @@ func _quickSort<
|
||||
//// End of non-predicate sort functions.
|
||||
|
||||
|
||||
func swap<T>(inout a : T, inout b : T) {
|
||||
@public func swap<T>(inout a : T, inout b : T) {
|
||||
// Semantically equivalent to (a, b) = (b, a).
|
||||
// Microoptimized to avoid retain/release traffic.
|
||||
let p1 = Builtin.addressof(&a)
|
||||
@@ -376,7 +382,7 @@ func swap<T>(inout a : T, inout b : T) {
|
||||
}
|
||||
|
||||
|
||||
func min<T : Comparable>(x: T, y: T) -> T {
|
||||
@public func min<T : Comparable>(x: T, y: T) -> T {
|
||||
var r = x
|
||||
if y < x {
|
||||
r = y
|
||||
@@ -384,7 +390,7 @@ func min<T : Comparable>(x: T, y: T) -> T {
|
||||
return r
|
||||
}
|
||||
|
||||
func min<T : Comparable>(x: T, y: T, z: T, rest: T...) -> T {
|
||||
@public func min<T : Comparable>(x: T, y: T, z: T, rest: T...) -> T {
|
||||
var r = x
|
||||
if y < x {
|
||||
r = y
|
||||
@@ -400,7 +406,7 @@ func min<T : Comparable>(x: T, y: T, z: T, rest: T...) -> T {
|
||||
return r
|
||||
}
|
||||
|
||||
func max<T : Comparable>(x: T, y: T) -> T {
|
||||
@public func max<T : Comparable>(x: T, y: T) -> T {
|
||||
var r = y
|
||||
if y < x {
|
||||
r = x
|
||||
@@ -408,7 +414,7 @@ func max<T : Comparable>(x: T, y: T) -> T {
|
||||
return r
|
||||
}
|
||||
|
||||
func max<T : Comparable>(x: T, y: T, z: T, rest: T...) -> T {
|
||||
@public func max<T : Comparable>(x: T, y: T, z: T, rest: T...) -> T {
|
||||
var r = y
|
||||
if y < x {
|
||||
r = x
|
||||
@@ -424,7 +430,7 @@ func max<T : Comparable>(x: T, y: T, z: T, rest: T...) -> T {
|
||||
return r
|
||||
}
|
||||
|
||||
func split<Seq: Sliceable, R:LogicValue>(
|
||||
@public func split<Seq: Sliceable, R:LogicValue>(
|
||||
seq: Seq,
|
||||
isSeparator: (Seq.GeneratorType.Element)->R,
|
||||
maxSplit: Int = Int.max,
|
||||
@@ -471,7 +477,7 @@ func split<Seq: Sliceable, R:LogicValue>(
|
||||
|
||||
/// Return true iff the elements of `e1` are equal to the initial
|
||||
/// elements of `e2`.
|
||||
func startsWith<
|
||||
@public func startsWith<
|
||||
S0: Sequence, S1: Sequence
|
||||
where
|
||||
S0.GeneratorType.Element == S1.GeneratorType.Element,
|
||||
@@ -490,8 +496,8 @@ func startsWith<
|
||||
return g1.next() ? false : true
|
||||
}
|
||||
|
||||
struct EnumerateGenerator<Base: Generator> : Generator, Sequence {
|
||||
typealias Element = (index: Int, element: Base.Element)
|
||||
@public struct EnumerateGenerator<Base: Generator> : Generator, Sequence {
|
||||
@public typealias Element = (index: Int, element: Base.Element)
|
||||
var base: Base
|
||||
var count: Int
|
||||
|
||||
@@ -500,20 +506,20 @@ struct EnumerateGenerator<Base: Generator> : Generator, Sequence {
|
||||
count = 0
|
||||
}
|
||||
|
||||
mutating func next() -> Element? {
|
||||
@public mutating func next() -> Element? {
|
||||
var b = base.next()
|
||||
if !b { return .None }
|
||||
return .Some((index: count++, element: b!))
|
||||
}
|
||||
|
||||
// Every Generator is also a single-pass Sequence
|
||||
typealias GeneratorType = EnumerateGenerator<Base>
|
||||
func generate() -> GeneratorType {
|
||||
@public typealias GeneratorType = EnumerateGenerator<Base>
|
||||
@public func generate() -> GeneratorType {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
func enumerate<Seq : Sequence>(
|
||||
@public func enumerate<Seq : Sequence>(
|
||||
seq: Seq
|
||||
) -> EnumerateGenerator<Seq.GeneratorType> {
|
||||
return EnumerateGenerator(seq.generate())
|
||||
@@ -521,7 +527,7 @@ func enumerate<Seq : Sequence>(
|
||||
|
||||
|
||||
/// Return true iff `a1` and `a2` contain the same elements.
|
||||
func equal<
|
||||
@public func equal<
|
||||
S1 : Sequence, S2 : Sequence
|
||||
where
|
||||
S1.GeneratorType.Element == S2.GeneratorType.Element,
|
||||
@@ -546,7 +552,7 @@ func equal<
|
||||
|
||||
/// Return true iff `a1` and `a2` contain the same elements, using
|
||||
/// `pred` as equality `==` comparison.
|
||||
func equal<
|
||||
@public func equal<
|
||||
S1 : Sequence, S2 : Sequence
|
||||
where
|
||||
S1.GeneratorType.Element == S2.GeneratorType.Element
|
||||
@@ -571,7 +577,7 @@ func equal<
|
||||
|
||||
/// Return true iff a1 precedes a2 in a lexicographical ("dictionary")
|
||||
/// ordering, using "<" as the comparison between elements.
|
||||
func lexicographicalCompare<
|
||||
@public func lexicographicalCompare<
|
||||
S1 : Sequence, S2 : Sequence
|
||||
where
|
||||
S1.GeneratorType.Element == S2.GeneratorType.Element,
|
||||
@@ -600,7 +606,7 @@ func lexicographicalCompare<
|
||||
|
||||
/// Return true iff `a1` precedes `a2` in a lexicographical ("dictionary")
|
||||
/// ordering, using `less` as the comparison between elements.
|
||||
func lexicographicalCompare<
|
||||
@public func lexicographicalCompare<
|
||||
S1 : Sequence, S2 : Sequence
|
||||
where
|
||||
S1.GeneratorType.Element == S2.GeneratorType.Element
|
||||
@@ -630,7 +636,7 @@ func lexicographicalCompare<
|
||||
}
|
||||
|
||||
/// Return `true` iff an element in `seq` satisfies `predicate`.
|
||||
func contains<
|
||||
@public func contains<
|
||||
S: Sequence, L: LogicValue
|
||||
>(seq: S, predicate: (S.GeneratorType.Element)->L) -> Bool {
|
||||
for a in seq {
|
||||
@@ -642,13 +648,13 @@ func contains<
|
||||
}
|
||||
|
||||
/// Return `true` iff `x` is in `seq`.
|
||||
func contains<
|
||||
@public func contains<
|
||||
S: Sequence where S.GeneratorType.Element: Equatable
|
||||
>(seq: S, x: S.GeneratorType.Element) -> Bool {
|
||||
return contains(seq, { $0 == x })
|
||||
}
|
||||
|
||||
func reduce<S: Sequence, U>(
|
||||
@public func reduce<S: Sequence, U>(
|
||||
sequence: S, initial: U, combine: (U, S.GeneratorType.Element)->U
|
||||
) -> U {
|
||||
var result = initial
|
||||
|
||||
Reference in New Issue
Block a user