Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdlib, SIL optimizer: use the SIL copy-on-write representation in the Array types. #32134

Merged
merged 6 commits into from Jun 9, 2020

Conversation

eeckstein
Copy link
Member

Use the new builtins for COW representation in Array, ContiguousArray and ArraySlice.
The basic idea is to strictly separate code which mutates an array buffer from code which reads from an array.
The concept is explained in more detail in docs/SIL.rst, section "Copy-on-Write Representation".

The main change is to use beginCOWMutation() instead of isUniquelyReferenced() and insert endCOWMutation() at the end of all mutating functions. Also, reading from the array buffer must be done differently, depending on if the buffer is in a mutable or immutable state.

All the required invariants are enforced by runtime checks - but only in an assert-build of the library: a bit in the buffer flags indicates if the buffer is mutable or not.

Along with the library changes, also two optimizations needed to be updated: COWArrayOpt and ObjectOutliner.

Another notable change is the new library intrinsic to "finalize" array literals: for COW support in SIL it's required to "finalize" array literals.
_finalizeUninitializedArray is a compiler known stdlib function which is called after all elements of an array literal are stored.
This runtime function marks the array literal as finished.

  %uninitialized_result_tuple = apply %_allocateUninitializedArray(%count)
  %mutable_array = tuple_extract %uninitialized_result_tuple, 0
  %elem_base_address = tuple_extract %uninitialized_result_tuple, 1
  ...
  store %elem_0 to %elem_addr_0
  store %elem_1 to %elem_addr_1
  ...
  %final_array = apply %_finalizeUninitializedArray(%mutable_array)

@eeckstein
Copy link
Member Author

@swift-ci test

@eeckstein
Copy link
Member Author

@swift-ci benchmark

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 2, 2020

Build failed
Swift Test OS X Platform
Git Sha - 17747fc

@eeckstein
Copy link
Member Author

@swift-ci test macOS

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 2, 2020

Performance: -O

Regression OLD NEW DELTA RATIO
RC4 78 183 +134.6% 0.43x
ArrayAppendLazyMap 850 1780 +109.4% 0.48x
Dictionary4 151 238 +57.6% 0.63x
Dictionary4OfObjects 188 256 +36.2% 0.73x
ArrayAppendRepeatCol 500 670 +34.0% 0.75x
LazilyFilteredRange 2160 2510 +16.2% 0.86x
String.replaceSubrange.RepChar.Small 261 294 +12.6% 0.89x
NopDeinit 8800 9900 +12.5% 0.89x (?)
Data.init.Sequence.2047B.Count.I 54 60 +11.1% 0.90x (?)
Data.init.Sequence.2049B.Count.I 54 60 +11.1% 0.90x (?)
Data.init.Sequence.511B.Count.I 67 73 +9.0% 0.92x (?)
CSVParsing.UTF8 23 25 +8.7% 0.92x
NormalizedIterator_latin1 212 230 +8.5% 0.92x
ArrayAppendReserved 250 270 +8.0% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
FlattenListLoop 2616 951 -63.6% 2.75x (?)
RemoveWhereSwapInts 40 15 -62.5% 2.67x
ArrayPlusEqualFiveElementCollection 4440 1739 -60.8% 2.55x
RemoveWhereMoveInts 17 7 -58.8% 2.43x
MapReduceAnyCollection 220 106 -51.8% 2.08x
MapReduceClass2 21 11 -47.6% 1.91x
MapReduce 186 107 -42.5% 1.74x
SuffixSequence 287 176 -38.7% 1.63x
SortIntPyramid 730 450 -38.4% 1.62x
SuffixSequenceLazy 287 177 -38.3% 1.62x
RemoveWhereSwapStrings 441 288 -34.7% 1.53x
SortAdjacentIntPyramids 960 660 -31.2% 1.45x
ArrayAppendSequence 680 500 -26.5% 1.36x (?)
BinaryFloatingPointPropertiesUlp 28 21 -25.0% 1.33x
PrefixWhileAnySeqCntRange 182 138 -24.2% 1.32x
PrefixWhileAnySeqCRangeIter 182 139 -23.6% 1.31x
ObjectiveCBridgeStubFromNSDate 3750 2930 -21.9% 1.28x (?)
MapReduceSequence 374 299 -20.1% 1.25x
RangeAssignment 213 171 -19.7% 1.25x
RandomShuffleLCG2 432 352 -18.5% 1.23x
Sim2DArray 358 301 -15.9% 1.19x
Chars2 3500 2950 -15.7% 1.19x
ObjectiveCBridgeStubDateAccess 152 130 -14.5% 1.17x (?)
MapReduceString 42 36 -14.3% 1.17x
Calculator 164 144 -12.2% 1.14x
SortStrings 529 468 -11.5% 1.13x
FlattenListFlatMap 3555 3162 -11.1% 1.12x (?)
SuffixAnySequence 1745 1566 -10.3% 1.11x (?)
SuffixAnySeqCntRange 653 589 -9.8% 1.11x
FilterEvenUsingReduce 880 800 -9.1% 1.10x (?)
AngryPhonebook.Armenian 169 154 -8.9% 1.10x (?)
AngryPhonebook.Cyrillic 181 165 -8.8% 1.10x (?)
MapReduceClassShort2 148 135 -8.8% 1.10x
MapReduceNSDecimalNumber 222 204 -8.1% 1.09x (?)
OpenClose 74 68 -8.1% 1.09x (?)
MapReduceAnyCollectionShort 1450 1340 -7.6% 1.08x (?)
RemoveWhereMoveStrings 297 275 -7.4% 1.08x (?)
ArraySubscript 884 820 -7.2% 1.08x (?)
MapReduceLazyCollectionShort 28 26 -7.1% 1.08x
ArrayPlusEqualThreeElements 1320 1230 -6.8% 1.07x (?)

