Skip to content

Commit fcf3118

Browse files
authored
Merge pull request swiftlang#30499 from slavapestov/remove-curried-declrefs
SIL: Remove curried SILDeclRefs
2 parents adc5756 + 9ec80df commit fcf3118

File tree

474 files changed

+3960
-4189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

474 files changed

+3960
-4189
lines changed

docs/SIL.rst

Lines changed: 46 additions & 131 deletions
Large diffs are not rendered by default.

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class ASTMangler : public Mangler {
8080
DynamicThunk,
8181
SwiftAsObjCThunk,
8282
ObjCAsSwiftThunk,
83-
DirectMethodReferenceThunk,
8483
};
8584

8685
ASTMangler(bool DWARFMangling = false)
@@ -98,14 +97,14 @@ class ASTMangler : public Mangler {
9897
std::string mangleClosureEntity(const AbstractClosureExpr *closure,
9998
SymbolKind SKind);
10099

101-
std::string mangleEntity(const ValueDecl *decl, bool isCurried,
100+
std::string mangleEntity(const ValueDecl *decl,
102101
SymbolKind SKind = SymbolKind::Default);
103102

104103
std::string mangleDestructorEntity(const DestructorDecl *decl,
105104
bool isDeallocating, SymbolKind SKind);
106105

107106
std::string mangleConstructorEntity(const ConstructorDecl *ctor,
108-
bool isAllocating, bool isCurried,
107+
bool isAllocating,
109108
SymbolKind SKind = SymbolKind::Default);
110109

111110
std::string mangleIVarInitDestroyEntity(const ClassDecl *decl,

include/swift/IRGen/Linking.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,7 @@ class LinkEntity {
554554
LinkEntity() = default;
555555

556556
static bool isValidResilientMethodRef(SILDeclRef declRef) {
557-
if (declRef.isForeign ||
558-
declRef.isDirectReference ||
559-
declRef.isCurried)
557+
if (declRef.isForeign)
560558
return false;
561559

562560
auto *decl = declRef.getDecl();

include/swift/SIL/SILDeclRef.h

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,16 @@ struct SILDeclRef {
143143
Loc loc;
144144
/// The Kind of this SILDeclRef.
145145
Kind kind : 4;
146-
/// True if the SILDeclRef is a curry thunk.
147-
unsigned isCurried : 1;
148146
/// True if this references a foreign entry point for the referenced decl.
149147
unsigned isForeign : 1;
150-
/// True if this is a direct reference to a class's method implementation
151-
/// that isn't dynamically dispatched.
152-
unsigned isDirectReference : 1;
153148
/// The default argument index for a default argument getter.
154149
unsigned defaultArgIndex : 10;
155150

156151
/// Produces a null SILDeclRef.
157-
SILDeclRef() : loc(), kind(Kind::Func),
158-
isCurried(0), isForeign(0), isDirectReference(0),
159-
defaultArgIndex(0) {}
152+
SILDeclRef() : loc(), kind(Kind::Func), isForeign(0), defaultArgIndex(0) {}
160153

161154
/// Produces a SILDeclRef of the given kind for the given decl.
162155
explicit SILDeclRef(ValueDecl *decl, Kind kind,
163-
bool isCurried = false,
164156
bool isForeign = false);
165157

166158
/// Produces a SILDeclRef for the given ValueDecl or
@@ -174,13 +166,7 @@ struct SILDeclRef {
174166
/// for the containing ClassDecl.
175167
/// - If 'loc' is a global VarDecl, this returns its GlobalAccessor
176168
/// SILDeclRef.
177-
///
178-
/// If 'isCurried' is true, the loc must be a method or enum element;
179-
/// the SILDeclRef will then refer to a curry thunk with type
180-
/// (Self) -> (Args...) -> Result, rather than a direct reference to
181-
/// the actual method whose lowered type is (Args..., Self) -> Result.
182169
explicit SILDeclRef(Loc loc,
183-
bool isCurried = false,
184170
bool isForeign = false);
185171

186172
/// Produce a SIL constant for a default argument generator.
@@ -289,16 +275,13 @@ struct SILDeclRef {
289275
llvm::hash_code getHashCode() const {
290276
return llvm::hash_combine(loc.getOpaqueValue(),
291277
static_cast<int>(kind),
292-
isCurried, isForeign, isDirectReference,
293-
defaultArgIndex);
278+
isForeign, defaultArgIndex);
294279
}
295280

296281
bool operator==(SILDeclRef rhs) const {
297282
return loc.getOpaqueValue() == rhs.loc.getOpaqueValue()
298283
&& kind == rhs.kind
299-
&& isCurried == rhs.isCurried
300284
&& isForeign == rhs.isForeign
301-
&& isDirectReference == rhs.isDirectReference
302285
&& defaultArgIndex == rhs.defaultArgIndex;
303286
}
304287
bool operator!=(SILDeclRef rhs) const {
@@ -309,32 +292,12 @@ struct SILDeclRef {
309292
void dump() const;
310293

311294
unsigned getParameterListCount() const;
312-
313-
// Returns the SILDeclRef for an entity at a shallower uncurry level.
314-
SILDeclRef asCurried(bool curried = true) const {
315-
assert(!isCurried && "can't safely go to deeper uncurry level");
316-
// Curry thunks are never foreign.
317-
bool willBeForeign = isForeign && !curried;
318-
bool willBeDirect = isDirectReference;
319-
return SILDeclRef(loc.getOpaqueValue(), kind,
320-
curried, willBeDirect, willBeForeign,
321-
defaultArgIndex);
322-
}
323-
295+
324296
/// Returns the foreign (or native) entry point corresponding to the same
325297
/// decl.
326298
SILDeclRef asForeign(bool foreign = true) const {
327-
assert(!isCurried);
328299
return SILDeclRef(loc.getOpaqueValue(), kind,
329-
isCurried, isDirectReference, foreign, defaultArgIndex);
330-
}
331-
332-
SILDeclRef asDirectReference(bool direct = true) const {
333-
SILDeclRef r = *this;
334-
// The 'direct' distinction only makes sense for curry thunks.
335-
if (r.isCurried)
336-
r.isDirectReference = direct;
337-
return r;
300+
foreign, defaultArgIndex);
338301
}
339302

340303
/// True if the decl ref references a thunk from a natively foreign
@@ -408,15 +371,10 @@ struct SILDeclRef {
408371
/// Produces a SILDeclRef from an opaque value.
409372
explicit SILDeclRef(void *opaqueLoc,
410373
Kind kind,
411-
bool isCurried,
412-
bool isDirectReference,
413374
bool isForeign,
414375
unsigned defaultArgIndex)
415-
: loc(Loc::getFromOpaqueValue(opaqueLoc)),
416-
kind(kind),
417-
isCurried(isCurried),
418-
isForeign(isForeign), isDirectReference(isDirectReference),
419-
defaultArgIndex(defaultArgIndex)
376+
: loc(Loc::getFromOpaqueValue(opaqueLoc)), kind(kind),
377+
isForeign(isForeign), defaultArgIndex(defaultArgIndex)
420378
{}
421379

422380
};
@@ -440,21 +398,20 @@ template<> struct DenseMapInfo<swift::SILDeclRef> {
440398

441399
static SILDeclRef getEmptyKey() {
442400
return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func,
443-
false, false, false, 0);
401+
false, 0);
444402
}
445403
static SILDeclRef getTombstoneKey() {
446404
return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func,
447-
false, false, false, 0);
405+
false, 0);
448406
}
449407
static unsigned getHashValue(swift::SILDeclRef Val) {
450408
unsigned h1 = PointerInfo::getHashValue(Val.loc.getOpaqueValue());
451409
unsigned h2 = UnsignedInfo::getHashValue(unsigned(Val.kind));
452410
unsigned h3 = (Val.kind == Kind::DefaultArgGenerator)
453411
? UnsignedInfo::getHashValue(Val.defaultArgIndex)
454-
: UnsignedInfo::getHashValue(Val.isCurried);
412+
: 0;
455413
unsigned h4 = UnsignedInfo::getHashValue(Val.isForeign);
456-
unsigned h5 = UnsignedInfo::getHashValue(Val.isDirectReference);
457-
return h1 ^ (h2 << 4) ^ (h3 << 9) ^ (h4 << 7) ^ (h5 << 11);
414+
return h1 ^ (h2 << 4) ^ (h3 << 9) ^ (h4 << 7);
458415
}
459416
static bool isEqual(swift::SILDeclRef const &LHS,
460417
swift::SILDeclRef const &RHS) {

include/swift/SIL/SILVTableVisitor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ struct SortedFuncList {
3737
Mangle::ASTMangler mangler;
3838
std::string mangledName;
3939
if (auto *cd = dyn_cast<ConstructorDecl>(afd))
40-
mangledName = mangler.mangleConstructorEntity(cd, 0, 0);
40+
mangledName = mangler.mangleConstructorEntity(cd, 0);
4141
else
42-
mangledName = mangler.mangleEntity(afd, 0);
42+
mangledName = mangler.mangleEntity(afd);
4343

4444
elts.push_back(std::make_pair(mangledName, afd));
4545
}

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,9 @@ std::string ASTMangler::mangleClosureEntity(const AbstractClosureExpr *closure,
7878
return finalize();
7979
}
8080

81-
std::string ASTMangler::mangleEntity(const ValueDecl *decl, bool isCurried,
82-
SymbolKind SKind) {
81+
std::string ASTMangler::mangleEntity(const ValueDecl *decl, SymbolKind SKind) {
8382
beginMangling();
8483
appendEntity(decl);
85-
if (isCurried)
86-
appendOperator("Tc");
8784
appendSymbolKind(SKind);
8885
return finalize();
8986
}
@@ -99,12 +96,9 @@ std::string ASTMangler::mangleDestructorEntity(const DestructorDecl *decl,
9996

10097
std::string ASTMangler::mangleConstructorEntity(const ConstructorDecl *ctor,
10198
bool isAllocating,
102-
bool isCurried,
10399
SymbolKind SKind) {
104100
beginMangling();
105101
appendConstructorEntity(ctor, isAllocating);
106-
if (isCurried)
107-
appendOperator("Tc");
108102
appendSymbolKind(SKind);
109103
return finalize();
110104
}
@@ -587,7 +581,6 @@ void ASTMangler::appendSymbolKind(SymbolKind SKind) {
587581
case SymbolKind::DynamicThunk: return appendOperator("TD");
588582
case SymbolKind::SwiftAsObjCThunk: return appendOperator("To");
589583
case SymbolKind::ObjCAsSwiftThunk: return appendOperator("TO");
590-
case SymbolKind::DirectMethodReferenceThunk: return appendOperator("Td");
591584
}
592585
}
593586

lib/IRGen/GenObjC.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,6 @@ void irgen::emitObjCIVarInitDestroyDescriptor(
13811381
SILDeclRef declRef = SILDeclRef(cd,
13821382
isDestroyer? SILDeclRef::Kind::IVarDestroyer
13831383
: SILDeclRef::Kind::IVarInitializer,
1384-
1,
13851384
/*foreign*/ true);
13861385
Selector selector(declRef);
13871386

lib/IRGen/Linking.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,9 @@ std::string LinkEntity::mangleAsString() const {
352352
assert(isa<AbstractFunctionDecl>(getDecl()));
353353
std::string Result;
354354
if (auto *Constructor = dyn_cast<ConstructorDecl>(getDecl())) {
355-
Result = mangler.mangleConstructorEntity(Constructor, isAllocator(),
356-
/*isCurried=*/false);
355+
Result = mangler.mangleConstructorEntity(Constructor, isAllocator());
357356
} else {
358-
Result = mangler.mangleEntity(getDecl(), /*isCurried=*/false);
357+
Result = mangler.mangleEntity(getDecl());
359358
}
360359
Result.append("TI");
361360
return Result;
@@ -379,10 +378,9 @@ std::string LinkEntity::mangleAsString() const {
379378
std::string Result;
380379
if (auto *Constructor = dyn_cast<ConstructorDecl>(getDecl())) {
381380
Result =
382-
mangler.mangleConstructorEntity(Constructor, isAllocator(),
383-
/*isCurried=*/false);
381+
mangler.mangleConstructorEntity(Constructor, isAllocator());
384382
} else {
385-
Result = mangler.mangleEntity(getDecl(), /*isCurried=*/false);
383+
Result = mangler.mangleEntity(getDecl());
386384
}
387385
Result.append("TX");
388386
return Result;
@@ -393,10 +391,9 @@ std::string LinkEntity::mangleAsString() const {
393391
std::string Result;
394392
if (auto *Constructor = dyn_cast<ConstructorDecl>(getDecl())) {
395393
Result =
396-
mangler.mangleConstructorEntity(Constructor, isAllocator(),
397-
/*isCurried=*/false);
394+
mangler.mangleConstructorEntity(Constructor, isAllocator());
398395
} else {
399-
Result = mangler.mangleEntity(getDecl(), /*isCurried=*/false);
396+
Result = mangler.mangleEntity(getDecl());
400397
}
401398
Result.append("Tx");
402399
return Result;

lib/ParseSIL/ParseSIL.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,7 @@ static Optional<AccessorKind> getAccessorKind(StringRef ident) {
13401340
}
13411341

13421342
/// sil-decl-ref ::= '#' sil-identifier ('.' sil-identifier)* sil-decl-subref?
1343-
/// sil-decl-subref ::= '!' sil-decl-subref-part ('.' sil-decl-uncurry-level)?
1344-
/// ('.' sil-decl-lang)?
1345-
/// sil-decl-subref ::= '!' sil-decl-uncurry-level ('.' sil-decl-lang)?
1343+
/// sil-decl-subref ::= '!' sil-decl-subref-part ('.' sil-decl-lang)?
13461344
/// sil-decl-subref ::= '!' sil-decl-lang
13471345
/// sil-decl-subref-part ::= 'getter'
13481346
/// sil-decl-subref-part ::= 'setter'
@@ -1351,33 +1349,28 @@ static Optional<AccessorKind> getAccessorKind(StringRef ident) {
13511349
/// sil-decl-subref-part ::= 'enumelt'
13521350
/// sil-decl-subref-part ::= 'destroyer'
13531351
/// sil-decl-subref-part ::= 'globalaccessor'
1354-
/// sil-decl-uncurry-level ::= [0-9]+
13551352
/// sil-decl-lang ::= 'foreign'
13561353
bool SILParser::parseSILDeclRef(SILDeclRef &Result,
13571354
SmallVectorImpl<ValueDecl *> &values) {
13581355
ValueDecl *VD;
13591356
if (parseSILDottedPath(VD, values))
13601357
return true;
13611358

1362-
// Initialize Kind, uncurryLevel and IsObjC.
1359+
// Initialize Kind and IsObjC.
13631360
SILDeclRef::Kind Kind = SILDeclRef::Kind::Func;
1364-
unsigned uncurryLevel = 0;
13651361
bool IsObjC = false;
13661362

13671363
if (!P.consumeIf(tok::sil_exclamation)) {
13681364
// Construct SILDeclRef.
1369-
Result = SILDeclRef(VD, Kind, /*isCurried=*/false, IsObjC);
1370-
if (uncurryLevel < Result.getParameterListCount() - 1)
1371-
Result = Result.asCurried();
1365+
Result = SILDeclRef(VD, Kind, IsObjC);
13721366
return false;
13731367
}
13741368

13751369
// Handle sil-constant-kind-and-uncurry-level.
13761370
// ParseState indicates the value we just handled.
1377-
// 1 means we just handled Kind, 2 means we just handled uncurryLevel.
1378-
// We accept func|getter|setter|...|foreign or an integer when ParseState is
1379-
// 0; accept foreign or an integer when ParseState is 1; accept foreign when
1380-
// ParseState is 2.
1371+
// 1 means we just handled Kind.
1372+
// We accept func|getter|setter|...|foreign when ParseState is 0;
1373+
// accept foreign when ParseState is 1.
13811374
unsigned ParseState = 0;
13821375
Identifier Id;
13831376
do {
@@ -1448,19 +1441,13 @@ bool SILParser::parseSILDeclRef(SILDeclRef &Result,
14481441
break;
14491442
} else
14501443
break;
1451-
} else if (ParseState < 2 && P.Tok.is(tok::integer_literal)) {
1452-
parseIntegerLiteral(P.Tok.getText(), 0, uncurryLevel);
1453-
P.consumeToken(tok::integer_literal);
1454-
ParseState = 2;
14551444
} else
14561445
break;
14571446

14581447
} while (P.consumeIf(tok::period));
14591448

14601449
// Construct SILDeclRef.
1461-
Result = SILDeclRef(VD, Kind, /*isCurried=*/false, IsObjC);
1462-
if (uncurryLevel < Result.getParameterListCount() - 1)
1463-
Result = Result.asCurried();
1450+
Result = SILDeclRef(VD, Kind, IsObjC);
14641451
return false;
14651452
}
14661453

0 commit comments

Comments
 (0)