-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Lazy accessor synthesis for storage in primary files #26469
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
slavapestov
merged 5 commits into
swiftlang:master
from
slavapestov:lazy-accessor-synthesis-part-2
Aug 7, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e0cc652
AST: Replace AbstractStorageDecl::hasAnyAccessors() with hasParsedAcc…
slavapestov 6c5ecb5
AST: Introduce AbstractStorageDecl::visit{Parsed,Emitted}Accessors()
slavapestov a4bb310
Sema: Remove addExpectedOpaqueAccessorsToStorage()
slavapestov 2e3f4ac
AST: Fix mangling of unvalidated declarations
slavapestov 05baaa8
AST: Slightly more efficient requiresNewVTableEntry()
slavapestov 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
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
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 |
---|---|---|
|
@@ -2140,23 +2140,24 @@ static FuncDecl *findReplacedAccessor(DeclName replacedVarName, | |
} | ||
|
||
// Find the accessor in the replaced storage decl. | ||
for (auto *origAccessor : origStorage->getAllAccessors()) { | ||
TC.validateDecl(origAccessor); | ||
if (origAccessor->getAccessorKind() != replacement->getAccessorKind()) | ||
continue; | ||
auto *origAccessor = origStorage->getOpaqueAccessor( | ||
replacement->getAccessorKind()); | ||
if (!origAccessor) | ||
return nullptr; | ||
|
||
if (origAccessor->isImplicit() && | ||
!(origStorage->getReadImpl() == ReadImplKind::Stored && | ||
origStorage->getWriteImpl() == WriteImplKind::Stored)) { | ||
TC.diagnose(attr->getLocation(), | ||
diag::dynamic_replacement_accessor_not_explicit, | ||
(unsigned)origAccessor->getAccessorKind(), replacedVarName); | ||
attr->setInvalid(); | ||
return nullptr; | ||
} | ||
return origAccessor; | ||
TC.validateDecl(origAccessor); | ||
|
||
if (origAccessor->isImplicit() && | ||
!(origStorage->getReadImpl() == ReadImplKind::Stored && | ||
origStorage->getWriteImpl() == WriteImplKind::Stored)) { | ||
TC.diagnose(attr->getLocation(), | ||
diag::dynamic_replacement_accessor_not_explicit, | ||
(unsigned)origAccessor->getAccessorKind(), replacedVarName); | ||
attr->setInvalid(); | ||
return nullptr; | ||
} | ||
return nullptr; | ||
|
||
return origAccessor; | ||
} | ||
|
||
static AbstractFunctionDecl * | ||
|
@@ -2298,19 +2299,19 @@ void TypeChecker::checkDynamicReplacementAttribute(ValueDecl *D) { | |
|
||
// Collect the accessor replacement mapping if this is an abstract storage. | ||
if (auto *var = dyn_cast<AbstractStorageDecl>(D)) { | ||
for (auto *accessor : var->getAllAccessors()) { | ||
var->visitParsedAccessors([&](AccessorDecl *accessor) { | ||
if (attr->isInvalid()) | ||
return; | ||
|
||
validateDecl(accessor); | ||
if (accessor->isImplicit()) | ||
continue; | ||
auto *orig = findReplacedAccessor(attr->getReplacedFunctionName(), | ||
accessor, attr, *this); | ||
if (attr->isInvalid()) | ||
return; | ||
if (!orig) | ||
continue; | ||
return; | ||
|
||
origs.push_back(orig); | ||
replacements.push_back(accessor); | ||
} | ||
}); | ||
} else { | ||
// Otherwise, find the matching function. | ||
auto *fun = cast<AbstractFunctionDecl>(D); | ||
|
@@ -2823,12 +2824,14 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) { | |
return; | ||
} | ||
|
||
// Don't add dynamic if accessor is inlinable or tranparent. | ||
// Don't add dynamic if accessor is inlinable or transparent. | ||
if (auto *asd = dyn_cast<AbstractStorageDecl>(D)) { | ||
for (auto *accessor : asd->getAllAccessors()) { | ||
if (!accessor->isImplicit() && shouldBlockImplicitDynamic(accessor)) | ||
return; | ||
} | ||
bool blocked = false; | ||
asd->visitParsedAccessors([&](AccessorDecl *accessor) { | ||
blocked |= shouldBlockImplicitDynamic(accessor); | ||
}); | ||
|
||
if (blocked) | ||
return; | ||
} | ||
|
||
if (auto *VD = dyn_cast<VarDecl>(D)) { | ||
|
Oops, something went wrong.
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.
"Eagerly" emitted accessors, maybe?