Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
04c7d94
Migrate _copyContents to be called from UnsafeMutableBufferPointer wi…
airspeedswift Oct 28, 2016
dbf4bf9
Move += operator for append(contentsOf:) up to RangeReplaceableCollec…
airspeedswift Oct 31, 2016
3677d8e
Added test of += matching .append(contentsOf:) to StdLibUnitTest
airspeedswift Oct 31, 2016
acfc744
Added test for undercounted collection not crashing
airspeedswift Nov 1, 2016
c857dab
Switch to _copyContents returning an (Iterator,UnsafeBuffer.Index)
airspeedswift Nov 4, 2016
3074318
perf improvement to Sequence._copyContents
airspeedswift Dec 18, 2016
6b9c3a5
Merge branch 'master' into collapse-append-contentsof
airspeedswift Dec 18, 2016
38bb800
Fix accidental miscommit
airspeedswift Dec 18, 2016
e6d2eb8
add tests of generic append
airspeedswift Dec 18, 2016
abc83ad
Merge pull request #6377 from airspeedswift/add-append-tests
airspeedswift Dec 19, 2016
fdd02f6
[CMake] Stop linking CoreFoundation into swiftc and libobjc into ever…
jrose-apple Dec 22, 2016
0936c51
[swiftc (83 vs. 5325)] Add crasher in swift::TypeChecker::checkAutoCl…
practicalswift Dec 22, 2016
1889fde
Resolve `type(of:)` by overload resolution rather than parse hackery.
jckarter Dec 20, 2016
23f25e1
In immediate mode, detect the host OS version on Apple platforms.
jrose-apple Dec 22, 2016
ee5ed7b
[IRGen] Code Size Reduction: Outline Copy/Consume (Loadable) Enum
Dec 21, 2016
b538baa
[ClangImporter] Simplify importFunctionType too.
jrose-apple Dec 22, 2016
d1e0877
[ClangImporter] "Fix" too-wide bitfield.
jrose-apple Dec 22, 2016
0c92978
Sema: Handle type-checking for withoutActuallyEscaping.
jckarter Dec 22, 2016
d5046a6
[gardening] Make sure argument names in comments match the actual par…
practicalswift Dec 23, 2016
f42fa36
[Diagnostics] Type-check return of the multi-statement closure withou…
xedin Dec 23, 2016
3a61fba
[Diagnostics] Mark all closure result type-checking related crashers …
xedin Dec 24, 2016
047f7e0
[QoI] Allow computeAssignDestType to return UnresolvedType to facilit…
xedin Dec 25, 2016
dab14d3
[TypeChecker] Fix isAnyHashableType to check type variables
xedin Dec 26, 2016
951395c
[Diagnostics] Explicitly disallow solutions with unresolved types whe…
xedin Dec 26, 2016
b02568f
[ASTDumper] More colors, compat with print methods
modocache Dec 26, 2016
9d62225
[ASTDumper] Print colors for Expr
modocache Dec 26, 2016
6116001
[ASTDumper] Use color when printing patterns
modocache Dec 26, 2016
3185571
[ASTDumper] Use color when printing Decl
modocache Dec 26, 2016
e58648a
[ASTDumper] Use color when printing AST nodes
modocache Dec 26, 2016
755c0a6
[ASTDumper] Use color when printing parameters
modocache Dec 26, 2016
02738a5
[ASTDumper] Use color when printing Stmt
modocache Dec 26, 2016
11a46ff
[ASTDumper] Use color when printing identifiers
modocache Dec 26, 2016
8459212
[ASTDumper] Use color when printing TypeRepr
modocache Dec 26, 2016
71a9292
[ASTDumper] Use color when printing protocols
modocache Dec 26, 2016
4cc3397
[QoI] Ignore erroneous default literal types in lookup
xedin Dec 27, 2016
464fee9
Remove lib prefix from Windows stdlib libraries
hughbe Dec 27, 2016
db27ccf
[QoI] Don't walk into erroneous apply expressions while validating to…
xedin Dec 28, 2016
b236244
[QoI] Don't try to type-check closure return statement if it involves…
xedin Dec 28, 2016
5022c25
Mark as fixed.
practicalswift Dec 29, 2016
a26254b
Mark as fixed.
practicalswift Dec 29, 2016
88a06fb
Use annotation "REQUIRES: deterministic-behavior"
practicalswift Dec 29, 2016
7b82cf8
SILOptimizer: Fix Mandatory Inlining problem with opened existentials
slavapestov Dec 28, 2016
ce60a22
Merge branch 'master' into collapse-append-contentsof
airspeedswift Dec 30, 2016
fee0727
updated UnsafeBuffer.initialize(from:) docs and labelled returned tuple
airspeedswift Dec 30, 2016
8c4b871
[QoI] Fix recursive propagation of materializability to look through …
xedin Dec 30, 2016
130e5fb
[QoI] Fix computeAssignDestType to mark lvalue enforcement type varia…
xedin Dec 30, 2016
d37e93d
[QoI] While merging equivalence classes don't forget to merge fixed t…
xedin Dec 31, 2016
faa7c74
Removed repetitive docstring
Dec 31, 2016
2b62ed2
Updated index(_:offsetBy:limitedBy:) code example
Dec 31, 2016
bd34ea5
remove trailing semicolons in stdlib source
jpsim Jan 1, 2017
ea5b665
prefer '-> Void' over '-> ()'
jpsim Jan 1, 2017
bb0af66
fix mismatched closure open/close spacing in stdlib source
jpsim Jan 1, 2017
7301b79
remove superfluous parentheses in control statements in stdlib source
jpsim Jan 1, 2017
2b24689
fix overly-spaced return arrows in XCTest.swift
jpsim Jan 1, 2017
83b6d3c
remove redundant optional nil assignment in stdlib source
jpsim Jan 1, 2017
fac59ce
[Diagnostics] Improve diagnostics of self assignment of the anonymous…
xedin Jan 1, 2017
bde054a
[DiagnosticsQoI] Look through argument tuples when diagnosing convers…
CodaFi Jan 1, 2017
25cb143
[CSGen] handle ForceValueExpr in LinkedExprAnalyzer
jtbandes Dec 31, 2016
7f29a33
[docs] Fix code snippet
ole Jan 2, 2017
63498f8
Revert "[AST Verifier] Hack: don't look for destructors of Clang nodes."
DougGregor Jan 3, 2017
832aa38
[Serialization] Be less lazy about deserialized generic environments.
DougGregor Jan 3, 2017
a202795
[Type checker] Fix a use-after-free due to StringRefs stored in Diagn…
DougGregor Jan 3, 2017
adb05f5
Merge pull request #6532 from DougGregor/modulefile-pending-actions
DougGregor Jan 3, 2017
9cebf0a
Merge pull request #6533 from DougGregor/diag-use-after-free
DougGregor Jan 3, 2017
ef49338
Revert "Introduce and use SWIFT_HAVE_LIBEDIT"
shahmishal Jan 3, 2017
f7b1cbc
Revert "Added HAVE_UNICODE_LIBEDIT instead of doing platform checks"
shahmishal Jan 3, 2017
6dbcfc9
Don't check access for compound TypeReprs in Swift 3 mode.
jrose-apple Jan 3, 2017
4fbd3e6
Don't check availability for compound TypeReprs in Swift 3 mode.
jrose-apple Jan 3, 2017
6705350
Merge pull request #6534 from apple/revert-6459-libedit-windows
shahmishal Jan 3, 2017
2706904
[SIL Box types] Handle box types with layouts with non-parameter requ…
DougGregor Jan 3, 2017
d2f490e
Merge pull request #6509 from slavapestov/mi-fix
shahmishal Jan 3, 2017
3ddf178
SILGen: Basic implementation of withoutActuallyEscaping.
jckarter Jan 3, 2017
0d09619
Merge pull request #6535 from jrose-apple/compounding-problems
jrose-apple Jan 3, 2017
f130bb1
Sema: Fix recent regression where generic parameters were considered …
slavapestov Jan 3, 2017
cd4a1eb
Merge pull request #6536 from slavapestov/fix-objc-inference-regression
slavapestov Jan 4, 2017
06b6ba6
Merge pull request #6479 from jrose-apple/importer-cleanup
jrose-apple Jan 4, 2017
6f25956
Merge pull request #6527 from jpsim/jp-remove-redundant-optional-nil-…
CodaFi Jan 4, 2017
5d18d27
Merge pull request #6529 from ole/patch-1
CodaFi Jan 4, 2017
3828784
Merge pull request #6526 from jpsim/jp-return-arrow-whitespace
CodaFi Jan 4, 2017
6dd2dda
Merge pull request #6525 from jpsim/jp-omit-control-statement-parens
CodaFi Jan 4, 2017
359a664
Merge pull request #6520 from jpsim/jp-trailing-semicolon
CodaFi Jan 4, 2017
46eb397
[RangeInfo] Some enrichment on reported range info. (#6475)
nkcsgexi Jan 4, 2017
e1822bc
Merge pull request #6516 from sigito/patch-1
CodaFi Jan 4, 2017
891729f
remove redundant '-> Void' return types from functions in stdlib source
jpsim Jan 1, 2017
9a389d5
Merge pull request #6456 from jrose-apple/it-is-a-lot-to-process
jrose-apple Jan 4, 2017
a598ed6
Sema: Fixes for generic typealiases and nested type lookup
slavapestov Jan 2, 2017
3fae2be
Format doxygen comment correctly.
gottesmm Dec 27, 2016
b95a34a
Add a new utility called reverse_range(start, end) that returns a rev…
gottesmm Dec 27, 2016
b5e3524
Introduce a new Cleanup called EndBorrowCleanup
gottesmm Dec 22, 2016
fd5b46d
Mirror +1 rvalue SILGenFunction convenience APIs for +0 rvalues.
gottesmm Dec 22, 2016
e9319fa
Now that non-trivial +0 rvalues have cleanups, fix up a comment.
gottesmm Dec 22, 2016
e265cc6
Merge pull request #6499 from hughbe/lib-prefix-stdlib
swift-ci Jan 4, 2017
861f52c
Merge pull request #6540 from DougGregor/sil-box-deserialization
swift-ci Jan 4, 2017
e36b52c
Resolve some compiler crashers
CodaFi Dec 29, 2016
51dc142
[28419] Extend nested init-chaining diagnostics to defer statements
CodaFi Dec 29, 2016
c20e012
[28396] Remove an assert that is too strict.
CodaFi Dec 29, 2016
3a4eb3f
Validate an assumption in 'lookupConstructors'
CodaFi Dec 30, 2016
adb862d
[SR-3210] Closures aren't the only things that can implicitly capture…
CodaFi Dec 31, 2016
9bb914a
[SR-3523] Coercions that implicitly look through IUOs should not prop…
CodaFi Jan 2, 2017
b294198
Merge pull request #6539 from slavapestov/nested-type-lookup-derived-…
slavapestov Jan 4, 2017
57ffa60
Merge pull request #6524 from jpsim/jp-remove-func-void-return
CodaFi Jan 4, 2017
87dd722
Merge pull request #6489 from xedin/assign-crashers
slavapestov Jan 4, 2017
bd53d2a
Merge pull request #6491 from xedin/crasher-28544
slavapestov Jan 4, 2017
822bb35
Merge pull request #6497 from xedin/crasher-28497
slavapestov Jan 4, 2017
0a179db
Merge pull request #6492 from xedin/crasher-28505
slavapestov Jan 4, 2017
fb35153
[Diagnostics] When checking AssignExpr properly diagnose destination
xedin Dec 31, 2016
5330485
Merge pull request #6477 from gottesmm/semantic_sil_managed_value
gottesmm Jan 4, 2017
d1b1361
Merge pull request #6504 from CodaFi/crash-AAAAAHHH
slavapestov Jan 4, 2017
7db9ac9
Merge pull request #6518 from jtbandes/a-chain-is-only-as-strong-as-i…
slavapestov Jan 4, 2017
66e4597
Merge pull request #6451 from shajrawi/outline_enum_retain_release
Jan 4, 2017
796df2d
Merge pull request #6429 from jckarter/type-of-by-overload-resolution
jckarter Jan 4, 2017
f56f403
Merge pull request #6528 from CodaFi/minimum-escape-velocity
slavapestov Jan 4, 2017
00c1947
Merge pull request #6501 from xedin/crasher-28520
slavapestov Jan 4, 2017
4cb5aef
Merge pull request #6511 from xedin/crasher-28586
slavapestov Jan 4, 2017
5da7e10
Merge pull request #6481 from xedin/diagnose-closure-return
slavapestov Jan 4, 2017
053ca89
Merge pull request #6476 from practicalswift/swiftc-28595-typeinconte…
slavapestov Jan 4, 2017
eb78182
Merge pull request #6510 from xedin/crasher-28592
slavapestov Jan 4, 2017
ad01c1e
SILGen: Implement missing function conversions from tuples to Any
slavapestov Dec 22, 2016
2517701
SILGen: Emit local types with a separate pass instead of while walkin…
slavapestov Dec 23, 2016
9f8ccd4
SILGen: Fix for tuple conversions in function argument position
slavapestov Dec 31, 2016
ab81426
SIL: Fix SILType substitution bug with DynamicSelfType vs MetatypeType
slavapestov Dec 31, 2016
54754c5
SILGen: Fix dynamic calls of 'throwing' methods
slavapestov Jan 1, 2017
4daf56b
SILGen: Fix calls to literal constructors defined in protocol extensions
slavapestov Jan 1, 2017
5f9fe6f
SILGen: Fix crash with non-scalar casts requiring re-abstraction
slavapestov Jan 1, 2017
3b388df
SILGen: Don't try using materializeForSet with storage in an @objc pr…
slavapestov Jan 2, 2017
fca7b66
Merge pull request #6521 from jpsim/jp-void-return
CodaFi Jan 4, 2017
65688bd
[gardening] replace unused closure parameters with '_' in stdlib sour…
jpsim Jan 4, 2017
dfed050
Merge pull request #6505 from practicalswift/mark-as-fixed
slavapestov Jan 4, 2017
a8da5b8
Merge pull request #6514 from xedin/SR_3506
slavapestov Jan 4, 2017
7258861
Merge pull request #6515 from xedin/crasher-28588
slavapestov Jan 4, 2017
88ecaad
Merge pull request #6543 from slavapestov/small-silgen-fixes
slavapestov Jan 4, 2017
f801430
Merge pull request #6517 from sigito/patch-2
swift-ci Jan 4, 2017
02c665f
[Serialization] Associated types are never private. (#6537)
jrose-apple Jan 4, 2017
2c7aae4
Sema: 'Never'-returning functions can be represented in Objective-C
slavapestov Dec 23, 2016
7e1bc3c
AST: Fix calls to protocol extension methods from class methods retur…
slavapestov Dec 30, 2016
fdaace5
Sema: Fix terrible bug with the '() -> T' => '() -> ()' implicit conv…
slavapestov Dec 30, 2016
a27d554
Sema: Fix SILGen crash with throwing @objc constructor with single tu…
slavapestov Jan 1, 2017
8bfe205
AST: Make TypeBase::getSuperclass() return the superclass type when c…
slavapestov Dec 22, 2016
48c529b
Resolve SIL crasher which started passing at some point
slavapestov Jan 2, 2017
b258ebe
Merge pull request #6482 from practicalswift/§
swift-ci Jan 4, 2017
954f7d0
Merge pull request #6545 from slavapestov/small-sema-fixes
slavapestov Jan 4, 2017
6bea953
Merge pull request #6523 from jpsim/jp-inconsistent-closure-spacing
slavapestov Jan 4, 2017
54752d4
Merge pull request #6495 from modocache/ast-dump-colors
slavapestov Jan 4, 2017
645d262
IRGen: Fix Clang type conversion for pointers to optionals of metatypes
slavapestov Jan 1, 2017
9f30532
Sema: Fix closeExistential() in CSApply with invalid direct call of m…
slavapestov Dec 25, 2016
9db06ee
Sema: Fixes for handling of 'Self'-returning methods
slavapestov Dec 25, 2016
4d34975
SIL: Use new TypeBase::eraseDynamicSelfType()
slavapestov Dec 28, 2016
a72eba1
SILGen: Implement function conversions involving opened existentials
slavapestov Dec 28, 2016
b5da219
Sema: Fix crash when closing an existential reference necessitates tu…
slavapestov Dec 29, 2016
9b03f9d
SILGen: Fix reabstraction thunk emission when generic parameters are …
slavapestov Dec 30, 2016
1682052
This test requires Objective-C interop
slavapestov Dec 30, 2016
709e12d
Merge pull request #6546 from slavapestov/existential-dilemma
slavapestov Jan 4, 2017
f19cbef
Sema: Try harder not to perform lookups into tuple types
slavapestov Dec 23, 2016
8f96606
Sema: Remove TupleToScalar conversion, which did nothing useful excep…
slavapestov Dec 23, 2016
0107840
Merge pull request #6548 from slavapestov/fix-tuple-crash-on-invalid
slavapestov Jan 4, 2017
32ebe2d
Parse: Don't crash if property with no declared type has addressors
slavapestov Dec 23, 2016
e6ada30
Parse: Fix crash when alignment is too large
slavapestov Dec 23, 2016
c7ab11f
Sema: Fix crash in 'var' parameter migration
slavapestov Dec 23, 2016
2932aac
AST: More accurate AbstractFunctionDecl::getImplicitSelfDecl()
slavapestov Dec 25, 2016
d406c4d
ASTVerifier: Don't check Override attribute if we haven't done early …
slavapestov Dec 25, 2016
469cccd
Sema: Avoid infinite recursion in associated type inference
slavapestov Dec 25, 2016
e455085
Sema: When opening an UnboundGenericType, don't put replacements in t…
slavapestov Dec 25, 2016
a230bde
AST: Clean up getDeclaredType() and friends
slavapestov Dec 23, 2016
cc2ae7b
AST: Fix crash with invalid generic environment
slavapestov Dec 23, 2016
b6d8bbb
AST: Return abstract conformance for UnresolvedType
slavapestov Dec 24, 2016
2b05dd9
AST: Remove error path that was causing crashes
slavapestov Dec 20, 2016
af934f2
Sema: Allow local types to conform to protocols with associated types
slavapestov Dec 25, 2016
2eeb8f5
AST: Fix crash when type nested inside generic function conforms to a…
slavapestov Dec 26, 2016
e4abdfc
AST: Model protocols nested inside other types
slavapestov Dec 25, 2016
0a7e1d5
Sema: Fix crash in conformance checking
slavapestov Dec 23, 2016
1fc7dbe
Merge pull request #6549 from slavapestov/fix-assorted-crashers
slavapestov Jan 4, 2017
b8d60e9
Sema: Clean up logic for forming type witness substitutions
slavapestov Dec 26, 2016
3d7cac5
Sema: Simplify checkUnsupportedNestedGeneric()
slavapestov Dec 23, 2016
fd3101e
ASTVerifier: Add missing newline in some printouts
slavapestov Dec 25, 2016
71df32f
Sema: Add some asserts
slavapestov Dec 25, 2016
43ce2e7
AST: Simplify DeclContext::getGeneric{Signature,Environment}OfContext()
slavapestov Dec 15, 2016
2555135
AST: Remove DeclContext::isValidGenericContext()
slavapestov Dec 26, 2016
064fda5
AST: Remove Type::getCanonicalTypeOrNull()
slavapestov Dec 28, 2016
16bb0cd
AST: Remove some dead code from UnqualifiedLookup logic
slavapestov Jan 2, 2017
9e6089a
[bug-reducer] Fix an issue where we would always print the last optim…
gottesmm Jan 4, 2017
4b24cd4
Merge pull request #6551 from gottesmm/bug_reducer_fix
swift-ci Jan 4, 2017
6c9f99f
Merge pull request #6550 from slavapestov/sema-cleanups
slavapestov Jan 4, 2017
584f47d
Sema: Fix crashes in CSDiag
slavapestov Dec 25, 2016
18adb53
Sema: Tighten up name lookup routines to not look through metatypes/l…
slavapestov Jan 3, 2017
41dde88
Sema: Allow unqualified type lookup to find typealiases in protocols
slavapestov Jan 3, 2017
e65d867
Merge pull request #6552 from slavapestov/protocol-typealias-unqualif…
slavapestov Jan 4, 2017
412559a
Add test cases for a few bugs that seem to be fixed already
slavapestov Dec 22, 2016
b47eff1
Merge pull request #6553 from slavapestov/some-more-regression-tests
slavapestov Jan 4, 2017
ab56a69
[swiftc (20 vs. 5389)] Add crasher in swift::GenericSignature::enumer…
practicalswift Jan 4, 2017
1aeca5b
Merge pull request #6555 from practicalswift/swiftc-28596-unreachable…
practicalswift Jan 4, 2017
a5ae8a5
[swiftc (21 vs. 5389)] Add crasher in swift::NewMangling::Mangler::ap…
practicalswift Jan 4, 2017
146a537
Merge pull request #6556 from practicalswift/swiftc-28597-first-char-…
practicalswift Jan 4, 2017
12cbf5d
[swiftc (22 vs. 5389)] Add crasher in swift::IterativeTypeChecker::sa…
practicalswift Jan 4, 2017
d9624dc
Merge pull request #6557 from practicalswift/swiftc-28598-issatisfied…
practicalswift Jan 4, 2017
673b297
[swiftc (23 vs. 5389)] Add crasher in swift::TypeChecker::resolveType…
practicalswift Jan 4, 2017
c80559d
Merge pull request #6558 from practicalswift/swiftc-28599-false-shoul…
practicalswift Jan 4, 2017
150d484
[swiftc (24 vs. 5389)] Add crasher in swift::Parser::parseTopLevel(...)
practicalswift Jan 4, 2017
7268654
Merge pull request #6559 from practicalswift/swiftc-28600-isinsilmode…
practicalswift Jan 4, 2017
c3bce78
[swiftc (25 vs. 5389)] Add crasher in swift::ASTVisitor
practicalswift Jan 4, 2017
b1c793e
[PrintAsObjC] Special-case <os/object.h> types, like Dispatch. (#6544)
jrose-apple Jan 4, 2017
92dd5f5
Integrated upstream change to Data
airspeedswift Jan 4, 2017
ca7046e
Merge pull request #6560 from practicalswift/swiftc-28601-getkind-exp…
practicalswift Jan 4, 2017
c8ced0d
Migrate _copyContents to be called from UnsafeMutableBufferPointer wi…
airspeedswift Oct 28, 2016
1c48b31
Move += operator for append(contentsOf:) up to RangeReplaceableCollec…
airspeedswift Oct 31, 2016
dc1b6ae
Added test of += matching .append(contentsOf:) to StdLibUnitTest
airspeedswift Oct 31, 2016
3b25d59
Added test for undercounted collection not crashing
airspeedswift Nov 1, 2016
f484576
Switch to _copyContents returning an (Iterator,UnsafeBuffer.Index)
airspeedswift Nov 4, 2016
299db43
perf improvement to Sequence._copyContents
airspeedswift Dec 18, 2016
db520f2
Fix accidental miscommit
airspeedswift Dec 18, 2016
f91e043
updated UnsafeBuffer.initialize(from:) docs and labelled returned tuple
airspeedswift Dec 30, 2016
71fea23
Integrated upstream change to Data
airspeedswift Jan 4, 2017
ba49dac
Merge branch 'collapse-append-contentsof' of github.com:airspeedswift…
airspeedswift Jan 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@ self.test("\(testNamePrefix).append(contentsOf:)/semantics") {
}
}

self.test("\(testNamePrefix).OperatorPlusEquals") {
for test in appendContentsOfTests {
var c = makeWrappedCollection(test.collection)
let newElements =
MinimalCollection(elements: test.newElements.map(wrapValue))
c += newElements
expectEqualSequence(
test.expected,
c.map { extractValue($0).value },
stackTrace: SourceLocStack().with(test.loc))
}
}

//===----------------------------------------------------------------------===//
// insert()
//===----------------------------------------------------------------------===//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,14 @@ public func checkSequence<
_ = sequence._preprocessingPass { () -> Void in
var count = 0
for _ in sequence { count += 1 }
let buf = UnsafeMutablePointer<S.Iterator.Element>.allocate(capacity: count)
let end = sequence._copyContents(initializing: buf)
expectTrue(end == buf + count, "_copyContents returned the wrong value")
var j = expected.startIndex
for i in 0..<(end - buf) {
expectTrue(sameValue(expected[j], buf[i]))
j = expected.index(after: j)
}
buf.deinitialize(count: end - buf)
buf.deallocate(capacity: count)
let ptr = UnsafeMutablePointer<S.Iterator.Element>.allocate(capacity: count)
let buf = UnsafeMutableBufferPointer(start: ptr, count: count)
var remainders = sequence._copyContents(initializing: buf)
expectTrue(remainders == nil || remainders!.next() == nil,
"_copyContents returned unwritten elements")
expectEqualSequence(expected, buf, ${trace}, sameValue: sameValue)
ptr.deinitialize(count: count)
ptr.deallocate(capacity: count)
}

// Test `_copyToContiguousArray()` if we can do so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public struct ${Self}<

public typealias Iterator = LoggingIterator<Base.Iterator>

public func makeIterator() -> LoggingIterator<Base.Iterator> {
public func makeIterator() -> Iterator {
Log.makeIterator[selfType] += 1
return LoggingIterator(wrapping: base.makeIterator())
}
Expand Down Expand Up @@ -321,10 +321,10 @@ public struct ${Self}<

/// Copy a Sequence into an array.
public func _copyContents(
initializing ptr: UnsafeMutablePointer<Base.Iterator.Element>
) -> UnsafeMutablePointer<Base.Iterator.Element> {
initializing buf: UnsafeMutableBufferPointer<Iterator.Element>
) -> Iterator? {
Log._copyContents[selfType] += 1
return base._copyContents(initializing: ptr)
return base._copyContents(initializing: buf).map(Iterator.init)
}

% if Kind in ['Collection', 'MutableCollection', 'RangeReplaceableCollection']:
Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/SDK/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
}

if replacementCount != 0 {
newElements._copyContents(initializing: bytes + start)
let buf = UnsafeMutableBufferPointer(start: bytes + start, count: numericCast(newElements.count))
// FIXME: is this guaranteed to return no residual elements?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this have the same correctness hole as append(contentsOf:)? The Data API can't guarantee that the generic collection argument is implemented correctly. In my mind we at least need an assert. Then it's a question of whether, in release mode, we want to crash with a fatalError or drop elements. Why not make it a fatalError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it needs to trap, especially for underflow in this case since it if it doesn't use the entire expected range it will leave corrupt data behind (specific to this being a replaceSubrange use case).

let _ = newElements._copyContents(initializing: buf)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions stdlib/public/core/ArrayType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ internal protocol _ArrayProtocol
/// - Complexity: O(`self.count`).
mutating func reserveCapacity(_ minimumCapacity: Int)

/// Operator form of `append(contentsOf:)`.
static func += <S : Sequence>(lhs: inout Self, rhs: S)
where S.Iterator.Element == Iterator.Element

/// Insert `newElement` at index `i`.
///
/// Invalidates all indices with respect to `self`.
Expand Down
109 changes: 17 additions & 92 deletions stdlib/public/core/Arrays.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {

/// Adds the elements of a sequence to the end of the array.
///
/// Use this method to append the elements of a sequence to the end of an
/// Use this method to append the elements of a sequence to the end of this
/// array. This example appends the elements of a `Range<Int>` instance
/// to an array of integers.
///
Expand All @@ -1293,39 +1293,8 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
/// - Complexity: O(*n*), where *n* is the length of the resulting array.
public mutating func append<S : Sequence>(contentsOf newElements: S)
where S.Iterator.Element == Element {
let oldCount = self.count
let capacity = self.capacity
let newCount = oldCount + newElements.underestimatedCount

if newCount > capacity {
self.reserveCapacity(
Swift.max(newCount, _growArrayCapacity(capacity)))
}
_buffer._arrayAppendSequence(newElements)
}

// An overload of `append(contentsOf:)` that uses the += that is optimized for
// collections.
// FIXME(ABI)#13 (Performance): remove this entrypoint. The overload for `Sequence` should be
// made optimal for this case, too.
/// Adds the elements of a collection to the end of the array.
///
/// Use this method to append the elements of a collection to the end of this
/// array. This example appends the elements of a `Range<Int>` instance
/// to an array of integers.
///
/// var numbers = [1, 2, 3, 4, 5]
/// numbers.append(contentsOf: 10...15)
/// print(numbers)
/// // Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
///
/// - Parameter newElements: The elements to append to the array.
///
/// - Complexity: O(*n*), where *n* is the length of the resulting array.
public mutating func append<C : Collection>(contentsOf newElements: C)
where C.Iterator.Element == Element {

let newElementsCount = numericCast(newElements.count) as Int
let newElementsCount = newElements.underestimatedCount

let oldCount = self.count
let capacity = self.capacity
Expand All @@ -1338,8 +1307,13 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
Swift.max(newCount, _growArrayCapacity(capacity))
: newCount)

(self._buffer.firstElementAddress + oldCount).initialize(from: newElements)
self._buffer.count = newCount
let buf = UnsafeMutableBufferPointer(start: _buffer.firstElementAddress + oldCount, count: newElementsCount)
_buffer.count = newCount
if let remainder = buf.initialize(from: newElements) {
// there were elements that didn't fit in the existing buffer,
// append them in slow sequence-only mode
_buffer._arrayAppendSequence(IteratorSequence(remainder))
}
}

%if Self == 'ArraySlice':
Expand Down Expand Up @@ -1624,23 +1598,22 @@ extension ${Self} {
return try body(&inoutBufferPointer)
}

@discardableResult
public func _copyContents(
initializing ptr: UnsafeMutablePointer<Element>
) -> UnsafeMutablePointer<Element> {
if let s = self._baseAddressIfContiguous {
let count = self.count
ptr.initialize(from: s, count: count)
initializing buf: UnsafeMutableBufferPointer<Element>
) -> Iterator? {
// FIXME: decide if this really is a fatalError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would nil base address be an error? An empty buffer is supposed to be nil.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"An empty buffer is supposed to be nil." Is it? Surely an empty buffer is just a buffer where startIndex == endIndex – it can still have a baseAddress. i.e. likely cause of empty buffer is that there was no "spare" storage on the end – but that will still have a non-nil pointer inside the buffer, just an zero-sized view onto it. I can understand wanting to sometimes be able to represent an empty buffer by never allocating any memory hence baseAddress is optional, but not always, and in this case I suspect that might happen only in error – why would you call initialize on a buffer based on memory you haven't allocated?

guard var p = buf.baseAddress
else { fatalError("Attempt to copy contents into nil buffer pointer") }
if let s = _baseAddressIfContiguous {
p.initialize(from: s, count: self.count)
_fixLifetime(self._owner)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish all _fixLifetime calls came with a comment. In this case, AFAICT the issue is that we need a _fixLifetime bracketing the _baseAddressIfContiguous getter and all uses of the pointer it returns.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confident enough of this for me to add this as the comment above this on? 😀

return ptr + count
} else {
var p = ptr
for x in self {
p.initialize(to: x)
p += 1
}
return p
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing. The Sequence._copyContents interface claims to support under-sized buffer arguments. But this implementation clearly doesn't support that. Is there a subtle assumption being made that Array always correctly reports it's count, thus we don't need to handle under-sized buffers? I don't think we can make any assumptions here because UnsafeMutableBufferPointer.initialize<S: Sequence>(from: S) is public.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the call into the appended collection, copying itself into the buffer of the appendee. The appended knows it didn't lie about it's count. The appendee is required to have allocated enough storage for it to append itself (though this should be documented as a precondition of initialize(from:), and checked here, will do that). This is different to the appendee collection, which can make no assumptions about the generic collection it received.

That said, based on benchmarks so far, this optimization might not be worth it.

}
}
%end
Expand Down Expand Up @@ -1766,54 +1739,6 @@ extension ${Self} {
}
}
}

// FIXME(ABI)#16 : remove this entrypoint. The functionality should be provided by
// a `+=` operator on `RangeReplaceableCollection`.
/// Appends the elements of a sequence to ${a_Self}.
///
/// Use this operator to append the elements of a sequence to the end of
/// ${a_Self} with same `Element` type. This example appends
/// the elements of a `Range<Int>` instance to an array of integers.
///
/// var numbers = [1, 2, 3, 4, 5]
/// numbers += 10...15
/// print(numbers)
/// // Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
///
/// - Parameters:
/// - lhs: The array to append to.
/// - rhs: A collection or finite sequence.
///
/// - Complexity: O(*n*), where *n* is the length of the resulting array.
public func += <
S : Sequence
>(lhs: inout ${Self}<S.Iterator.Element>, rhs: S) {
lhs.append(contentsOf: rhs)
}

// FIXME(ABI)#17 : remove this entrypoint. The functionality should be provided by
// a `+=` operator on `RangeReplaceableCollection`.
/// Appends the elements of a collection to ${a_Self}.
///
/// Use this operator to append the elements of a collection to the end of
/// ${a_Self} with same `Element` type. This example appends
/// the elements of a `Range<Int>` instance to an array of integers.
///
/// var numbers = [1, 2, 3, 4, 5]
/// numbers += 10...15
/// print(numbers)
/// // Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
///
/// - Parameters:
/// - lhs: The array to append to.
/// - rhs: A collection.
///
/// - Complexity: O(*n*), where *n* is the length of the resulting array.
public func += <
C : Collection
>(lhs: inout ${Self}<C.Iterator.Element>, rhs: C) {
lhs.append(contentsOf: rhs)
}
% end

//===--- generic helpers --------------------------------------------------===//
Expand Down
12 changes: 10 additions & 2 deletions stdlib/public/core/ContiguousArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,11 @@ internal func += <Element, C : Collection>(
let oldCount = lhs.count
let newCount = oldCount + numericCast(rhs.count)

let buf: UnsafeMutableBufferPointer<Element>

if _fastPath(newCount <= lhs.capacity) {
buf = UnsafeMutableBufferPointer(start: lhs.firstElementAddress + oldCount, count: numericCast(rhs.count))
lhs.count = newCount
(lhs.firstElementAddress + oldCount).initialize(from: rhs)
}
else {
var newLHS = _ContiguousArrayBuffer<Element>(
Expand All @@ -490,7 +492,13 @@ internal func += <Element, C : Collection>(
from: lhs.firstElementAddress, count: oldCount)
lhs.count = 0
swap(&lhs, &newLHS)
(lhs.firstElementAddress + oldCount).initialize(from: rhs)
buf = UnsafeMutableBufferPointer(start: lhs.firstElementAddress + oldCount, count: numericCast(rhs.count))
}

if let remainder = buf.initialize(from: rhs) {
// there were elements that didn't fit in the existing buffer,
// append them in slow sequence-only mode
//FIXME: handle this possibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title should have [WIP] if you don't actually intend to merge this as-is.

That said, why do you want to handle this case? Shouldn't we be consistent and make it a fatal error anywhere that Collection.count does not match the collections number of elements (assuming no intervening access to the Collection)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right, this function is taking a collection so underflow should trap.

}
}

Expand Down
22 changes: 13 additions & 9 deletions stdlib/public/core/ExistentialCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ internal class _AnyRandomAccessCollectionBox<Element>
_abstract()
}

internal func __copyContents(initializing ptr: UnsafeMutablePointer<Element>)
-> UnsafeMutablePointer<Element> {
internal func __copyContents(initializing buf: UnsafeMutableBufferPointer<Element>)
-> AnyIterator<Element>? {
_abstract()
}

Expand Down Expand Up @@ -387,9 +387,9 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
internal override func __copyToContiguousArray() -> ContiguousArray<Element> {
return _base._copyToContiguousArray()
}
internal override func __copyContents(initializing ptr: UnsafeMutablePointer<Element>)
-> UnsafeMutablePointer<Element> {
return _base._copyContents(initializing: ptr)
internal override func __copyContents(initializing buf: UnsafeMutableBufferPointer<Element>)
-> AnyIterator<Element>? {
return _base._copyContents(initializing: buf).map(AnyIterator.init)
}
internal override func _drop(
while predicate: (Element) throws -> Bool
Expand Down Expand Up @@ -588,6 +588,8 @@ public struct AnySequence<Element> : Sequence {
self.init(_ClosureBasedSequence(makeUnderlyingIterator))
}

public typealias Iterator = AnyIterator<Element>

internal init(_box: _AnySequenceBox<Element>) {
self._box = _box
}
Expand All @@ -602,7 +604,7 @@ extension Any${Kind} {
% else:
/// Returns an iterator over the elements of this collection.
% end
public func makeIterator() -> AnyIterator<Element> {
public func makeIterator() -> Iterator {
return _box._makeIterator()
}

Expand Down Expand Up @@ -683,9 +685,9 @@ extension Any${Kind} {
return self._box.__copyToContiguousArray()
}

public func _copyContents(initializing ptr: UnsafeMutablePointer<Element>)
-> UnsafeMutablePointer<Element> {
return _box.__copyContents(initializing: ptr)
public func _copyContents(initializing buf: UnsafeMutableBufferPointer<Iterator.Element>)
-> Iterator? {
return _box.__copyContents(initializing: buf).map(AnyIterator.init)
}
}
% end
Expand Down Expand Up @@ -808,6 +810,8 @@ public struct ${Self}<Element>
// public typealias Indices
// = Default${Traversal.replace('Forward', '')}Indices<${Self}>

public typealias Iterator = AnyIterator<Element>

internal init(_box: _${Self}Box<Element>) {
self._box = _box
}
Expand Down
11 changes: 6 additions & 5 deletions stdlib/public/core/LazyCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ public struct ${Self}<Base : ${TraversalCollection}> : LazyCollectionProtocol {
/// Forward implementations to the base collection, to pick up any
/// optimizations it might implement.
extension ${Self} : Sequence {

public typealias Iterator = Base.Iterator

/// Returns an iterator over the elements of this sequence.
///
/// - Complexity: O(1).
public func makeIterator() -> Base.Iterator {
public func makeIterator() -> Iterator {
return _base.makeIterator()
}

Expand All @@ -94,11 +96,10 @@ extension ${Self} : Sequence {
return _base._copyToContiguousArray()
}

@discardableResult
public func _copyContents(
initializing ptr: UnsafeMutablePointer<Base.Iterator.Element>
) -> UnsafeMutablePointer<Base.Iterator.Element> {
return _base._copyContents(initializing: ptr)
initializing buf: UnsafeMutableBufferPointer<Iterator.Element>
) -> Iterator? {
return _base._copyContents(initializing: buf)
}

public func _customContainsEquatableElement(
Expand Down
Loading