Skip to content

Commit ded34af

Browse files
committed
[no-implicit-copy] Remove rest of the unnecessary code from SILFunctionType.
Previously I thought that we would have @_noImplicitCopy change the SILFunctionType (but not the AST level type). This caused other problems and was unnecessary. So I removed all such changes in this commit. Specifically: 1. We no longer thread through no implicit copy in SILFunctionType.cpp. 2. noImplicitCopy no longer by default makes an argument an owned argument. Instead we use the default convention and handle it appropriately.
1 parent 09ed0f1 commit ded34af

File tree

2 files changed

+21
-47
lines changed

2 files changed

+21
-47
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//===----------------------------------------------------------------------===//
1818

1919
#define DEBUG_TYPE "libsil"
20+
2021
#include "swift/AST/AnyFunctionRef.h"
2122
#include "swift/AST/CanTypeVisitor.h"
2223
#include "swift/AST/Decl.h"
@@ -1388,16 +1389,13 @@ class DestructureInputs {
13881389
AbstractionPattern TopLevelOrigType = AbstractionPattern::getInvalid();
13891390
SmallVectorImpl<SILParameterInfo> &Inputs;
13901391
unsigned NextOrigParamIndex = 0;
1391-
Optional<SmallBitVector> NoImplicitCopyIndices;
13921392

13931393
public:
13941394
DestructureInputs(TypeExpansionContext expansion, TypeConverter &TC,
13951395
const Conventions &conventions, const ForeignInfo &foreign,
1396-
SmallVectorImpl<SILParameterInfo> &inputs,
1397-
Optional<SmallBitVector> noImplicitCopyIndices)
1396+
SmallVectorImpl<SILParameterInfo> &inputs)
13981397
: expansion(expansion), TC(TC), Convs(conventions), Foreign(foreign),
1399-
Inputs(inputs),
1400-
NoImplicitCopyIndices(noImplicitCopyIndices) {}
1398+
Inputs(inputs) {}
14011399

14021400
void destructure(AbstractionPattern origType,
14031401
CanAnyFunctionType::CanParamArrayRef params,
@@ -1435,18 +1433,14 @@ class DestructureInputs {
14351433
// Add any foreign parameters that are positioned here.
14361434
maybeAddForeignParameters();
14371435

1438-
bool hasNoImplicitCopy =
1439-
NoImplicitCopyIndices.hasValue() && NoImplicitCopyIndices->any();
1440-
14411436
// Process all the non-self parameters.
14421437
for (unsigned i = 0; i != numNonSelfParams; ++i) {
14431438
auto ty = params[i].getParameterType();
14441439
auto eltPattern = origType.getFunctionParamType(i);
14451440
auto flags = params[i].getParameterFlags();
14461441

14471442
visit(flags.getValueOwnership(), /*forSelf=*/false, eltPattern, ty,
1448-
flags.isNoDerivative(),
1449-
hasNoImplicitCopy && (*NoImplicitCopyIndices)[i]);
1443+
flags.isNoDerivative());
14501444
}
14511445

14521446
// Process the self parameter. Note that we implicitly drop self
@@ -1457,8 +1451,7 @@ class DestructureInputs {
14571451
auto eltPattern = origType.getFunctionParamType(numNonSelfParams);
14581452
auto flags = selfParam.getParameterFlags();
14591453

1460-
visit(flags.getValueOwnership(), /*forSelf=*/true, eltPattern, ty, false,
1461-
false);
1454+
visit(flags.getValueOwnership(), /*forSelf=*/true, eltPattern, ty, false);
14621455
}
14631456

14641457
TopLevelOrigType = AbstractionPattern::getInvalid();
@@ -1467,7 +1460,7 @@ class DestructureInputs {
14671460

14681461
void visit(ValueOwnership ownership, bool forSelf,
14691462
AbstractionPattern origType, CanType substType,
1470-
bool isNonDifferentiable, bool isNoImplicitCopy) {
1463+
bool isNonDifferentiable) {
14711464
assert(!isa<InOutType>(substType));
14721465

14731466
// Tuples get handled specially, in some cases:
@@ -1485,7 +1478,7 @@ class DestructureInputs {
14851478
assert(ownership == ValueOwnership::Default);
14861479
assert(!elt.isVararg());
14871480
visit(ownership, forSelf, origType.getTupleElementType(i),
1488-
CanType(elt.getRawType()), false, false);
1481+
CanType(elt.getRawType()), false);
14891482
}
14901483
return;
14911484
case ValueOwnership::InOut:
@@ -1511,8 +1504,6 @@ class DestructureInputs {
15111504
convention = ParameterConvention::Direct_Unowned;
15121505
} else {
15131506
// If we are no implicit copy, our ownership is always Owned.
1514-
if (isNoImplicitCopy)
1515-
ownership = ValueOwnership::Owned;
15161507
convention = Convs.getDirect(ownership, forSelf, origParamIndex, origType,
15171508
substTLConv);
15181509
assert(!isIndirectFormalParameter(convention));
@@ -1579,7 +1570,7 @@ class DestructureInputs {
15791570
// This is a "self", but it's not a Swift self, we handle it differently.
15801571
visit(ForeignSelf->SubstSelfParam.getValueOwnership(),
15811572
/*forSelf=*/false, ForeignSelf->OrigSelfParam,
1582-
ForeignSelf->SubstSelfParam.getParameterType(), false, false);
1573+
ForeignSelf->SubstSelfParam.getParameterType(), false);
15831574
}
15841575
return true;
15851576
}
@@ -1892,8 +1883,7 @@ static CanSILFunctionType getSILFunctionType(
18921883
SILExtInfoBuilder extInfoBuilder, const Conventions &conventions,
18931884
const ForeignInfo &foreignInfo, Optional<SILDeclRef> origConstant,
18941885
Optional<SILDeclRef> constant, Optional<SubstitutionMap> reqtSubs,
1895-
ProtocolConformanceRef witnessMethodConformance,
1896-
Optional<SmallBitVector> noImplicitCopyIndices) {
1886+
ProtocolConformanceRef witnessMethodConformance) {
18971887
// Find the generic parameters.
18981888
CanGenericSignature genericSig =
18991889
substFnInterfaceType.getOptGenericSignature();
@@ -2053,8 +2043,7 @@ static CanSILFunctionType getSILFunctionType(
20532043
SmallVector<SILParameterInfo, 8> inputs;
20542044
{
20552045
DestructureInputs destructurer(expansionContext, TC, conventions,
2056-
foreignInfo, inputs,
2057-
noImplicitCopyIndices);
2046+
foreignInfo, inputs);
20582047
destructurer.destructure(origType, substFnInterfaceType.getParams(),
20592048
extInfoBuilder);
20602049
}
@@ -2337,15 +2326,14 @@ static CanSILFunctionType getNativeSILFunctionType(
23372326
AbstractionPattern origType, CanAnyFunctionType substInterfaceType,
23382327
SILExtInfoBuilder extInfoBuilder, Optional<SILDeclRef> origConstant,
23392328
Optional<SILDeclRef> constant, Optional<SubstitutionMap> reqtSubs,
2340-
ProtocolConformanceRef witnessMethodConformance,
2341-
Optional<SmallBitVector> noImplicitCopyIndices) {
2329+
ProtocolConformanceRef witnessMethodConformance) {
23422330
assert(bool(origConstant) == bool(constant));
23432331
auto getSILFunctionTypeForConventions =
23442332
[&](const Conventions &convs) -> CanSILFunctionType {
23452333
return getSILFunctionType(TC, context, origType, substInterfaceType,
23462334
extInfoBuilder, convs, ForeignInfo(),
23472335
origConstant, constant, reqtSubs,
2348-
witnessMethodConformance, noImplicitCopyIndices);
2336+
witnessMethodConformance);
23492337
};
23502338
switch (extInfoBuilder.getRepresentation()) {
23512339
case SILFunctionType::Representation::Block:
@@ -2409,7 +2397,7 @@ CanSILFunctionType swift::getNativeSILFunctionType(
24092397

24102398
return ::getNativeSILFunctionType(
24112399
TC, context, origType, substType, silExtInfo.intoBuilder(), origConstant,
2412-
substConstant, reqtSubs, witnessMethodConformance, None);
2400+
substConstant, reqtSubs, witnessMethodConformance);
24132401
}
24142402

24152403
/// Build a generic signature and environment for a re-abstraction thunk.
@@ -3076,7 +3064,7 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
30763064
return getSILFunctionType(
30773065
TC, TypeExpansionContext::minimal(), origPattern, substInterfaceType,
30783066
extInfoBuilder, ObjCMethodConventions(method), foreignInfo, constant,
3079-
constant, None, ProtocolConformanceRef(), None);
3067+
constant, None, ProtocolConformanceRef());
30803068
}
30813069

30823070
if (auto method = dyn_cast<clang::CXXMethodDecl>(clangDecl)) {
@@ -3088,7 +3076,7 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
30883076
return getSILFunctionType(TC, TypeExpansionContext::minimal(), origPattern,
30893077
substInterfaceType, extInfoBuilder, conventions,
30903078
foreignInfo, constant, constant, None,
3091-
ProtocolConformanceRef(), None);
3079+
ProtocolConformanceRef());
30923080
}
30933081

30943082
if (auto func = dyn_cast<clang::FunctionDecl>(clangDecl)) {
@@ -3101,7 +3089,7 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
31013089
return getSILFunctionType(TC, TypeExpansionContext::minimal(), origPattern,
31023090
substInterfaceType, extInfoBuilder,
31033091
CFunctionConventions(func), foreignInfo, constant,
3104-
constant, None, ProtocolConformanceRef(), None);
3092+
constant, None, ProtocolConformanceRef());
31053093
}
31063094

31073095
llvm_unreachable("call to unknown kind of C function");
@@ -3129,15 +3117,15 @@ static CanSILFunctionType getSILFunctionTypeForAbstractCFunction(
31293117
return getSILFunctionType(
31303118
TC, TypeExpansionContext::minimal(), origType, substType,
31313119
extInfoBuilder, CFunctionTypeConventions(fnType), ForeignInfo(),
3132-
constant, constant, None, ProtocolConformanceRef(), None);
3120+
constant, constant, None, ProtocolConformanceRef());
31333121
}
31343122
}
31353123

31363124
// TODO: Ought to support captures in block funcs.
31373125
return getSILFunctionType(TC, TypeExpansionContext::minimal(), origType,
31383126
substType, extInfoBuilder,
31393127
DefaultBlockConventions(), ForeignInfo(), constant,
3140-
constant, None, ProtocolConformanceRef(), None);
3128+
constant, None, ProtocolConformanceRef());
31413129
}
31423130

31433131
/// Try to find a clang method declaration for the given function.
@@ -3305,7 +3293,7 @@ static CanSILFunctionType getSILFunctionTypeForObjCSelectorFamily(
33053293
TC, TypeExpansionContext::minimal(), AbstractionPattern(origType),
33063294
substInterfaceType, extInfoBuilder, ObjCSelectorFamilyConventions(family),
33073295
foreignInfo, constant, constant,
3308-
/*requirement subs*/ None, ProtocolConformanceRef(), None);
3296+
/*requirement subs*/ None, ProtocolConformanceRef());
33093297
}
33103298

33113299
static bool isImporterGeneratedAccessor(const clang::Decl *clangDecl,
@@ -3375,23 +3363,9 @@ static CanSILFunctionType getUncachedSILFunctionTypeForConstant(
33753363
}
33763364
}();
33773365

3378-
Optional<SmallBitVector> noImplicitCopyIndices;
3379-
if (constant.hasDecl()) {
3380-
auto decl = constant.getDecl();
3381-
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
3382-
noImplicitCopyIndices.emplace(funcDecl->getParameters()->size());
3383-
for (auto p : llvm::enumerate(*funcDecl->getParameters())) {
3384-
if (p.value()->isNoImplicitCopy()) {
3385-
noImplicitCopyIndices->set(p.index());
3386-
}
3387-
}
3388-
}
3389-
}
3390-
33913366
return ::getNativeSILFunctionType(
33923367
TC, context, origType, origLoweredInterfaceType, extInfoBuilder,
3393-
constant, constant, None, witnessMethodConformance,
3394-
noImplicitCopyIndices);
3368+
constant, constant, None, witnessMethodConformance);
33953369
}
33963370

33973371
ForeignInfo foreignInfo;

lib/SIL/IR/TypeLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,7 @@ TypeConverter::computeLoweredRValueType(TypeExpansionContext forExpansion,
24322432
.build();
24332433

24342434
return ::getNativeSILFunctionType(TC, forExpansion, origType, substFnType,
2435-
silExtInfo);
2435+
silExtInfo, None, None, None, {});
24362436
}
24372437

24382438
// Ignore dynamic self types.

0 commit comments

Comments
 (0)