Skip to content

Commit 9fd02eb

Browse files
authored
Merge pull request #9383 from slavapestov/simplify-curry-thunks
SIL: Kill off uncurryLevel even more
2 parents 6f0dded + 775462b commit 9fd02eb

27 files changed

+218
-491
lines changed

include/swift/Reflection/TypeRef.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,6 @@ class ProtocolTypeRef final : public TypeRef {
396396
FIND_OR_CREATE_TYPEREF(A, ProtocolTypeRef, MangledName);
397397
}
398398

399-
bool isAnyObject() const {
400-
return MangledName == "s9AnyObject_p";
401-
}
402-
403399
bool isError() const {
404400
return MangledName == "s5Error_p";
405401
}

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,6 @@ class TypeRefBuilder {
311311
const std::string &Member,
312312
const TypeRef *Protocol);
313313

314-
const TypeRef *
315-
lookupSuperclass(const std::string &MangledTypeName);
316-
317314
const TypeRef *
318315
lookupSuperclass(const TypeRef *TR);
319316

include/swift/SIL/SILDeclRef.h

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ 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+
6971
enum ForDefinition_t : bool {
7072
NotForDefinition = false,
7173
ForDefinition = true
@@ -144,8 +146,6 @@ struct SILDeclRef {
144146
Loc loc;
145147
/// The Kind of this SILDeclRef.
146148
Kind kind : 4;
147-
/// The uncurry level of this SILDeclRef.
148-
unsigned uncurryLevel : 8;
149149
/// The required resilience expansion of the declaration.
150150
unsigned Expansion : 1;
151151
/// True if the SILDeclRef is a curry thunk.
@@ -158,28 +158,19 @@ struct SILDeclRef {
158158
/// The default argument index for a default argument getter.
159159
unsigned defaultArgIndex : 10;
160160

161-
/// A magic value for SILDeclRef constructors to ask for the natural uncurry
162-
/// level of the constant.
163-
enum : unsigned { ConstructAtNaturalUncurryLevel = ~0U };
164-
165-
/// A magic value for SILDeclRef constructors to ask for the best
166-
/// available resilience expansion of the constant.
167-
static constexpr ResilienceExpansion ConstructAtBestResilienceExpansion
168-
= /*TODO*/ ResilienceExpansion::Minimal;
169-
170161
/// Produces a null SILDeclRef.
171-
SILDeclRef() : loc(), kind(Kind::Func), uncurryLevel(0), Expansion(0),
162+
SILDeclRef() : loc(), kind(Kind::Func), Expansion(0),
172163
isCurried(0), isForeign(0), isDirectReference(0),
173164
defaultArgIndex(0) {}
174165

175166
/// Produces a SILDeclRef of the given kind for the given decl.
176167
explicit SILDeclRef(ValueDecl *decl, Kind kind,
177168
ResilienceExpansion expansion
178169
= ResilienceExpansion::Minimal,
179-
unsigned uncurryLevel = ConstructAtNaturalUncurryLevel,
170+
bool isCurried = false,
180171
bool isForeign = false);
181172

182-
/// Produces the 'natural' SILDeclRef for the given ValueDecl or
173+
/// Produces a SILDeclRef for the given ValueDecl or
183174
/// AbstractClosureExpr:
184175
/// - If 'loc' is a func or closure, this returns a Func SILDeclRef.
185176
/// - If 'loc' is a ConstructorDecl, this returns the Allocator SILDeclRef
@@ -190,13 +181,15 @@ struct SILDeclRef {
190181
/// for the containing ClassDecl.
191182
/// - If 'loc' is a global VarDecl, this returns its GlobalAccessor
192183
/// SILDeclRef.
193-
/// If the uncurry level is unspecified or specified as NaturalUncurryLevel,
194-
/// then the SILDeclRef for the natural uncurry level of the definition is
195-
/// used.
184+
///
185+
/// If 'isCurried' is true, the loc must be a method or enum element;
186+
/// the SILDeclRef will then refer to a curry thunk with type
187+
/// (Self) -> (Args...) -> Result, rather than a direct reference to
188+
/// the actual method whose lowered type is (Args..., Self) -> Result.
196189
explicit SILDeclRef(Loc loc,
197190
ResilienceExpansion expansion
198191
= ResilienceExpansion::Minimal,
199-
unsigned uncurryLevel = ConstructAtNaturalUncurryLevel,
192+
bool isCurried = false,
200193
bool isForeign = false);
201194

202195
/// Produce a SIL constant for a default argument generator.
@@ -284,7 +277,7 @@ struct SILDeclRef {
284277
llvm::hash_code getHashCode() const {
285278
return llvm::hash_combine(loc.getOpaqueValue(),
286279
static_cast<int>(kind),
287-
Expansion, uncurryLevel,
280+
Expansion, isCurried,
288281
isForeign, isDirectReference,
289282
defaultArgIndex);
290283
}
@@ -293,7 +286,7 @@ struct SILDeclRef {
293286
return loc.getOpaqueValue() == rhs.loc.getOpaqueValue()
294287
&& kind == rhs.kind
295288
&& Expansion == rhs.Expansion
296-
&& uncurryLevel == rhs.uncurryLevel
289+
&& isCurried == rhs.isCurried
297290
&& isForeign == rhs.isForeign
298291
&& isDirectReference == rhs.isDirectReference
299292
&& defaultArgIndex == rhs.defaultArgIndex;
@@ -305,26 +298,28 @@ struct SILDeclRef {
305298
void print(llvm::raw_ostream &os) const;
306299
void dump() const;
307300

301+
unsigned getUncurryLevel() const;
302+
308303
ResilienceExpansion getResilienceExpansion() const {
309304
return ResilienceExpansion(Expansion);
310305
}
311306

312307
// Returns the SILDeclRef for an entity at a shallower uncurry level.
313-
SILDeclRef atUncurryLevel(unsigned level) const {
314-
assert(level <= uncurryLevel && "can't safely go to deeper uncurry level");
315-
bool willBeCurried = isCurried || level < uncurryLevel;
308+
SILDeclRef asCurried(bool curried = true) const {
309+
assert(!isCurried && "can't safely go to deeper uncurry level");
316310
// Curry thunks are never foreign.
317-
bool willBeForeign = isForeign && !willBeCurried;
311+
bool willBeForeign = isForeign && !curried;
318312
bool willBeDirect = isDirectReference;
319-
return SILDeclRef(loc.getOpaqueValue(), kind, Expansion, level,
320-
willBeCurried, willBeDirect, willBeForeign,
313+
return SILDeclRef(loc.getOpaqueValue(), kind, Expansion,
314+
curried, willBeDirect, willBeForeign,
321315
defaultArgIndex);
322316
}
323317

324318
/// Returns the foreign (or native) entry point corresponding to the same
325319
/// decl.
326320
SILDeclRef asForeign(bool foreign = true) const {
327-
return SILDeclRef(loc.getOpaqueValue(), kind, Expansion, uncurryLevel,
321+
assert(!isCurried);
322+
return SILDeclRef(loc.getOpaqueValue(), kind, Expansion,
328323
isCurried, isDirectReference, foreign, defaultArgIndex);
329324
}
330325

@@ -379,13 +374,13 @@ struct SILDeclRef {
379374
explicit SILDeclRef(void *opaqueLoc,
380375
Kind kind,
381376
unsigned rawExpansion,
382-
unsigned uncurryLevel,
383377
bool isCurried,
384378
bool isDirectReference,
385379
bool isForeign,
386380
unsigned defaultArgIndex)
387381
: loc(Loc::getFromOpaqueValue(opaqueLoc)),
388-
kind(kind), uncurryLevel(uncurryLevel), Expansion(rawExpansion),
382+
kind(kind),
383+
Expansion(rawExpansion),
389384
isCurried(isCurried),
390385
isForeign(isForeign), isDirectReference(isDirectReference),
391386
defaultArgIndex(defaultArgIndex)
@@ -413,18 +408,18 @@ template<> struct DenseMapInfo<swift::SILDeclRef> {
413408

414409
static SILDeclRef getEmptyKey() {
415410
return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func,
416-
0, 0, false, false, false, 0);
411+
0, false, false, false, 0);
417412
}
418413
static SILDeclRef getTombstoneKey() {
419414
return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func,
420-
0, 0, false, false, false, 0);
415+
0, false, false, false, 0);
421416
}
422417
static unsigned getHashValue(swift::SILDeclRef Val) {
423418
unsigned h1 = PointerInfo::getHashValue(Val.loc.getOpaqueValue());
424419
unsigned h2 = UnsignedInfo::getHashValue(unsigned(Val.kind));
425420
unsigned h3 = (Val.kind == Kind::DefaultArgGenerator)
426421
? UnsignedInfo::getHashValue(Val.defaultArgIndex)
427-
: UnsignedInfo::getHashValue(Val.uncurryLevel);
422+
: UnsignedInfo::getHashValue(Val.isCurried);
428423
unsigned h4 = UnsignedInfo::getHashValue(Val.isForeign);
429424
unsigned h5 = UnsignedInfo::getHashValue(Val.isDirectReference);
430425
return h1 ^ (h2 << 4) ^ (h3 << 9) ^ (h4 << 7) ^ (h5 << 11);

lib/IRGen/GenClass.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,7 @@ static bool getInstanceSizeByMethod(IRGenFunction &IGF,
798798
}
799799

800800
// Check whether the SIL module defines it. (We need a type for it.)
801-
SILDeclRef fnRef(fn, SILDeclRef::Kind::Func,
802-
ResilienceExpansion::Minimal,
803-
/*uncurryLevel*/ 1,
804-
/*foreign*/ false);
801+
SILDeclRef fnRef(fn, SILDeclRef::Kind::Func);
805802
SILFunction *silFn = IGF.getSILModule().lookUpFunction(fnRef);
806803
if (!silFn)
807804
return false;
@@ -1475,10 +1472,8 @@ namespace {
14751472

14761473
// We don't have a destructor body, so hunt for the SIL function
14771474
// for it.
1478-
SILDeclRef dtorRef(destructor, SILDeclRef::Kind::Deallocator,
1479-
ResilienceExpansion::Minimal,
1480-
SILDeclRef::ConstructAtNaturalUncurryLevel,
1481-
/*isForeign=*/true);
1475+
auto dtorRef = SILDeclRef(destructor, SILDeclRef::Kind::Deallocator)
1476+
.asForeign();
14821477
if (auto silFn = IGM.getSILModule().lookUpFunction(dtorRef))
14831478
return silFn->isDefinition();
14841479

lib/IRGen/GenDecl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,12 +2811,11 @@ Optional<llvm::Function*> IRGenModule::getAddrOfIVarInitDestroy(
28112811
bool isDestroyer,
28122812
bool isForeign,
28132813
ForDefinition_t forDefinition) {
2814-
SILDeclRef silRef(cd,
2815-
isDestroyer? SILDeclRef::Kind::IVarDestroyer
2816-
: SILDeclRef::Kind::IVarInitializer,
2817-
ResilienceExpansion::Minimal,
2818-
SILDeclRef::ConstructAtNaturalUncurryLevel,
2819-
isForeign);
2814+
auto silRef = SILDeclRef(cd,
2815+
isDestroyer
2816+
? SILDeclRef::Kind::IVarDestroyer
2817+
: SILDeclRef::Kind::IVarInitializer)
2818+
.asForeign(isForeign);
28202819

28212820
// Find the SILFunction for the ivar initializer or destroyer.
28222821
if (auto silFn = getSILModule().lookUpFunction(silRef)) {

lib/IRGen/GenObjC.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,13 +1004,8 @@ static llvm::Constant *getObjCGetterPointer(IRGenModule &IGM,
10041004
if (isa<ProtocolDecl>(property->getDeclContext()))
10051005
return llvm::ConstantPointerNull::get(IGM.Int8PtrTy);
10061006

1007-
// FIXME: Explosion level
1008-
ResilienceExpansion expansion = ResilienceExpansion::Minimal;
1009-
1010-
SILDeclRef getter = SILDeclRef(property->getGetter(), SILDeclRef::Kind::Func,
1011-
expansion,
1012-
SILDeclRef::ConstructAtNaturalUncurryLevel,
1013-
/*foreign*/ true);
1007+
SILDeclRef getter = SILDeclRef(property->getGetter(), SILDeclRef::Kind::Func)
1008+
.asForeign();
10141009

10151010
return findSwiftAsObjCThunk(IGM, getter);
10161011
}
@@ -1028,11 +1023,8 @@ static llvm::Constant *getObjCSetterPointer(IRGenModule &IGM,
10281023
assert(property->isSettable(property->getDeclContext()) &&
10291024
"property is not settable?!");
10301025

1031-
ResilienceExpansion expansion = ResilienceExpansion::Minimal;
1032-
SILDeclRef setter = SILDeclRef(property->getSetter(), SILDeclRef::Kind::Func,
1033-
expansion,
1034-
SILDeclRef::ConstructAtNaturalUncurryLevel,
1035-
/*foreign*/ true);
1026+
SILDeclRef setter = SILDeclRef(property->getSetter(), SILDeclRef::Kind::Func)
1027+
.asForeign();
10361028

10371029
return findSwiftAsObjCThunk(IGM, setter);
10381030
}
@@ -1047,11 +1039,8 @@ static llvm::Constant *getObjCMethodPointer(IRGenModule &IGM,
10471039
if (isa<ProtocolDecl>(method->getDeclContext()))
10481040
return llvm::ConstantPointerNull::get(IGM.Int8PtrTy);
10491041

1050-
ResilienceExpansion expansion = ResilienceExpansion::Minimal;
1051-
SILDeclRef declRef = SILDeclRef(method, SILDeclRef::Kind::Func,
1052-
expansion,
1053-
SILDeclRef::ConstructAtNaturalUncurryLevel,
1054-
/*foreign*/ true);
1042+
SILDeclRef declRef = SILDeclRef(method, SILDeclRef::Kind::Func)
1043+
.asForeign();
10551044

10561045
return findSwiftAsObjCThunk(IGM, declRef);
10571046
}
@@ -1066,11 +1055,8 @@ static llvm::Constant *getObjCMethodPointer(IRGenModule &IGM,
10661055
if (isa<ProtocolDecl>(constructor->getDeclContext()))
10671056
return llvm::ConstantPointerNull::get(IGM.Int8PtrTy);
10681057

1069-
ResilienceExpansion expansion = ResilienceExpansion::Minimal;
1070-
SILDeclRef declRef = SILDeclRef(constructor, SILDeclRef::Kind::Initializer,
1071-
expansion,
1072-
SILDeclRef::ConstructAtNaturalUncurryLevel,
1073-
/*foreign*/ true);
1058+
SILDeclRef declRef = SILDeclRef(constructor, SILDeclRef::Kind::Initializer)
1059+
.asForeign();
10741060

10751061
return findSwiftAsObjCThunk(IGM, declRef);
10761062
}
@@ -1081,11 +1067,8 @@ static llvm::Constant *getObjCMethodPointer(IRGenModule &IGM,
10811067
/// Returns a value of type i8*.
10821068
static llvm::Constant *getObjCMethodPointer(IRGenModule &IGM,
10831069
DestructorDecl *destructor) {
1084-
ResilienceExpansion expansion = ResilienceExpansion::Minimal;
1085-
SILDeclRef declRef = SILDeclRef(destructor, SILDeclRef::Kind::Deallocator,
1086-
expansion,
1087-
SILDeclRef::ConstructAtNaturalUncurryLevel,
1088-
/*foreign*/ true);
1070+
SILDeclRef declRef = SILDeclRef(destructor, SILDeclRef::Kind::Deallocator)
1071+
.asForeign();
10891072

10901073
return findSwiftAsObjCThunk(IGM, declRef);
10911074
}

lib/Parse/ParseSIL.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,9 @@ bool SILParser::parseSILDeclRef(SILDeclRef &Result,
11851185

11861186
if (!P.consumeIf(tok::sil_exclamation)) {
11871187
// Construct SILDeclRef.
1188-
Result = SILDeclRef(VD, Kind, expansion, uncurryLevel, IsObjC);
1188+
Result = SILDeclRef(VD, Kind, expansion, /*isCurried=*/false, IsObjC);
1189+
if (uncurryLevel < Result.getUncurryLevel())
1190+
Result = Result.asCurried();
11891191
return false;
11901192
}
11911193

@@ -1274,7 +1276,9 @@ bool SILParser::parseSILDeclRef(SILDeclRef &Result,
12741276
} while (P.consumeIf(tok::period));
12751277

12761278
// Construct SILDeclRef.
1277-
Result = SILDeclRef(VD, Kind, expansion, uncurryLevel, IsObjC);
1279+
Result = SILDeclRef(VD, Kind, expansion, /*isCurried=*/false, IsObjC);
1280+
if (uncurryLevel < Result.getUncurryLevel())
1281+
Result = Result.asCurried();
12781282
return false;
12791283
}
12801284

0 commit comments

Comments
 (0)