Code size: -O

Regression OLD NEW DELTA RATIO
Substring.o 15643 16273 +4.0% 0.96x
PopFrontGeneric.o 2576 2624 +1.9% 0.98x
StringComparison.o 37050 37688 +1.7% 0.98x
IntegerParsing.o 56445 57309 +1.5% 0.98x
main.o 55611 56355 +1.3% 0.99x
 
Improvement OLD NEW DELTA RATIO
Walsh.o 7092 5316 -25.0% 1.33x
XorLoop.o 2045 1634 -20.1% 1.25x
ArraySubscript.o 2898 2396 -17.3% 1.21x
RC4.o 3911 3535 -9.6% 1.11x
Prims.o 13499 12515 -7.3% 1.08x
PrimsSplit.o 13551 12567 -7.3% 1.08x
ArrayOfGenericRef.o 8718 8142 -6.6% 1.07x
ArrayOfRef.o 9147 8571 -6.3% 1.07x
NopDeinit.o 3775 3551 -5.9% 1.06x
RemoveWhere.o 15907 14979 -5.8% 1.06x
BinaryFloatingPointProperties.o 5442 5138 -5.6% 1.06x
Array2D.o 3115 2955 -5.1% 1.05x
COWTree.o 11420 10836 -5.1% 1.05x
ClassArrayGetter.o 3571 3395 -4.9% 1.05x
DictionaryGroup.o 12435 11843 -4.8% 1.05x
RandomShuffle.o 3542 3382 -4.5% 1.05x
DiffingMyers.o 6437 6165 -4.2% 1.04x
PrimsNonStrongRef.o 126912 121896 -4.0% 1.04x
SortLettersInPlace.o 8437 8133 -3.6% 1.04x
Queue.o 12469 12053 -3.3% 1.03x
Sim2DArray.o 1286 1254 -2.5% 1.03x
Phonebook.o 9359 9135 -2.4% 1.02x
FlattenList.o 4042 3946 -2.4% 1.02x
StringEdits.o 10897 10657 -2.2% 1.02x
Breadcrumbs.o 42543 41615 -2.2% 1.02x
DriverUtils.o 142139 139151 -2.1% 1.02x
Hash.o 23217 22735 -2.1% 1.02x
FindStringNaive.o 9251 9059 -2.1% 1.02x
RangeReplaceableCollectionPlusDefault.o 5628 5516 -2.0% 1.02x
DropLast.o 22631 22183 -2.0% 1.02x
RGBHistogram.o 21934 21502 -2.0% 1.02x
Codable.o 30975 30407 -1.8% 1.02x
ReversedCollections.o 9222 9062 -1.7% 1.02x
Suffix.o 22757 22397 -1.6% 1.02x
ArraySetElement.o 1190 1174 -1.3% 1.01x
ObserverClosure.o 2390 2358 -1.3% 1.01x
ObserverPartiallyAppliedMethod.o 2453 2421 -1.3% 1.01x
COWArrayGuaranteedParameterOverhead.o 1265 1249 -1.3% 1.01x
DictionarySubscriptDefault.o 19299 19059 -1.2% 1.01x
DataBenchmarks.o 57205 56589 -1.1% 1.01x
Join.o 1511 1495 -1.1% 1.01x
RangeOverlaps.o 6102 6038 -1.0% 1.01x

