Skip to content

Commit 9a1abf7

Browse files
committed
SILGen: Remove SILGenSILBuilder
This reverts commit 59cc3c1216fbb1719e5357dcef3f8b249528fc74.
1 parent 3e99d11 commit 9a1abf7

13 files changed

+108
-330
lines changed

lib/SILGen/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ add_swift_host_library(swiftSILGen STATIC
2929
SILGenPoly.cpp
3030
SILGenProlog.cpp
3131
SILGenStmt.cpp
32-
SILGenSILBuilder.cpp
3332
SILGenThunk.cpp
3433
SILGenType.cpp)
3534
target_link_libraries(swiftSILGen PRIVATE

lib/SILGen/SILGenApply.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,21 +1781,19 @@ static void emitRawApply(SILGenFunction &SGF,
17811781
}
17821782

17831783
auto resultType = substFnConv.getSILResultType();
1784-
auto calleeType = SILType::getPrimitiveObjectType(substFnType);
17851784

17861785
// If the function is a coroutine, we need to use 'begin_apply'.
17871786
if (substFnType->isCoroutine()) {
17881787
assert(!substFnType->hasErrorResult());
1789-
auto apply = SGF.B.createBeginApply(loc, fnValue, subs, argValues);
1788+
auto apply = SGF.B.createBeginApply(loc, fnValue, subs, argValues, false);
17901789
for (auto result : apply->getAllResults())
17911790
rawResults.push_back(result);
17921791
return;
17931792
}
17941793

17951794
// If we don't have an error result, we can make a simple 'apply'.
17961795
if (!substFnType->hasErrorResult()) {
1797-
auto result = SGF.B.createApply(loc, fnValue, calleeType,
1798-
resultType, subs, argValues);
1796+
auto result = SGF.B.createApply(loc, fnValue, subs, argValues, false);
17991797
rawResults.push_back(result);
18001798

18011799
// Otherwise, we need to create a try_apply.
@@ -1809,7 +1807,7 @@ static void emitRawApply(SILGenFunction &SGF,
18091807
SGF.getTryApplyErrorDest(loc, substFnType->getErrorResult(),
18101808
options & ApplyOptions::DoesNotThrow);
18111809

1812-
SGF.B.createTryApply(loc, fnValue, calleeType, subs, argValues,
1810+
SGF.B.createTryApply(loc, fnValue, subs, argValues,
18131811
normalBB, errorBB);
18141812
SGF.B.emitBlock(normalBB);
18151813
}
@@ -4007,19 +4005,10 @@ CallEmission::applyPartiallyAppliedSuperMethod(SGFContext C) {
40074005
S.pop();
40084006
}
40094007
auto calleeConvention = ParameterConvention::Direct_Guaranteed;
4010-
auto closureTy = SILGenBuilder::getPartialApplyResultType(
4011-
constantInfo.getSILType(), 1, SGF.B.getModule(), subs, calleeConvention);
40124008

4013-
auto &module = SGF.getFunction().getModule();
4014-
4015-
auto partialApplyTy = functionTy;
4016-
if (constantInfo.SILFnType->isPolymorphic() && !subs.empty())
4017-
partialApplyTy = partialApplyTy.substGenericArgs(module, subs);
4018-
4019-
ManagedValue pa = SGF.B.createPartialApply(loc, superMethod, partialApplyTy,
4009+
ManagedValue pa = SGF.B.createPartialApply(loc, superMethod,
40204010
subs, {upcastedSelf},
4021-
closureTy);
4022-
assert(!closureTy.castTo<SILFunctionType>()->isNoEscape());
4011+
calleeConvention);
40234012
firstLevelResult.value = RValue(SGF, loc, formalApplyType.getResult(), pa);
40244013
return firstLevelResult;
40254014
}
@@ -4544,12 +4533,12 @@ SILValue SILGenFunction::emitApplyWithRethrow(SILLocation loc, SILValue fn,
45444533
SILType resultType = fnConv.getSILResultType();
45454534

45464535
if (!silFnType->hasErrorResult()) {
4547-
return B.createApply(loc, fn, substFnType, resultType, subs, args);
4536+
return B.createApply(loc, fn, subs, args, false);
45484537
}
45494538

45504539
SILBasicBlock *errorBB = createBasicBlock();
45514540
SILBasicBlock *normalBB = createBasicBlock();
4552-
B.createTryApply(loc, fn, substFnType, subs, args, normalBB, errorBB);
4541+
B.createTryApply(loc, fn, subs, args, normalBB, errorBB);
45534542

45544543
// Emit the rethrow logic.
45554544
{
@@ -4578,7 +4567,7 @@ SILGenFunction::emitBeginApplyWithRethrow(SILLocation loc, SILValue fn,
45784567
// TODO: adjust this to create try_begin_apply when appropriate.
45794568
assert(!substFnType.castTo<SILFunctionType>()->hasErrorResult());
45804569

4581-
auto beginApply = B.createBeginApply(loc, fn, subs, args);
4570+
auto beginApply = B.createBeginApply(loc, fn, subs, args, false);
45824571

45834572
auto yieldResults = beginApply->getYieldedValues();
45844573
yields.append(yieldResults.begin(), yieldResults.end());
@@ -5728,26 +5717,20 @@ static ManagedValue emitDynamicPartialApply(SILGenFunction &SGF,
57285717
CanAnyFunctionType nativeFormalType) {
57295718
auto calleeConvention = ParameterConvention::Direct_Guaranteed;
57305719

5731-
auto partialApplyTy =
5732-
SILBuilder::getPartialApplyResultType(method->getType(),
5733-
/*argCount*/ 1, SGF.SGM.M,
5734-
/*subs*/ {}, calleeConvention);
5735-
57365720
// Retain 'self' because the partial apply will take ownership.
57375721
// We can't simply forward 'self' because the partial apply is conditional.
57385722
if (!self->getType().isAddress())
57395723
self = SGF.B.emitCopyValueOperation(loc, self);
57405724

57415725
SILValue resultValue =
5742-
SGF.B.createPartialApply(loc, method, method->getType(), {},
5743-
self, partialApplyTy);
5726+
SGF.B.createPartialApply(loc, method, {}, self, calleeConvention);
57445727
ManagedValue result = SGF.emitManagedRValueWithCleanup(resultValue);
57455728

57465729
// If necessary, thunk to the native ownership conventions and bridged types.
57475730
auto nativeTy =
57485731
SGF.getLoweredLoadableType(nativeFormalType).castTo<SILFunctionType>();
57495732

5750-
if (nativeTy != partialApplyTy.getASTType()) {
5733+
if (nativeTy != resultValue->getType().getASTType()) {
57515734
result = SGF.emitBlockToFunc(loc, result, foreignFormalType,
57525735
nativeFormalType, nativeTy);
57535736
}

lib/SILGen/SILGenBridging.cpp

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ emitBridgeNativeToObjectiveC(SILGenFunction &SGF,
154154
}
155155

156156
// Call the witness.
157-
SILType resultTy = SGF.getLoweredType(objcType);
158157
SILValue bridgedValue =
159-
SGF.B.createApply(loc, witnessRef, witnessFnTy, resultTy, typeSubMap,
160-
swiftValue.borrow(SGF, loc).getValue());
158+
SGF.B.createApply(loc, witnessRef, typeSubMap,
159+
swiftValue.borrow(SGF, loc).getValue(), false);
161160

162161
auto bridgedMV = SGF.emitManagedRValueWithCleanup(bridgedValue);
163162
bridgedMV = scope.popPreservingValue(bridgedMV);
@@ -252,11 +251,8 @@ static ManagedValue emitBridgeBoolToObjCBool(SILGenFunction &SGF,
252251
SILValue boolToObjCBoolFn
253252
= SGF.emitGlobalFunctionRef(loc, SGF.SGM.getBoolToObjCBoolFn());
254253

255-
SILType resultTy =SGF.getLoweredLoadableType(SGF.SGM.Types.getObjCBoolType());
256-
257254
SILValue result = SGF.B.createApply(loc, boolToObjCBoolFn,
258-
boolToObjCBoolFn->getType(),
259-
resultTy, {}, swiftBool.forward(SGF));
255+
{}, swiftBool.forward(SGF), false);
260256
return SGF.emitManagedRValueWithCleanup(result);
261257
}
262258

@@ -267,12 +263,8 @@ static ManagedValue emitBridgeBoolToDarwinBoolean(SILGenFunction &SGF,
267263
SILValue boolToDarwinBooleanFn
268264
= SGF.emitGlobalFunctionRef(loc, SGF.SGM.getBoolToDarwinBooleanFn());
269265

270-
SILType resultTy =
271-
SGF.getLoweredLoadableType(SGF.SGM.Types.getDarwinBooleanType());
272-
273266
SILValue result = SGF.B.createApply(loc, boolToDarwinBooleanFn,
274-
boolToDarwinBooleanFn->getType(),
275-
resultTy, {}, swiftBool.forward(SGF));
267+
{}, swiftBool.forward(SGF), false);
276268
return SGF.emitManagedRValueWithCleanup(result);
277269
}
278270

@@ -283,10 +275,8 @@ static ManagedValue emitBridgeForeignBoolToBool(SILGenFunction &SGF,
283275
// func _convertObjCBoolToBool(ObjCBool) -> Bool
284276
SILValue bridgingFn = SGF.emitGlobalFunctionRef(loc, bridgingFnRef);
285277

286-
SILType resultTy = SGF.getLoweredLoadableType(SGF.SGM.Types.getBoolType());
287-
288-
SILValue result = SGF.B.createApply(loc, bridgingFn, bridgingFn->getType(),
289-
resultTy, {}, foreignBool.forward(SGF));
278+
SILValue result = SGF.B.createApply(loc, bridgingFn, {},
279+
foreignBool.forward(SGF), false);
290280
return SGF.emitManagedRValueWithCleanup(result);
291281
}
292282

@@ -960,9 +950,8 @@ SILGenFunction::emitBlockToFunc(SILLocation loc,
960950
// Create it in the current function.
961951
auto thunkValue = B.createFunctionRefFor(loc, thunk);
962952
ManagedValue thunkedFn = B.createPartialApply(
963-
loc, thunkValue, SILType::getPrimitiveObjectType(substFnTy),
964-
interfaceSubs, block,
965-
SILType::getPrimitiveObjectType(loweredFuncTyWithoutNoEscape));
953+
loc, thunkValue, interfaceSubs, block,
954+
loweredFuncTy->getCalleeConvention());
966955

967956
if (!loweredFuncTy->isNoEscape()) {
968957
return thunkedFn;
@@ -1143,18 +1132,17 @@ ManagedValue SILGenFunction::emitBridgedToNativeError(SILLocation loc,
11431132
// a standard error for a nil NSError.
11441133
auto bridgeFn = emitGlobalFunctionRef(loc, SGM.getNSErrorToErrorFn());
11451134
auto bridgeFnType = bridgeFn->getType().castTo<SILFunctionType>();
1146-
SILFunctionConventions bridgeFnConv(bridgeFnType, SGM.M);
11471135
assert(bridgeFnType->getNumResults() == 1);
11481136
assert(bridgeFnType->getResults()[0].getConvention()
11491137
== ResultConvention::Owned);
1150-
auto nativeErrorType = bridgeFnConv.getSILType(bridgeFnType->getResults()[0]);
11511138

1152-
assert(bridgeFnType->getParameters()[0].getConvention() ==
1153-
ParameterConvention::Direct_Guaranteed);
1139+
assert(bridgeFnType->getParameters()[0].getConvention()
1140+
== ParameterConvention::Direct_Guaranteed);
1141+
(void) bridgeFnType;
1142+
11541143
SILValue arg = bridgedError.getValue();
11551144

1156-
SILValue nativeError = B.createApply(loc, bridgeFn, bridgeFn->getType(),
1157-
nativeErrorType, {}, arg);
1145+
SILValue nativeError = B.createApply(loc, bridgeFn, {}, arg, false);
11581146
return emitManagedRValueWithCleanup(nativeError);
11591147
}
11601148

@@ -1191,19 +1179,16 @@ ManagedValue SILGenFunction::emitNativeToBridgedError(SILLocation loc,
11911179

11921180
auto bridgeFn = emitGlobalFunctionRef(loc, SGM.getErrorToNSErrorFn());
11931181
auto bridgeFnType = bridgeFn->getType().castTo<SILFunctionType>();
1194-
SILFunctionConventions bridgeFnConv(bridgeFnType, SGM.M);
11951182
assert(bridgeFnType->getNumResults() == 1);
11961183
assert(bridgeFnType->getResults()[0].getConvention()
11971184
== ResultConvention::Owned);
1198-
auto loweredBridgedErrorType =
1199-
bridgeFnConv.getSILType(bridgeFnType->getResults()[0]);
1185+
assert(bridgeFnType->getParameters()[0].getConvention()
1186+
== ParameterConvention::Direct_Guaranteed);
1187+
(void) bridgeFnType;
12001188

1201-
assert(bridgeFnType->getParameters()[0].getConvention() ==
1202-
ParameterConvention::Direct_Guaranteed);
12031189
SILValue arg = nativeError.getValue();
12041190

1205-
SILValue bridgedError = B.createApply(loc, bridgeFn, bridgeFn->getType(),
1206-
loweredBridgedErrorType, {}, arg);
1191+
SILValue bridgedError = B.createApply(loc, bridgeFn, {}, arg, false);
12071192
return emitManagedRValueWithCleanup(bridgedError);
12081193
}
12091194

@@ -1405,7 +1390,6 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
14051390
auto nativeInfo = getConstantInfo(native);
14061391
auto subs = F.getForwardingSubstitutionMap();
14071392
auto substTy = nativeInfo.SILFnType->substGenericArgs(SGM.M, subs);
1408-
SILType substSILTy = SILType::getPrimitiveObjectType(substTy);
14091393
SILFunctionConventions substConv(substTy, SGM.M);
14101394

14111395
// Use the same generic environment as the native entry point.
@@ -1506,8 +1490,7 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
15061490
assert(foreignError.hasValue() == substTy->hasErrorResult());
15071491
if (!substTy->hasErrorResult()) {
15081492
// Create the apply.
1509-
result = B.createApply(loc, nativeFn, substSILTy,
1510-
swiftResultTy, subs, args);
1493+
result = B.createApply(loc, nativeFn, subs, args, false);
15111494

15121495
if (substConv.hasIndirectSILResults()) {
15131496
assert(substTy->getNumResults() == 1);
@@ -1525,8 +1508,7 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
15251508
SILBasicBlock *contBB = createBasicBlock();
15261509
SILBasicBlock *errorBB = createBasicBlock();
15271510
SILBasicBlock *normalBB = createBasicBlock();
1528-
B.createTryApply(loc, nativeFn, substSILTy, subs, args,
1529-
normalBB, errorBB);
1511+
B.createTryApply(loc, nativeFn, subs, args, normalBB, errorBB);
15301512

15311513
// Emit the non-error destination.
15321514
{

lib/SILGen/SILGenBuilder.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,30 @@ SILGenModule &SILGenBuilder::getSILGenModule() const { return SGF.SGM; }
3333
//===----------------------------------------------------------------------===//
3434

3535
SILGenBuilder::SILGenBuilder(SILGenFunction &SGF)
36-
: SILGenSILBuilder(SGF), SGF(SGF) {}
36+
: SILBuilder(SGF.F), SGF(SGF) {}
3737

3838
SILGenBuilder::SILGenBuilder(SILGenFunction &SGF, SILBasicBlock *insertBB,
3939
SmallVectorImpl<SILInstruction *> *insertedInsts)
40-
: SILGenSILBuilder(SGF, insertBB, insertedInsts), SGF(SGF) {}
40+
: SILBuilder(insertBB, insertedInsts), SGF(SGF) {}
4141

4242
SILGenBuilder::SILGenBuilder(SILGenFunction &SGF, SILBasicBlock *insertBB,
4343
SILBasicBlock::iterator insertInst)
44-
: SILGenSILBuilder(SGF, insertBB, insertInst), SGF(SGF) {}
44+
: SILBuilder(insertBB, insertInst), SGF(SGF) {}
4545

4646
//===----------------------------------------------------------------------===//
4747
// Managed Value APIs
4848
//===----------------------------------------------------------------------===//
49-
//
50-
// *NOTE* Please use SILGenBuilder SILValue APIs below. Otherwise, we
51-
// potentially do not get all of the conformances that we need.
52-
//
5349

5450
ManagedValue SILGenBuilder::createPartialApply(SILLocation loc, SILValue fn,
55-
SILType substFnTy,
5651
SubstitutionMap subs,
5752
ArrayRef<ManagedValue> args,
58-
SILType closureTy) {
53+
ParameterConvention calleeConvention) {
5954
llvm::SmallVector<SILValue, 8> values;
6055
transform(args, std::back_inserter(values), [&](ManagedValue mv) -> SILValue {
6156
return mv.forward(getSILGenFunction());
6257
});
6358
SILValue result =
64-
createPartialApply(loc, fn, substFnTy, subs, values, closureTy);
59+
createPartialApply(loc, fn, subs, values, calleeConvention);
6560
// Partial apply instructions create a box, so we need to put on a cleanup.
6661
return getSILGenFunction().emitManagedRValueWithCleanup(result);
6762
}

0 commit comments

Comments
 (0)