-
Notifications
You must be signed in to change notification settings - Fork 10.5k
More TBD work #9983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
More TBD work #9983
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fed23ed
[TBDGen] Include both direct and indirect field offsets.
huonw 002e4d5
[TBDGen] Include extra allocating constructors instead of missing some.
huonw 8d455a4
[TBDGen] Explicitly walk members of stored static vars.
huonw 296f231
[TBDGen] Protocol witnesses thunks for members of public superprotoco…
huonw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,22 +62,7 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> { | |
addSymbol(linkage.getName()); | ||
} | ||
|
||
void addConformances(DeclContext *DC) { | ||
for (auto conformance : DC->getLocalConformances()) { | ||
auto needsWTable = Lowering::TypeConverter::protocolRequiresWitnessTable( | ||
conformance->getProtocol()); | ||
if (!needsWTable) | ||
continue; | ||
|
||
// Only normal conformances get symbols; the others get any public symbols | ||
// from their parent normal conformance. | ||
if (conformance->getKind() != ProtocolConformanceKind::Normal) | ||
continue; | ||
|
||
addSymbol(LinkEntity::forDirectProtocolWitnessTable(conformance)); | ||
addSymbol(LinkEntity::forProtocolWitnessTableAccessFunction(conformance)); | ||
} | ||
} | ||
void addConformances(DeclContext *DC); | ||
|
||
public: | ||
TBDGenVisitor(StringSet &symbols, | ||
|
@@ -96,6 +81,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> { | |
addMembers(ED->getMembers()); | ||
else if (auto NTD = dyn_cast<NominalTypeDecl>(D)) | ||
addMembers(NTD->getMembers()); | ||
else if (auto VD = dyn_cast<VarDecl>(D)) | ||
VD->getAllAccessorFunctions(members); | ||
|
||
for (auto member : members) { | ||
ASTVisitor::visit(member); | ||
|
@@ -160,10 +147,6 @@ void TBDGenVisitor::addSymbol(SILDeclRef declRef, bool checkSILOnly) { | |
// currently need to refer to them by symbol for their own vtable. | ||
switch (declRef.getSubclassScope()) { | ||
case SubclassScope::External: | ||
// Allocating constructors retain their normal linkage behavior. | ||
if (declRef.kind == SILDeclRef::Kind::Allocator) | ||
break; | ||
|
||
// Unlike the "truly" public things, private things have public symbols | ||
// unconditionally, even if they're theoretically SIL only. | ||
if (isPrivate) { | ||
|
@@ -186,6 +169,81 @@ void TBDGenVisitor::addSymbol(SILDeclRef declRef, bool checkSILOnly) { | |
addSymbol(declRef.mangle()); | ||
} | ||
|
||
void TBDGenVisitor::addConformances(DeclContext *DC) { | ||
for (auto conformance : DC->getLocalConformances()) { | ||
auto protocol = conformance->getProtocol(); | ||
auto needsWTable = | ||
Lowering::TypeConverter::protocolRequiresWitnessTable(protocol); | ||
if (!needsWTable) | ||
continue; | ||
|
||
// Only normal conformances get symbols; the others get any public symbols | ||
// from their parent normal conformance. | ||
auto normalConformance = dyn_cast<NormalProtocolConformance>(conformance); | ||
if (!normalConformance) | ||
continue; | ||
|
||
addSymbol(LinkEntity::forDirectProtocolWitnessTable(normalConformance)); | ||
addSymbol( | ||
LinkEntity::forProtocolWitnessTableAccessFunction(normalConformance)); | ||
|
||
// FIXME: the logic around visibility in extensions is confusing, and | ||
// sometimes witness thunks need to be manually made public. | ||
|
||
auto conformanceIsSerialized = normalConformance->isSerialized(); | ||
auto addSymbolIfNecessary = [&](ValueDecl *valueReq, | ||
SILLinkage witnessLinkage) { | ||
if (conformanceIsSerialized && | ||
fixmeWitnessHasLinkageThatNeedsToBePublic(witnessLinkage)) { | ||
Mangle::ASTMangler Mangler; | ||
addSymbol(Mangler.mangleWitnessThunk(normalConformance, valueReq)); | ||
} | ||
}; | ||
normalConformance->forEachValueWitness(nullptr, [&](ValueDecl *valueReq, | ||
Witness witness) { | ||
if (isa<AbstractFunctionDecl>(valueReq)) { | ||
auto witnessLinkage = | ||
SILDeclRef(witness.getDecl()).getLinkage(ForDefinition); | ||
addSymbolIfNecessary(valueReq, witnessLinkage); | ||
} else if (auto VD = dyn_cast<AbstractStorageDecl>(valueReq)) { | ||
// A var or subscript decl needs special handling in the special | ||
// handling: the things that end up in the witness table are the | ||
// accessors, but the compiler only talks about the actual storage decl | ||
// in the conformance, so we have to manually walk over the members, | ||
// having pulled out something that will have the right linkage. | ||
auto witnessVD = cast<AbstractStorageDecl>(witness.getDecl()); | ||
|
||
SmallVector<Decl *, 4> members; | ||
VD->getAllAccessorFunctions(members); | ||
|
||
// Grab one of the accessors, and then use that to pull out which of the | ||
// getter or setter will have the appropriate linkage. | ||
FuncDecl *witnessWithRelevantLinkage; | ||
switch (cast<FuncDecl>(members[0])->getAccessorKind()) { | ||
case AccessorKind::NotAccessor: | ||
llvm_unreachable("must be an accessor"); | ||
case AccessorKind::IsGetter: | ||
case AccessorKind::IsAddressor: | ||
witnessWithRelevantLinkage = witnessVD->getGetter(); | ||
break; | ||
case AccessorKind::IsSetter: | ||
case AccessorKind::IsWillSet: | ||
case AccessorKind::IsDidSet: | ||
case AccessorKind::IsMaterializeForSet: | ||
case AccessorKind::IsMutableAddressor: | ||
witnessWithRelevantLinkage = witnessVD->getSetter(); | ||
break; | ||
} | ||
auto witnessLinkage = | ||
SILDeclRef(witnessWithRelevantLinkage).getLinkage(ForDefinition); | ||
for (auto member : members) { | ||
addSymbolIfNecessary(cast<ValueDecl>(member), witnessLinkage); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
void TBDGenVisitor::visitValueDecl(ValueDecl *VD) { | ||
addSymbol(SILDeclRef(VD)); | ||
visitMembers(VD); | ||
|
@@ -225,9 +283,11 @@ void TBDGenVisitor::visitVarDecl(VarDecl *VD) { | |
// like globals. | ||
if (!FileHasEntryPoint) | ||
addSymbol(SILDeclRef(VD, SILDeclRef::Kind::GlobalAccessor)); | ||
} | ||
|
||
visitMembers(VD); | ||
// In this case, the members of the VarDecl don't also appear as top-level | ||
// decls, so we need to explicitly walk them. | ||
visitMembers(VD); | ||
} | ||
} | ||
|
||
void TBDGenVisitor::visitNominalTypeDecl(NominalTypeDecl *NTD) { | ||
|
@@ -281,9 +341,11 @@ void TBDGenVisitor::visitClassDecl(ClassDecl *CD) { | |
auto hasFieldOffset = | ||
!isGeneric && var && var->hasStorage() && !var->isStatic(); | ||
if (hasFieldOffset) { | ||
// Field are only direct if the class's internals are completely known. | ||
auto isIndirect = !CD->hasFixedLayout(); | ||
addSymbol(LinkEntity::forFieldOffset(var, isIndirect)); | ||
// FIXME: a field only has one sort of offset, but it is moderately | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we find a way to use IRGen type lowering from TBDGen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, rdar://problem/32252689 . |
||
// non-trivial to compute which one. Including both is less painful than | ||
// missing the correct one (for now), so we do that. | ||
addSymbol(LinkEntity::forFieldOffset(var, /*isIndirect=*/false)); | ||
addSymbol(LinkEntity::forFieldOffset(var, /*isIndirect=*/true)); | ||
} | ||
|
||
// The non-allocating forms of the constructors and destructors. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can observers and addressors ever be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it is correct for them to be public, but yes, it seems that addressors can currently: rdar://problem/32391290
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observers cannot and never will be, addressors can and probably always are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean addressors are sometimes called directly, and not just via getter/setter/materializeForSet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, maybe I'm wrong, but I thought so. @rjmccall?