Performance: -Osize

Regression OLD NEW DELTA RATIO
MapReduceLazyCollectionShort 30 67 +123.3% 0.45x
SuffixArrayLazy 5 9 +80.0% 0.56x
DropLastArray 5 9 +80.0% 0.56x
ArrayAppendRepeatCol 410 670 +63.4% 0.61x
PrefixWhileArrayLazy 26 40 +53.8% 0.65x
PrefixWhileAnyCollection 139 166 +19.4% 0.84x
SuffixAnyCollection 38 45 +18.4% 0.84x
UTF8Decode_InitFromCustom_noncontiguous_ascii 743 861 +15.9% 0.86x
UTF8Decode_InitFromCustom_noncontiguous_ascii_as_ascii 816 943 +15.6% 0.87x (?)
String.replaceSubrange.RepChar.Small 260 292 +12.3% 0.89x (?)
PrefixAnySeqCRangeIterLazy 108 121 +12.0% 0.89x
PrefixAnySeqCntRangeLazy 108 121 +12.0% 0.89x (?)
ChaCha 85 95 +11.8% 0.89x
DropFirstAnyCollection 101 112 +10.9% 0.90x (?)
UTF8Decode_InitFromCustom_noncontiguous 334 369 +10.5% 0.91x
ArraySetElement 263 285 +8.4% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
ArrayPlusEqualFiveElementCollection 4847 1739 -64.1% 2.79x
ArrayAppendLazyMap 2140 850 -60.3% 2.52x
DropLastCountableRangeLazy 9 4 -55.5% 2.25x
SuffixArray 9 4 -55.5% 2.25x
MapReduceAnyCollection 239 111 -53.6% 2.15x
MapReduce 241 112 -53.5% 2.15x
FlattenListLoop 3213 1514 -52.9% 2.12x
RemoveWhereSwapInts 36 17 -52.8% 2.12x
ArrayAppendSequence 1290 680 -47.3% 1.90x
RemoveWhereMoveInts 20 11 -45.0% 1.82x
Sim2DArray 365 208 -43.0% 1.75x
PrefixWhileSequenceLazy 40 26 -35.0% 1.54x
RemoveWhereSwapStrings 439 288 -34.4% 1.52x
Data.append.Sequence.64kB.Count.RE.I 44 29 -34.1% 1.52x
Data.append.Sequence.64kB.Count.RE 44 29 -34.1% 1.52x
Data.init.Sequence.64kB.Count.RE.I 43 29 -32.6% 1.48x
Data.init.Sequence.64kB.Count.RE 43 29 -32.6% 1.48x
PrefixWhileAnySeqCntRange 195 133 -31.8% 1.47x
PrefixWhileAnySeqCRangeIter 195 135 -30.8% 1.44x
ErrorHandling 910 650 -28.6% 1.40x
RangeAssignment 232 174 -25.0% 1.33x
Dictionary4 208 158 -24.0% 1.32x
MapReduceString 50 38 -24.0% 1.32x (?)
RandomShuffleLCG2 480 368 -23.3% 1.30x
Data.init.Sequence.809B.Count.RE 75 58 -22.7% 1.29x
Data.init.Sequence.809B.Count.RE.I 75 58 -22.7% 1.29x
MapReduceSequence 431 340 -21.1% 1.27x
Data.append.Sequence.809B.Count.RE 88 71 -19.3% 1.24x
Data.append.Sequence.809B.Count.RE.I 88 71 -19.3% 1.24x
DataAppendSequence 8800 7200 -18.2% 1.22x
Dictionary4OfObjects 276 229 -17.0% 1.21x
SuffixAnySequence 1919 1618 -15.7% 1.19x
StrToInt 1240 1080 -12.9% 1.15x
Chars2 3700 3250 -12.2% 1.14x
StringComparison_ascii 404 362 -10.4% 1.12x
SuffixSequenceLazy 695 623 -10.4% 1.12x (?)
SuffixSequence 694 623 -10.2% 1.11x (?)
Calculator 167 150 -10.2% 1.11x (?)
BinaryFloatingPointPropertiesBinade 21 19 -9.5% 1.11x (?)
DropLastAnyCollection 45 41 -8.9% 1.10x (?)
AngryPhonebook.Cyrillic 181 165 -8.8% 1.10x (?)
AngryPhonebook.Armenian 168 154 -8.3% 1.09x (?)
MapReduceClass2 148 136 -8.1% 1.09x
ObjectiveCBridgeStubToNSDate2 380 350 -7.9% 1.09x (?)
SortAdjacentIntPyramids 1030 950 -7.8% 1.08x (?)
MapReduceNSDecimalNumber 223 206 -7.6% 1.08x (?)
RemoveWhereMoveStrings 296 274 -7.4% 1.08x (?)
SortStrings 515 477 -7.4% 1.08x (?)

