Skip to content

Commit 04c20b8

Browse files
authored
Merge pull request swiftlang#30340 from apple/revert-29812-captureconv
Revert "Use in_guaranteed for let captures"
2 parents 8e39711 + ccbc26d commit 04c20b8

23 files changed

+115
-293
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ enum class CaptureKind {
561561
StorageAddress,
562562
/// A local value captured as a constant.
563563
Constant,
564-
/// A let constant captured as a pointer to storage
565-
Immutable
566564
};
567565

568566

include/swift/SILOptimizer/Utils/InstOptUtils.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,12 @@ void releasePartialApplyCapturedArg(
364364
SILParameterInfo paramInfo,
365365
InstModCallbacks callbacks = InstModCallbacks());
366366

367-
void deallocPartialApplyCapturedArg(
368-
SILBuilder &builder, SILLocation loc, SILValue arg,
369-
SILParameterInfo paramInfo);
370-
371367
/// Insert destroys of captured arguments of partial_apply [stack].
372368
void insertDestroyOfCapturedArguments(
373369
PartialApplyInst *pai, SILBuilder &builder,
374370
llvm::function_ref<bool(SILValue)> shouldInsertDestroy =
375371
[](SILValue arg) -> bool { return true; });
376372

377-
void insertDeallocOfCapturedArguments(
378-
PartialApplyInst *pai, SILBuilder &builder);
379-
380373
/// This iterator 'looks through' one level of builtin expect users exposing all
381374
/// users of the looked through builtin expect instruction i.e it presents a
382375
/// view that shows all users as if there were no builtin expect instructions

lib/IRGen/GenFunc.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,25 +1319,9 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
13191319
SmallVector<SILType, 4> argValTypes;
13201320
SmallVector<ParameterConvention, 4> argConventions;
13211321

1322-
// Go over the params and check if any of them can cause the HeapLayout to be non-fixed
1323-
// This is needed because we should not consider parameters of kind ClassPointer and Metadata sources
1324-
// If not, we may end up with missing TypeMetadata for a type dependent generic parameter
1325-
// while generating code for destructor of HeapLayout.
1326-
bool considerParameterSources = true;
1327-
for (auto param : params) {
1328-
SILType argType = IGF.IGM.silConv.getSILType(param, origType);
1329-
auto argLoweringTy = getArgumentLoweringType(argType.getASTType(), param);
1330-
auto &ti = IGF.getTypeInfoForLowered(argLoweringTy);
1331-
1332-
if (!isa<FixedTypeInfo>(ti)) {
1333-
considerParameterSources = false;
1334-
break;
1335-
}
1336-
}
1337-
13381322
// Reserve space for polymorphic bindings.
13391323
auto bindings =
1340-
NecessaryBindings::forPartialApplyForwarder(IGF.IGM, origType, subs, considerParameterSources);
1324+
NecessaryBindings::forPartialApplyForwarder(IGF.IGM, origType, subs);
13411325

13421326
if (!bindings.empty()) {
13431327
hasSingleSwiftRefcountedContext = No;
@@ -1540,7 +1524,7 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
15401524
HeapNonFixedOffsets offsets(IGF, layout);
15411525
if (outType->isNoEscape()) {
15421526
stackAddr = IGF.emitDynamicAlloca(
1543-
IGF.IGM.Int8Ty, layout.isFixedLayout() ? layout.emitSize(IGF.IGM) : offsets.getSize() , Alignment(16));
1527+
IGF.IGM.Int8Ty, layout.emitSize(IGF.IGM), Alignment(16));
15441528
stackAddr = stackAddr->withAddress(IGF.Builder.CreateBitCast(
15451529
stackAddr->getAddress(), IGF.IGM.OpaquePtrTy));
15461530
data = stackAddr->getAddress().getAddress();

lib/IRGen/GenProto.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class PolymorphicConvention {
112112
}
113113

114114
public:
115-
PolymorphicConvention(IRGenModule &IGM, CanSILFunctionType fnType, bool considerParameterSources);
115+
PolymorphicConvention(IRGenModule &IGM, CanSILFunctionType fnType);
116116

117117
ArrayRef<MetadataSource> getSources() const { return Sources; }
118118

@@ -179,9 +179,8 @@ class PolymorphicConvention {
179179
} // end anonymous namespace
180180

181181
PolymorphicConvention::PolymorphicConvention(IRGenModule &IGM,
182-
CanSILFunctionType fnType,
183-
bool considerParameterSources = true)
184-
: IGM(IGM), M(*IGM.getSwiftModule()), FnType(fnType){
182+
CanSILFunctionType fnType)
183+
: IGM(IGM), M(*IGM.getSwiftModule()), FnType(fnType) {
185184
initGenerics();
186185

187186
auto rep = fnType->getRepresentation();
@@ -213,18 +212,16 @@ PolymorphicConvention::PolymorphicConvention(IRGenModule &IGM,
213212
unsigned selfIndex = ~0U;
214213
auto params = fnType->getParameters();
215214

216-
if (considerParameterSources) {
217-
// Consider 'self' first.
218-
if (fnType->hasSelfParam()) {
219-
selfIndex = params.size() - 1;
220-
considerParameter(params[selfIndex], selfIndex, true);
221-
}
215+
// Consider 'self' first.
216+
if (fnType->hasSelfParam()) {
217+
selfIndex = params.size() - 1;
218+
considerParameter(params[selfIndex], selfIndex, true);
219+
}
222220

223-
// Now consider the rest of the parameters.
224-
for (auto index : indices(params)) {
225-
if (index != selfIndex)
226-
considerParameter(params[index], index, false);
227-
}
221+
// Now consider the rest of the parameters.
222+
for (auto index : indices(params)) {
223+
if (index != selfIndex)
224+
considerParameter(params[index], index, false);
228225
}
229226
}
230227
}
@@ -3003,16 +3000,14 @@ NecessaryBindings::forFunctionInvocations(IRGenModule &IGM,
30033000
NecessaryBindings
30043001
NecessaryBindings::forPartialApplyForwarder(IRGenModule &IGM,
30053002
CanSILFunctionType origType,
3006-
SubstitutionMap subs,
3007-
bool considerParameterSources) {
3003+
SubstitutionMap subs) {
30083004
return computeBindings(IGM, origType, subs,
3009-
true /*forPartialApplyForwarder*/,
3010-
considerParameterSources);
3005+
true /*forPartialApplyForwarder*/);
30113006
}
30123007

30133008
NecessaryBindings NecessaryBindings::computeBindings(
30143009
IRGenModule &IGM, CanSILFunctionType origType, SubstitutionMap subs,
3015-
bool forPartialApplyForwarder, bool considerParameterSources) {
3010+
bool forPartialApplyForwarder) {
30163011

30173012
NecessaryBindings bindings;
30183013
bindings.forPartialApply = forPartialApplyForwarder;
@@ -3022,7 +3017,7 @@ NecessaryBindings NecessaryBindings::computeBindings(
30223017
return bindings;
30233018

30243019
// Figure out what we're actually required to pass:
3025-
PolymorphicConvention convention(IGM, origType, considerParameterSources);
3020+
PolymorphicConvention convention(IGM, origType);
30263021

30273022
// - unfulfilled requirements
30283023
convention.enumerateUnfulfilledRequirements(

lib/IRGen/NecessaryBindings.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class NecessaryBindings {
5959
SubstitutionMap subs);
6060
static NecessaryBindings forPartialApplyForwarder(IRGenModule &IGM,
6161
CanSILFunctionType origType,
62-
SubstitutionMap subs,
63-
bool considerParameterSources = true);
62+
SubstitutionMap subs);
6463

6564
/// Add whatever information is necessary to reconstruct type metadata
6665
/// for the given type.
@@ -99,8 +98,7 @@ class NecessaryBindings {
9998
static NecessaryBindings computeBindings(IRGenModule &IGM,
10099
CanSILFunctionType origType,
101100
SubstitutionMap subs,
102-
bool forPartialApplyForwarder,
103-
bool considerParameterSources = true);
101+
bool forPartialApplyForwarder);
104102
};
105103

106104
} // end namespace irgen

lib/SIL/SILFunctionType.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,8 +1460,9 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
14601460
case CaptureKind::Constant: {
14611461
// Constants are captured by value.
14621462
ParameterConvention convention;
1463-
assert (!loweredTL.isAddressOnly());
1464-
if (loweredTL.isTrivial()) {
1463+
if (loweredTL.isAddressOnly()) {
1464+
convention = ParameterConvention::Indirect_In_Guaranteed;
1465+
} else if (loweredTL.isTrivial()) {
14651466
convention = ParameterConvention::Direct_Unowned;
14661467
} else {
14671468
convention = ParameterConvention::Direct_Guaranteed;
@@ -1494,16 +1495,6 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
14941495
inputs.push_back(param);
14951496
break;
14961497
}
1497-
case CaptureKind::Immutable: {
1498-
// 'let' constants that are address-only are captured as the address of the value
1499-
// and will be consumed by the closure.
1500-
SILType ty = loweredTy.getAddressType();
1501-
auto param =
1502-
SILParameterInfo(ty.getASTType(),
1503-
ParameterConvention::Indirect_In_Guaranteed);
1504-
inputs.push_back(param);
1505-
break;
1506-
}
15071498
}
15081499
}
15091500
}

lib/SIL/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11171117
if (VarInfo)
11181118
if (unsigned ArgNo = VarInfo->ArgNo) {
11191119
// It is a function argument.
1120-
if (ArgNo < DebugVars.size() && !DebugVars[ArgNo].empty() && !VarInfo->Name.empty()) {
1120+
if (ArgNo < DebugVars.size() && !DebugVars[ArgNo].empty()) {
11211121
require(
11221122
DebugVars[ArgNo] == VarInfo->Name,
11231123
"Scope contains conflicting debug variables for one function "

lib/SIL/TypeLowering.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ CaptureKind TypeConverter::getDeclCaptureKind(CapturedValue capture,
126126
return CaptureKind::Box;
127127
}
128128

129-
// For 'let' constants
130-
if (!var->supportsMutation()) {
131-
return CaptureKind::Immutable;
132-
}
133-
134129
// If we're capturing into a non-escaping closure, we can generally just
135130
// capture the address of the value as no-escape.
136131
return (capture.isNoEscape()

lib/SILGen/SILGenFunction.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ void SILGenFunction::emitCaptures(SILLocation loc,
262262
case CaptureKind::Constant:
263263
capturedArgs.push_back(emitUndef(getLoweredType(type)));
264264
break;
265-
case CaptureKind::Immutable:
266265
case CaptureKind::StorageAddress:
267266
capturedArgs.push_back(emitUndef(getLoweredType(type).getAddressType()));
268267
break;
@@ -334,23 +333,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
334333
capturedArgs.push_back(emitManagedRValueWithCleanup(Val));
335334
break;
336335
}
337-
case CaptureKind::Immutable: {
338-
if (canGuarantee) {
339-
auto entryValue = getAddressValue(Entry.value);
340-
// No-escaping stored declarations are captured as the
341-
// address of the value.
342-
assert(entryValue->getType().isAddress() && "no address for captured var!");
343-
capturedArgs.push_back(ManagedValue::forLValue(entryValue));
344-
}
345-
else {
346-
auto entryValue = getAddressValue(Entry.value);
347-
auto addr = emitTemporaryAllocation(vd, entryValue->getType());
348-
auto val = B.createCopyAddr(loc, entryValue, addr, IsNotTake,
349-
IsInitialization);
350-
capturedArgs.push_back(ManagedValue::forLValue(addr));
351-
}
352-
break;
353-
}
336+
354337
case CaptureKind::StorageAddress: {
355338
auto entryValue = getAddressValue(Entry.value);
356339
// No-escaping stored declarations are captured as the

lib/SILGen/SILGenProlog.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ static void emitCaptureArguments(SILGenFunction &SGF,
420420
SGF.B.createDebugValueAddr(Loc, addr, DbgVar);
421421
break;
422422
}
423-
case CaptureKind::Immutable:
424423
case CaptureKind::StorageAddress: {
425424
// Non-escaping stored decls are captured as the address of the value.
426425
auto type = getVarTypeInCaptureContext();

0 commit comments

Comments
 (0)