Skip to content

Commit 6ba4547

Browse files
committed
Remove the pinning addressors
It was used for Array + related types. With exclusivity checking the pinned addressors are not useful anymore. rdar://problem/35401528
1 parent 809764f commit 6ba4547

21 files changed

+16
-382
lines changed

Diff for: docs/ABI/Mangling.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Entities
232232
ADDRESSOR-KIND ::= 'u' // unsafe addressor (no owner)
233233
ADDRESSOR-KIND ::= 'O' // owning addressor (non-native owner)
234234
ADDRESSOR-KIND ::= 'o' // owning addressor (native owner)
235-
ADDRESSOR-KIND ::= 'p' // pinning addressor (native owner)
235+
ADDRESSOR-KIND ::= 'p' // pinning addressor (native owner), not used anymore
236236

237237
decl-name ::= identifier
238238
decl-name ::= identifier 'L' INDEX // locally-discriminated declaration

Diff for: include/swift/AST/AccessorKinds.def

-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ ACCESSOR(Address)
187187
IMMUTABLE_ADDRESSOR(Unsafe, unsafeAddress)
188188
IMMUTABLE_ADDRESSOR(Owning, addressWithOwner)
189189
IMMUTABLE_ADDRESSOR(NativeOwning, addressWithNativeOwner)
190-
IMMUTABLE_ADDRESSOR(NativePinning, addressWithPinnedNativeOwner)
191190

192191
/// This is a mutableAddress-family accessor: a function that is
193192
/// called when the storage is assigned to (like a setter) or
@@ -203,7 +202,6 @@ ACCESSOR(MutableAddress)
203202
MUTABLE_ADDRESSOR(Unsafe, unsafeMutableAddress)
204203
MUTABLE_ADDRESSOR(Owning, mutableAddressWithOwner)
205204
MUTABLE_ADDRESSOR(NativeOwning, mutableAddressWithNativeOwner)
206-
MUTABLE_ADDRESSOR(NativePinning, mutableAddressWithPinnedNativeOwner)
207205

208206
#ifdef LAST_ACCESSOR
209207
LAST_ACCESSOR(MutableAddress)

Diff for: include/swift/AST/StorageImpl.h

-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ enum class AddressorKind : uint8_t {
5454
/// \brief This is an owning addressor; it returns a Builtin.NativeObject
5555
/// which should be released when the caller is done with the object.
5656
NativeOwning,
57-
/// \brief This is a pinning addressor; it returns a Builtin.NativeObject?
58-
/// which should be unpinned when the caller is done with the object.
59-
NativePinning,
6057
};
6158

6259
/// Whether an access to storage is for reading, writing, or both.

Diff for: lib/AST/ASTMangler.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ static StringRef getCodeForAccessorKind(AccessorKind kind,
7171
return "lO";
7272
case AddressorKind::NativeOwning:
7373
return "lo";
74-
case AddressorKind::NativePinning:
75-
return "lp";
7674
}
7775
llvm_unreachable("bad addressor kind");
7876
case AccessorKind::MutableAddress:
@@ -85,8 +83,6 @@ static StringRef getCodeForAccessorKind(AccessorKind kind,
8583
return "aO";
8684
case AddressorKind::NativeOwning:
8785
return "ao";
88-
case AddressorKind::NativePinning:
89-
return "aP";
9086
}
9187
llvm_unreachable("bad addressor kind");
9288
case AccessorKind::MaterializeForSet:

Diff for: lib/SILGen/SILGenApply.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -5605,7 +5605,6 @@ emitAddressorAccessor(SILLocation loc, SILDeclRef addressor,
56055605
break;
56065606
case AddressorKind::Owning:
56075607
case AddressorKind::NativeOwning:
5608-
case AddressorKind::NativePinning:
56095608
assert(results.size() == 2);
56105609
pointer = results[0].getUnmanagedValue();
56115610
owner = results[1];
@@ -5636,7 +5635,6 @@ emitAddressorAccessor(SILLocation loc, SILDeclRef addressor,
56365635
break;
56375636
case AddressorKind::Owning:
56385637
case AddressorKind::NativeOwning:
5639-
case AddressorKind::NativePinning:
56405638
address = B.createMarkDependence(loc, address, owner.getValue());
56415639
break;
56425640
}

Diff for: lib/SILGen/SILGenExpr.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,6 @@ emitRValueWithAccessor(SILGenFunction &SGF, SILLocation loc,
10371037
// Emit the release immediately.
10381038
SGF.B.emitDestroyValueOperation(loc, addressorResult.second.forward(SGF));
10391039
break;
1040-
case AddressorKind::NativePinning:
1041-
// Emit the unpin immediately.
1042-
SGF.B.createStrongUnpin(loc, addressorResult.second.forward(SGF),
1043-
SGF.B.getDefaultAtomicity());
1044-
break;
10451040
}
10461041

10471042
return result;

Diff for: lib/SILGen/SILGenLValue.cpp

-36
Original file line numberDiff line numberDiff line change
@@ -1582,33 +1582,6 @@ namespace {
15821582
}
15831583
};
15841584