Code size: -Osize

Regression OLD NEW DELTA RATIO
NopDeinit.o 3943 4159 +5.5% 0.95x
RangeAssignment.o 3080 3128 +1.6% 0.98x
IntegerParsing.o 53664 54496 +1.6% 0.98x
 
Improvement OLD NEW DELTA RATIO
StrToInt.o 5047 3432 -32.0% 1.47x
XorLoop.o 1864 1447 -22.4% 1.29x
ArraySubscript.o 2728 2197 -19.5% 1.24x
RemoveWhere.o 15437 13706 -11.2% 1.13x
ClassArrayGetter.o 3364 3155 -6.2% 1.07x
BinaryFloatingPointProperties.o 5166 4846 -6.2% 1.07x
DictionaryOfAnyHashableStrings.o 7140 6716 -5.9% 1.06x
ArrayOfGenericRef.o 8504 8032 -5.6% 1.06x
ArrayOfRef.o 8813 8325 -5.5% 1.06x
Walsh.o 4366 4126 -5.5% 1.06x
Array2D.o 2654 2510 -5.4% 1.06x
SortLettersInPlace.o 8173 7747 -5.2% 1.05x
ErrorHandling.o 3125 2973 -4.9% 1.05x
RandomShuffle.o 3655 3479 -4.8% 1.05x
ArrayAppend.o 22973 21909 -4.6% 1.05x
SortIntPyramids.o 9043 8634 -4.5% 1.05x
Prims.o 11915 11405 -4.3% 1.04x
RangeReplaceableCollectionPlusDefault.o 4596 4405 -4.2% 1.04x
PrimsSplit.o 11951 11457 -4.1% 1.04x
RC4.o 3305 3169 -4.1% 1.04x
Sim2DArray.o 1197 1149 -4.0% 1.04x
COWTree.o 11200 10816 -3.4% 1.04x
PrimsNonStrongRef.o 98870 95522 -3.4% 1.04x
DiffingMyers.o 6527 6319 -3.2% 1.03x
Combos.o 5147 4988 -3.1% 1.03x
Phonebook.o 9011 8744 -3.0% 1.03x
PopFront.o 3431 3335 -2.8% 1.03x
PopFrontGeneric.o 2621 2549 -2.7% 1.03x
RGBHistogram.o 19912 19400 -2.6% 1.03x
Breadcrumbs.o 36937 36017 -2.5% 1.03x
Suffix.o 21868 21329 -2.5% 1.03x
DictionaryGroup.o 10635 10379 -2.4% 1.02x
DropLast.o 21731 21219 -2.4% 1.02x
StringBuilder.o 7531 7356 -2.3% 1.02x
Queue.o 12217 11937 -2.3% 1.02x
Join.o 1426 1394 -2.2% 1.02x
StackPromo.o 1961 1921 -2.0% 1.02x
ObserverClosure.o 2542 2491 -2.0% 1.02x
ObserverPartiallyAppliedMethod.o 2605 2554 -2.0% 1.02x
Hash.o 19947 19581 -1.8% 1.02x
ReversedCollections.o 8587 8443 -1.7% 1.02x
StaticArray.o 10944 10765 -1.6% 1.02x
NibbleSort.o 12111 11919 -1.6% 1.02x
COWArrayGuaranteedParameterOverhead.o 1212 1194 -1.5% 1.02x
DictionarySubscriptDefault.o 16301 16061 -1.5% 1.01x
ArraySetElement.o 1117 1101 -1.4% 1.01x
ObjectiveCBridgingStubs.o 14336 14136 -1.4% 1.01x
SortStrings.o 27287 26953 -1.2% 1.01x
StringEdits.o 10392 10265 -1.2% 1.01x
UTF8Decode.o 22811 22547 -1.2% 1.01x
FindStringNaive.o 8930 8835 -1.1% 1.01x
ArrayInClass.o 4523 4475 -1.1% 1.01x
MapReduce.o 22142 21918 -1.0% 1.01x

