Skip to content

Commit 15a5b84

Browse files
authored
Merge pull request #11514 from gottesmm/eliminate_unnecessary_static_function
2 parents eda0c0c + 52edcd1 commit 15a5b84

File tree

3 files changed

+55
-51
lines changed

3 files changed

+55
-51
lines changed

lib/SILGen/RValue.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ class RValue {
7474
CanType type;
7575
unsigned elementsToBeAdded;
7676

77-
/// Flag value used to mark an rvalue as invalid, because it was
78-
/// consumed or it was default-initialized.
77+
/// \brief Flag value used to mark an rvalue as invalid.
78+
///
79+
/// The reasons why this can be true is:
80+
///
81+
/// 1. The RValue was consumed.
82+
/// 2. The RValue was default-initialized.
83+
/// 3. The RValue was emitted into an SGFContext initialization.
7984
enum : unsigned {
8085
Null = ~0U,
8186
Used = Null - 1,

lib/SILGen/SILGenBuilder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
///
13+
/// \file
14+
///
15+
/// This file defines SILGenBuilder, a subclass of SILBuilder that provides APIs
16+
/// that traffic in ManagedValue. The intention is that if one is using a
17+
/// SILGenBuilder, the SILGenBuilder will handle preserving ownership invariants
18+
/// (or assert upon failure) freeing the implementor of such concerns.
19+
///
20+
//===----------------------------------------------------------------------===//
1221

1322
#ifndef SWIFT_SILGEN_SILGENBUILDER_H
1423
#define SWIFT_SILGEN_SILGENBUILDER_H

lib/SILGen/SILGenExpr.cpp

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,52 +4670,6 @@ ManagedValue SILGenFunction::emitLValueToPointer(SILLocation loc, LValue &&lv,
46704670
.getAsSingleValue(*this, loc);
46714671
}
46724672

4673-
static std::pair<ManagedValue, ManagedValue>
4674-
emitArrayToPointer(SILGenFunction &SGF, SILLocation loc, ManagedValue array,
4675-
SILGenFunction::ArrayAccessInfo accessInfo) {
4676-
auto &ctx = SGF.getASTContext();
4677-
4678-
FuncDecl *converter;
4679-
if (accessInfo.AccessKind == AccessKind::Read) {
4680-
converter = ctx.getConvertConstArrayToPointerArgument(nullptr);
4681-
if (array.isLValue())
4682-
array = SGF.B.createLoadCopy(loc, array);
4683-
4684-
} else {
4685-
converter = ctx.getConvertMutableArrayToPointerArgument(nullptr);
4686-
assert(array.isLValue());
4687-
}
4688-
4689-
// Invoke the conversion intrinsic, which will produce an owner-pointer pair.
4690-
auto *M = SGF.SGM.M.getSwiftModule();
4691-
auto firstSubMap =
4692-
accessInfo.ArrayType->getContextSubstitutionMap(M, ctx.getArrayDecl());
4693-
auto secondSubMap =
4694-
accessInfo.PointerType->getContextSubstitutionMap(M,
4695-
SGF.getPointerProtocol());
4696-
4697-
auto *genericSig = converter->getGenericSignature();
4698-
auto subMap =
4699-
SubstitutionMap::combineSubstitutionMaps(firstSubMap,
4700-
secondSubMap,
4701-
CombineSubstitutionMaps::AtIndex,
4702-
1, 0,
4703-
genericSig);
4704-
4705-
SmallVector<ManagedValue, 2> resultScalars;
4706-
SGF.emitApplyOfLibraryIntrinsic(loc, converter, subMap, array, SGFContext())
4707-
.getAll(resultScalars);
4708-
assert(resultScalars.size() == 2);
4709-
4710-
// Mark the dependence of the pointer on the owner value.
4711-
auto owner = resultScalars[0];
4712-
auto pointer = resultScalars[1].forward(SGF);
4713-
pointer = SGF.B.createMarkDependence(loc, pointer, owner.getValue());
4714-
4715-
// The owner's already in its own cleanup. Return the pointer.
4716-
return {ManagedValue::forTrivialObjectRValue(pointer), owner};
4717-
}
4718-
47194673
RValue RValueEmitter::visitArrayToPointerExpr(ArrayToPointerExpr *E,
47204674
SGFContext C) {
47214675
FormalEvaluationScope writeback(SGF);
@@ -4734,7 +4688,7 @@ RValue RValueEmitter::visitArrayToPointerExpr(ArrayToPointerExpr *E,
47344688
array = SGF.emitRValueAsSingleValue(subExpr);
47354689
}
47364690

4737-
auto pointer = ::emitArrayToPointer(SGF, E, array, accessInfo).first;
4691+
auto pointer = SGF.emitArrayToPointer(E, array, accessInfo).first;
47384692
return RValue(SGF, E, pointer);
47394693
}
47404694

@@ -4749,13 +4703,49 @@ SILGenFunction::emitArrayToPointer(SILLocation loc, LValue &&lv,
47494703
ArrayAccessInfo accessInfo) {
47504704
auto array =
47514705
emitAddressOfLValue(loc, std::move(lv), accessInfo.AccessKind);
4752-
return ::emitArrayToPointer(*this, loc, array, accessInfo);
4706+
return emitArrayToPointer(loc, array, accessInfo);
47534707
}
47544708

47554709
std::pair<ManagedValue, ManagedValue>
47564710
SILGenFunction::emitArrayToPointer(SILLocation loc, ManagedValue array,
47574711
ArrayAccessInfo accessInfo) {
4758-
return ::emitArrayToPointer(*this, loc, array, accessInfo);
4712+
auto &ctx = getASTContext();
4713+
4714+
FuncDecl *converter;
4715+
if (accessInfo.AccessKind == AccessKind::Read) {
4716+
converter = ctx.getConvertConstArrayToPointerArgument(nullptr);
4717+
if (array.isLValue())
4718+
array = B.createLoadCopy(loc, array);
4719+
4720+
} else {
4721+
converter = ctx.getConvertMutableArrayToPointerArgument(nullptr);
4722+
assert(array.isLValue());
4723+
}
4724+
4725+
// Invoke the conversion intrinsic, which will produce an owner-pointer pair.
4726+
auto *M = SGM.M.getSwiftModule();
4727+
auto firstSubMap =
4728+
accessInfo.ArrayType->getContextSubstitutionMap(M, ctx.getArrayDecl());
4729+
auto secondSubMap = accessInfo.PointerType->getContextSubstitutionMap(
4730+
M, getPointerProtocol());
4731+
4732+
auto *genericSig = converter->getGenericSignature();
4733+
auto subMap = SubstitutionMap::combineSubstitutionMaps(
4734+
firstSubMap, secondSubMap, CombineSubstitutionMaps::AtIndex, 1, 0,
4735+
genericSig);
4736+
4737+
SmallVector<ManagedValue, 2> resultScalars;
4738+
emitApplyOfLibraryIntrinsic(loc, converter, subMap, array, SGFContext())
4739+
.getAll(resultScalars);
4740+
assert(resultScalars.size() == 2);
4741+
4742+
// Mark the dependence of the pointer on the owner value.
4743+
auto owner = resultScalars[0];
4744+
auto pointer = resultScalars[1].forward(*this);
4745+
pointer = B.createMarkDependence(loc, pointer, owner.getValue());
4746+
4747+
// The owner's already in its own cleanup. Return the pointer.
4748+
return {ManagedValue::forTrivialObjectRValue(pointer), owner};
47594749
}
47604750

47614751
RValue RValueEmitter::visitStringToPointerExpr(StringToPointerExpr *E,

0 commit comments

Comments
 (0)