1585-
class UnpinPseudoComponent : public WritebackPseudoComponent {
1586-
public:
1587-
UnpinPseudoComponent(const LValueTypeData &typeData)
1588-
: WritebackPseudoComponent(typeData) {}
1589-
1590-
private:
1591-
void writeback(SILGenFunction &SGF, SILLocation loc,
1592-
ManagedValue base,
1593-
MaterializedLValue materialized,
1594-
bool isFinal) override {
1595-
loc.markAutoGenerated();
1596-
1597-
// If this is final, we can consume the owner (stored as
1598-
// 'base'). If it isn't, we actually need to retain it, because
1599-
// we've still got a release active.
1600-
SILValue baseValue = (isFinal ? base.forward(SGF) : base.getValue());
1601-
if (!isFinal)
1602-
baseValue = SGF.B.createCopyValue(loc, baseValue);
1603-
1604-
SGF.B.createStrongUnpin(loc, baseValue, SGF.B.getDefaultAtomicity());
1605-
}
1606-
1607-
void dump(raw_ostream &OS, unsigned indent) const override {
1608-
OS.indent(indent) << "UnpinPseudoComponent";
1609-
}
1610-
};
1611-
16121585
class MaterializeToTemporaryComponent final
16131586
: public AccessComponent<LogicalPathComponent> {
16141587
SubstitutionMap Substitutions;
@@ -1760,15 +1733,6 @@ namespace {
17601733
case AddressorKind::Owning:
17611734
case AddressorKind::NativeOwning:
17621735
break;
1763-
1764-
// For pinning addressors, we have to push a writeback.
1765-
case AddressorKind::NativePinning: {
1766-
std::unique_ptr<LogicalPathComponent>
1767-
component(new UnpinPseudoComponent(getTypeData()));
1768-
pushWriteback(SGF, loc, std::move(component), result.second,
1769-
MaterializedLValue());
1770-
break;
1771-
}
17721736
}
17731737

17741738
// Enter an unsafe access scope for the access.

Diff for: lib/SILGen/SILGenMaterializeForSet.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,6 @@ MaterializeForSetEmitter::createAddressorCallback(SILFunction &F,
881881
case AddressorKind::NativeOwning:
882882
SGF.B.createDestroyValue(loc, owner);
883883
break;
884-
885-
case AddressorKind::NativePinning:
886-
SGF.B.createStrongUnpin(loc, owner, SGF.B.getDefaultAtomicity());
887-
break;
888884
}
889885

890886
SGF.B.createDeallocValueBuffer(loc, ownerType, callbackStorage);

Diff for: lib/Sema/TypeCheckDecl.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -3707,20 +3707,6 @@ Type buildAddressorResultType(TypeChecker &TC,
37073707
};
37083708
return TupleType::get(elts, TC.Context);
37093709
}
3710-
3711-
// For native pinning addressors, the return type is actually
3712-
// (Unsafe{,Mutable}Pointer<T>, Builtin.NativeObject?)
3713-
case AddressorKind::NativePinning: {
3714-
Type pinTokenType =
3715-
TC.getOptionalType(addressor->getLoc(), TC.Context.TheNativeObjectType);
3716-
if (!pinTokenType) return Type();
3717-
3718-
TupleTypeElt elts[] = {
3719-
pointerType,
3720-
pinTokenType
3721-
};
3722-
return TupleType::get(elts, TC.Context);
3723-
}
37243710
}
37253711
llvm_unreachable("bad addressor kind");
37263712
}

Diff for: lib/Serialization/Deserialization.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -2021,8 +2021,6 @@ getActualAddressorKind(uint8_t raw) {
20212021
return swift::AddressorKind::Owning;
20222022
case serialization::AddressorKind::NativeOwning:
20232023
return swift::AddressorKind::NativeOwning;
2024-
case serialization::AddressorKind::NativePinning:
2025-
return swift::AddressorKind::NativePinning;
20262024
}
20272025

20282026
return None;

Diff for: lib/Serialization/Serialization.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,6 @@ static uint8_t getRawStableAddressorKind(swift::AddressorKind kind) {
12001200
return uint8_t(serialization::AddressorKind::Owning);
12011201
case swift::AddressorKind::NativeOwning:
12021202
return uint8_t(serialization::AddressorKind::NativeOwning);
1203-
case swift::AddressorKind::NativePinning:
1204-
return uint8_t(serialization::AddressorKind::NativePinning);
12051203
}
12061204
llvm_unreachable("bad addressor kind");
12071205
}

Diff for: stdlib/public/core/Array.swift

+3-12
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,10 @@ extension Array: RandomAccessCollection, MutableCollection {
570570
index, wasNativeTypeChecked: wasNativeTypeChecked,
571571
matchingSubscriptCheck: token)
572572
}
573-
mutableAddressWithPinnedNativeOwner {
574-
_makeMutableAndUniqueOrPinned() // makes the array native, too
573+
mutableAddressWithNativeOwner {
574+
_makeMutableAndUnique() // makes the array native, too
575575
_checkSubscript_native(index)
576-
return (_getElementAddress(index), Builtin.tryPin(_getOwner_native()))
576+
return (_getElementAddress(index), _getOwner_native())
577577
}
578578
}
579579

@@ -679,15 +679,6 @@ extension Array {
679679
}
680680
}
681681

682-
@inlinable
683-
@_semantics("array.make_mutable")
684-
internal mutating func _makeMutableAndUniqueOrPinned() {
685-
if _slowPath(!_buffer.isMutableAndUniquelyReferencedOrPinned()) {
686-
_buffer = _Buffer(copying: _buffer)
687-
}
688-
}
689-
690-
691682
/// Check that the given `index` is valid for subscripting, i.e.
692683
/// `0 ≤ index < count`.
693684
@inlinable

Diff for: stdlib/public/core/ArrayBuffer.swift

-24
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,6 @@ extension _ArrayBuffer {
123123
return _isNative
124124
}
125125

126-
/// Returns `true` iff this buffer's storage is either
127-
/// uniquely-referenced or pinned.
128-
@inlinable
129-
internal mutating func isUniquelyReferencedOrPinned() -> Bool {
130-
if !_isClassOrObjCExistential(Element.self) {
131-
return _storage.isUniquelyReferencedOrPinned_native_noSpareBits()
132-
}
133-
134-
// This is a performance optimization. This code used to be:
135-
//
136-
// return _storage.isUniquelyReferencedOrPinnedNative() && _isNative.
137-
//
138-
// SR-6437
139-
if !_storage.isUniquelyReferencedOrPinnedNative() {
140-
return false
141-
}
142-
return _isNative
143-
}
144-
145126
/// Convert to an NSArray.
146127
///
147128
/// O(1) if the element type is bridged verbatim, O(*n*) otherwise.
@@ -171,11 +152,6 @@ extension _ArrayBuffer {
171152
return isUniquelyReferenced()
172153
}
173154

174-
@inlinable
175-
internal mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
176-
return isUniquelyReferencedOrPinned()
177-
}
178-
179155
/// If this buffer is backed by a `_ContiguousArrayBuffer`
180156
/// containing the same number of elements as `self`, return it.
181157
/// Otherwise, return `nil`.

Diff for: stdlib/public/core/ArraySlice.swift

+3-12
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ extension ArraySlice: RandomAccessCollection, MutableCollection {
393393
index, wasNativeTypeChecked: wasNativeTypeChecked,
394394
matchingSubscriptCheck: token)
395395
}
396-
mutableAddressWithPinnedNativeOwner {
397-
_makeMutableAndUniqueOrPinned() // makes the array native, too
396+
mutableAddressWithNativeOwner {
397+
_makeMutableAndUnique() // makes the array native, too
398398
_checkSubscript_native(index)
399-
return (_getElementAddress(index), Builtin.tryPin(_getOwner_native()))
399+
return (_getElementAddress(index), _getOwner_native())
400400
}
401401
}
402402

@@ -502,15 +502,6 @@ extension ArraySlice {
502502
}
503503
}
504504

505-
@inlinable
506-
@_semantics("array.make_mutable")
507-
internal mutating func _makeMutableAndUniqueOrPinned() {
508-
if _slowPath(!_buffer.isMutableAndUniquelyReferencedOrPinned()) {
509-
_buffer = _Buffer(copying: _buffer)
510-
}
511-
}
512-
513-
514505
/// Check that the given `index` is valid for subscripting, i.e.
515506
/// `0 ≤ index < count`.
516507
@inlinable

Diff for: stdlib/public/core/ContiguousArray.swift

+3-12
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ extension ContiguousArray: RandomAccessCollection, MutableCollection {
301301
index, wasNativeTypeChecked: wasNativeTypeChecked,
302302
matchingSubscriptCheck: token)
303303
}
304-
mutableAddressWithPinnedNativeOwner {
305-
_makeMutableAndUniqueOrPinned() // makes the array native, too
304+
mutableAddressWithNativeOwner {
305+
_makeMutableAndUnique() // makes the array native, too
306306
_checkSubscript_native(index)
307-
return (_getElementAddress(index), Builtin.tryPin(_getOwner_native()))
307+
return (_getElementAddress(index), _getOwner_native())
308308
}
309309
}
310310

@@ -410,15 +410,6 @@ extension ContiguousArray {
410410
}
411411
}
412412

413-
@inlinable
414-
@_semantics("array.make_mutable")
415-
internal mutating func _makeMutableAndUniqueOrPinned() {
416-
if _slowPath(!_buffer.isMutableAndUniquelyReferencedOrPinned()) {
417-
_buffer = _Buffer(copying: _buffer)
418-
}
419-
}
420-
421-
422413
/// Check that the given `index` is valid for subscripting, i.e.
423414
/// `0 ≤ index < count`.
424415
@inlinable

Diff for: stdlib/public/core/ContiguousArrayBuffer.swift

-13
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,6 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
314314
return isUniquelyReferenced()
315315
}
316316

317-
@inlinable
318-
internal mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
319-
return isUniquelyReferencedOrPinned()
320-
}
321-
322317
/// If this buffer is backed by a `_ContiguousArrayBuffer`
323318
/// containing the same number of elements as `self`, return it.
324319
/// Otherwise, return `nil`.
@@ -435,14 +430,6 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
435430
return _isUnique(&_storage)
436431
}
437432

438-
/// Returns `true` iff this buffer's storage is either
439-
/// uniquely-referenced or pinned. NOTE: this does not mean
440-
/// the buffer is mutable; see the comment on isUniquelyReferenced.
441-
@inlinable
442-
internal mutating func isUniquelyReferencedOrPinned() -> Bool {
443-
return _isUniqueOrPinned(&_storage)
444-
}
445-
446433
#if _runtime(_ObjC)
447434
/// Convert to an NSArray.
448435
///

Diff for: stdlib/public/core/SliceBuffer.swift

+1-21
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ internal struct _SliceBuffer<Element>
196196
internal mutating func isMutableAndUniquelyReferenced() -> Bool {
197197
// This is a performance optimization that ensures that the copy of self
198198
// that occurs at -Onone is destroyed before we call
199-
// isUniquelyReferencedOrPinned. This code used to be:
199+
// isUniquelyReferenced. This code used to be:
200200
//
201201
// return _hasNativeBuffer && isUniquelyReferenced()
202202
//
@@ -207,21 +207,6 @@ internal struct _SliceBuffer<Element>
207207
return isUniquelyReferenced()
208208
}
209209

210-
@inlinable
211-
internal mutating func isMutableAndUniquelyReferencedOrPinned() -> Bool {
212-
// This is a performance optimization that ensures that the copy of self
213-
// that occurs at -Onone is destroyed before we call
214-
// isUniquelyReferencedOrPinned. This code used to be:
215-
//
216-
// return _hasNativeBuffer && isUniquelyReferencedOrPinned()
217-
//
218-
// SR-6437
219-
if !_hasNativeBuffer {
220-
return false
221-
}
222-
return isUniquelyReferencedOrPinned()
223-
}
224-
225210
/// If this buffer is backed by a `_ContiguousArrayBuffer`
226211
/// containing the same number of elements as `self`, return it.
227212
/// Otherwise, return `nil`.
@@ -297,11 +282,6 @@ internal struct _SliceBuffer<Element>
297282
return isKnownUniquelyReferenced(&owner)
298283
}
299284

300-
@inlinable // FIXME(sil-serialize-all)
301-
internal mutating func isUniquelyReferencedOrPinned() -> Bool {
302-
return _isKnownUniquelyReferencedOrPinned(&owner)
303-
}
304-
305285
@inlinable // FIXME(sil-serialize-all)
306286
internal func getElement(_ i: Int) -> Element {
307287
_sanityCheck(i >= startIndex, "slice index is out of range (before startIndex)")

0 commit comments

Comments
 (0)