Performance: -Onone

Regression OLD NEW DELTA RATIO
String.replaceSubrange.RepChar.Small 264 297 +12.5% 0.89x (?)
Data.init.Sequence.809B.Count.RE.I 20917 23130 +10.6% 0.90x (?)
Data.append.Sequence.809B.Count.RE 20940 23094 +10.3% 0.91x (?)
ArrayAppend 2720 2990 +9.9% 0.91x (?)
ArrayAppendRepeatCol 204600 223730 +9.3% 0.91x (?)
Data.init.Sequence.809B.Count.RE 21085 22999 +9.1% 0.92x (?)
Data.append.Sequence.64kB.Count.RE.I 16886 18349 +8.7% 0.92x (?)
Data.hash.Empty 105 114 +8.6% 0.92x (?)
Data.append.Sequence.809B.Count.RE.I 21088 22767 +8.0% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
Memset 8589 7484 -12.9% 1.15x
Sim2DArray 6770 5912 -12.7% 1.15x
Array2D 91408 81152 -11.2% 1.13x (?)
XorLoop 5438 4844 -10.9% 1.12x (?)
ArrayAppendLatin1 8568 7684 -10.3% 1.12x (?)
ArrayAppendUTF16 8568 7684 -10.3% 1.12x (?)
ArrayAppendAscii 8636 7786 -9.8% 1.11x (?)
Hanoi 9390 8500 -9.5% 1.10x (?)
Ackermann 1196 1096 -8.4% 1.09x (?)
AngryPhonebook.Cyrillic 180 165 -8.3% 1.09x (?)
AngryPhonebook.Armenian 168 155 -7.7% 1.08x (?)
CharIteration_chinese_unicodeScalars 132320 122640 -7.3% 1.08x (?)
CharIteration_russian_unicodeScalars 145120 135080 -6.9% 1.07x (?)
CharIteration_korean_unicodeScalars 169920 158680 -6.6% 1.07x (?)

Code size: -swiftlibs

Regression OLD NEW DELTA RATIO
libswiftSwiftPrivateLibcExtras.dylib 16384 20480 +25.0% 0.80x
 
Improvement OLD NEW DELTA RATIO
libswiftOSLogTestHelper.dylib 40960 36864 -10.0% 1.11x
libswiftStdlibUnittest.dylib 327680 323584 -1.2% 1.01x
How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac mini
  Model Identifier: Macmini8,1
  Processor Name: 6-Core Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 2, 2020

Build failed
Swift Test Linux Platform
Git Sha - 17747fc

@eeckstein eeckstein requested a review from atrick June 2, 2020 14:14
@swift-ci
Copy link
Collaborator

swift-ci commented Jun 2, 2020

Build failed
Swift Test OS X Platform
Git Sha - 17747fc

@eeckstein
Copy link
Member Author

@swift-ci test

1 similar comment
@eeckstein
Copy link
Member Author

@swift-ci test

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 2, 2020

Build failed
Swift Test Linux Platform
Git Sha - 7ec919906747f93b033c58baf4368c7f7acf1382

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 2, 2020

Build failed
Swift Test OS X Platform
Git Sha - 7ec919906747f93b033c58baf4368c7f7acf1382

@eeckstein
Copy link
Member Author

@swift-ci clean test

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 3, 2020

Build failed
Swift Test Linux Platform
Git Sha - 7ec919906747f93b033c58baf4368c7f7acf1382

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 3, 2020

Build failed
Swift Test OS X Platform
Git Sha - 7ec919906747f93b033c58baf4368c7f7acf1382

@eeckstein
Copy link
Member Author

@swift-ci clean test

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 3, 2020

Build failed
Swift Test Linux Platform
Git Sha - 7ec919906747f93b033c58baf4368c7f7acf1382

@eeckstein
Copy link
Member Author

@swift-ci clean test

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 3, 2020

Build failed
Swift Test Linux Platform
Git Sha - 7ec919906747f93b033c58baf4368c7f7acf1382

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 3, 2020

Build failed
Swift Test OS X Platform
Git Sha - 7ec919906747f93b033c58baf4368c7f7acf1382

@eeckstein
Copy link
Member Author

@swift-ci clean test macOS

1 similar comment
@eeckstein
Copy link
Member Author

@swift-ci clean test macOS

@eeckstein
Copy link
Member Author

@swift-ci clean test linux

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 3, 2020

