Skip to content

Commit ced25fb

Browse files
committed
SILGen: Remove more references to the 'uncurry level' concept
1 parent e2e73d2 commit ced25fb

File tree

9 files changed

+76
-122
lines changed

9 files changed

+76
-122
lines changed

include/swift/SIL/SILDeclRef.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ bool requiresForeignEntryPoint(ValueDecl *vd);
6666
/// True if the entry point is natively foreign.
6767
bool requiresForeignToNativeThunk(ValueDecl *vd);
6868

69-
unsigned getNaturalUncurryLevel(ValueDecl *vd);
70-
7169
enum ForDefinition_t : bool {
7270
NotForDefinition = false,
7371
ForDefinition = true
@@ -304,7 +302,7 @@ struct SILDeclRef {
304302
void print(llvm::raw_ostream &os) const;
305303
void dump() const;
306304

307-
unsigned getUncurryLevel() const;
305+
unsigned getParameterListCount() const;
308306

309307
ResilienceExpansion getResilienceExpansion() const {
310308
return ResilienceExpansion(Expansion);

lib/ParseSIL/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ bool SILParser::parseSILDeclRef(SILDeclRef &Result,
12361236
if (!P.consumeIf(tok::sil_exclamation)) {
12371237
// Construct SILDeclRef.
12381238
Result = SILDeclRef(VD, Kind, expansion, /*isCurried=*/false, IsObjC);
1239-
if (uncurryLevel < Result.getUncurryLevel())
1239+
if (uncurryLevel < Result.getParameterListCount() - 1)
12401240
Result = Result.asCurried();
12411241
return false;
12421242
}
@@ -1327,7 +1327,7 @@ bool SILParser::parseSILDeclRef(SILDeclRef &Result,
13271327

13281328
// Construct SILDeclRef.
13291329
Result = SILDeclRef(VD, Kind, expansion, /*isCurried=*/false, IsObjC);
1330-
if (uncurryLevel < Result.getUncurryLevel())
1330+
if (uncurryLevel < Result.getParameterListCount() - 1)
13311331
Result = Result.asCurried();
13321332
return false;
13331333
}

lib/SIL/SILDeclRef.cpp

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -227,29 +227,6 @@ static bool hasLoweredLocalCaptures(AnyFunctionRef AFR,
227227
return false;
228228
}
229229

230-
static unsigned getFuncNaturalUncurryLevel(AnyFunctionRef AFR) {
231-
assert(AFR.getParameterLists().size() >= 1 && "no arguments for func?!");
232-
return AFR.getParameterLists().size() - 1;
233-
}
234-
235-
unsigned swift::getNaturalUncurryLevel(ValueDecl *vd) {
236-
if (auto *func = dyn_cast<FuncDecl>(vd)) {
237-
return getFuncNaturalUncurryLevel(func);
238-
} else if (isa<ConstructorDecl>(vd)) {
239-
return 1;
240-
} else if (auto *ed = dyn_cast<EnumElementDecl>(vd)) {
241-
return ed->hasAssociatedValues() ? 1 : 0;
242-
} else if (isa<DestructorDecl>(vd)) {
243-
return 0;
244-
} else if (isa<ClassDecl>(vd)) {
245-
return 1;
246-
} else if (isa<VarDecl>(vd)) {
247-
return 0;
248-
} else {
249-
llvm_unreachable("Unhandled ValueDecl for SILDeclRef");
250-
}
251-
}
252-
253230
SILDeclRef::SILDeclRef(ValueDecl *vd, SILDeclRef::Kind kind,
254231
ResilienceExpansion expansion,
255232
bool isCurried, bool isForeign)
@@ -888,12 +865,23 @@ SubclassScope SILDeclRef::getSubclassScope() const {
888865
llvm_unreachable("Unhandled access level in switch.");
889866
}
890867

891-
unsigned SILDeclRef::getUncurryLevel() const {
892-
if (isCurried)
893-
return 0;
894-
if (!hasDecl())
895-
return getFuncNaturalUncurryLevel(*getAnyFunctionRef());
896-
if (kind == Kind::DefaultArgGenerator)
897-
return 0;
898-
return getNaturalUncurryLevel(getDecl());
868+
unsigned SILDeclRef::getParameterListCount() const {
869+
if (isCurried || !hasDecl() || kind == Kind::DefaultArgGenerator)
870+
return 1;
871+
872+
auto *vd = getDecl();
873+
874+
if (auto *func = dyn_cast<AbstractFunctionDecl>(vd)) {
875+
return func->getParameterLists().size();
876+
} else if (auto *ed = dyn_cast<EnumElementDecl>(vd)) {
877+
return ed->hasAssociatedValues() ? 2 : 1;
878+
} else if (isa<DestructorDecl>(vd)) {
879+
return 1;
880+
} else if (isa<ClassDecl>(vd)) {
881+
return 2;
882+
} else if (isa<VarDecl>(vd)) {
883+
return 1;
884+
} else {
885+
llvm_unreachable("Unhandled ValueDecl for SILDeclRef");
886+
}
899887
}

lib/SIL/SILFunctionType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ static bool isImporterGeneratedAccessor(const clang::Decl *clangDecl,
17771777
return false;
17781778

17791779
// Must be a type member.
1780-
if (constant.getUncurryLevel() != 1)
1780+
if (constant.getParameterListCount() != 2)
17811781
return false;
17821782

17831783
// Must be imported from a function.
@@ -2486,7 +2486,7 @@ getAbstractionPatternForConstant(ASTContext &ctx, SILDeclRef constant,
24862486
TypeConverter::LoweredFormalTypes
24872487
TypeConverter::getLoweredFormalTypes(SILDeclRef constant,
24882488
CanAnyFunctionType fnType) {
2489-
unsigned uncurryLevel = constant.getUncurryLevel();
2489+
unsigned uncurryLevel = constant.getParameterListCount() - 1;
24902490
auto extInfo = fnType->getExtInfo();
24912491

24922492
// Form an abstraction pattern for bridging purposes.

lib/SIL/SILPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void SILDeclRef::print(raw_ostream &OS) const {
351351
break;
352352
}
353353

354-
auto uncurryLevel = getUncurryLevel();
354+
auto uncurryLevel = getParameterListCount() - 1;
355355
if (uncurryLevel != 0)
356356
OS << (isDot ? '.' : '!') << uncurryLevel;
357357

0 commit comments

Comments
 (0)