Build failed
Swift Test OS X Platform
Git Sha - 9f16b328a6279c780c752625f4cae04cb04ab494

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 3, 2020

Build failed
Swift Test Linux Platform
Git Sha - 9f16b328a6279c780c752625f4cae04cb04ab494

@eeckstein
Copy link
Member Author

@swift-ci test

@eeckstein
Copy link
Member Author

@swift-ci clean test

1 similar comment
@eeckstein
Copy link
Member Author

@swift-ci clean test

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 4, 2020

Build failed
Swift Test Linux Platform
Git Sha - 9a28b635a6465808122b73d903b60b985ed31e59

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 4, 2020

Build failed
Swift Test OS X Platform
Git Sha - 9a28b635a6465808122b73d903b60b985ed31e59

@eeckstein
Copy link
Member Author

@swift-ci clean test

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 5, 2020

Build failed
Swift Test OS X Platform
Git Sha - 9a28b635a6465808122b73d903b60b985ed31e59

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 5, 2020

Build failed
Swift Test Linux Platform
Git Sha - 9a28b635a6465808122b73d903b60b985ed31e59

@eeckstein
Copy link
Member Author

@swift-ci clean test macOS

@eeckstein
Copy link
Member Author

@swift-ci smoke test macOS

1 similar comment
@eeckstein
Copy link
Member Author

@swift-ci smoke test macOS

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 5, 2020

Build failed
Swift Test OS X Platform
Git Sha - 1e0825e8992ddb1f459e2c7b2ca0c41a8e8d7682

@eeckstein
Copy link
Member Author

@swift-ci clean smoke test macOS

@eeckstein
Copy link
Member Author

@swift-ci smoke test macOS

dan-zheng and others added 5 commits June 8, 2020 10:24
Update differentiation to handle `array.finalize_intrinsic` applications.

`VJPEmitter::visitApplyInst` does standard cloning for these applications.

`PullbackEmitter::visitApplyInst` treats the intrinsic like an identity
function, accumulating result's adjoint into argument's adjoint.

This fixes array literal initialization differentiation.
This fixes a correctness issue.
The begin_cow_mutation instruction has dependencies with instructions which retain the buffer operand.
This prevents optimizations from moving begin_cow_mutation instructions across such retain instructions.
For COW support in SIL it's required to "finalize" array literals.
_finalizeUninitializedArray is a compiler known stdlib function which is called after all elements of an array literal are stored.
This runtime function marks the array literal as finished.

  %uninitialized_result_tuple = apply %_allocateUninitializedArray(%count)
  %mutable_array = tuple_extract %uninitialized_result_tuple, 0
  %elem_base_address = tuple_extract %uninitialized_result_tuple, 1
  ...
  store %elem_0 to %elem_addr_0
  store %elem_1 to %elem_addr_1
  ...
  %final_array = apply %_finalizeUninitializedArray(%mutable_array)

In this commit _finalizeUninitializedArray is still a no-op because the COW support is not used in the Array implementation yet.
…COW buffer runtime checking.

In an assert built of the library, store an extra boolean flag (isImmutable) in the object side-buffer table.
This flag can be set and get by the Array implementation to sanity check the immutability status of the buffer object.
…e Array types.

Use the new builtins for COW representation in Array, ContiguousArray and ArraySlice.
The basic idea is to strictly separate code which mutates an array buffer from code which reads from an array.
The concept is explained in more detail in docs/SIL.rst, section "Copy-on-Write Representation".

The main change is to use beginCOWMutation() instead of isUniquelyReferenced() and insert endCOWMutation() at the end of all mutating functions. Also, reading from the array buffer must be done differently, depending on if the buffer is in a mutable or immutable state.

All the required invariants are enforced by runtime checks - but only in an assert-build of the library: a bit in the buffer object side-table indicates if the buffer is mutable or not.

Along with the library changes, also two optimizations needed to be updated: COWArrayOpt and ObjectOutliner.
@eeckstein
Copy link
Member Author

@swift-ci test

1 similar comment
@eeckstein
Copy link
Member Author

@swift-ci test

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 8, 2020

Build failed
Swift Test OS X Platform
Git Sha - 71a642e

Some lldb tests are failing with that.
@eeckstein
Copy link
Member Author

@swift-ci clean smoke test

1 similar comment
@eeckstein
Copy link
Member Author

@swift-ci clean smoke test

@eeckstein eeckstein merged commit 291373f into apple:master Jun 9, 2020
@eeckstein eeckstein deleted the cow-support2 branch June 9, 2020 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants