mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Rationalize Implicit Member Synthesis Somewhat
Codable's deep magic currently forces conformance checks in the middle of name lookup in order to inject CodingKeys into lookup results. This is compounded by the fact that this lookup fixup is occuring incrementally, meaning depending on order of requirements being looked up, Decl::getMembers() will give you a different answer. Compounding this, NameLookup relied on the LazyResolver to formalize this layering violation, and relied on implicit laziness to guard against re-entrancy. The approach is multi-pronged: 1) Shift the layering violation into the request evaluator 2) Spell out the kinds of resolution we support explicitly (make them easier to find and kill) 3) Remove the LazyResolver entrypoint this was relying on 4) Split off the property wrappers part into its own utility
This commit is contained in:
@@ -3956,6 +3956,48 @@ ConstructorDecl *NominalTypeDecl::getDefaultInitializer() const {
|
||||
SynthesizeDefaultInitRequest{mutableThis}, nullptr);
|
||||
}
|
||||
|
||||
void NominalTypeDecl::synthesizeSemanticMembersIfNeeded(DeclName member) {
|
||||
// Silently break cycles here because we can't be sure when and where a
|
||||
// request to synthesize will come from yet.
|
||||
// FIXME: rdar://56844567
|
||||
if (Bits.NominalTypeDecl.IsComputingSemanticMembers)
|
||||
return;
|
||||
|
||||
Bits.NominalTypeDecl.IsComputingSemanticMembers = true;
|
||||
SWIFT_DEFER { Bits.NominalTypeDecl.IsComputingSemanticMembers = false; };
|
||||
|
||||
auto baseName = member.getBaseName();
|
||||
auto &Context = getASTContext();
|
||||
Optional<ImplicitMemberAction> action = None;
|
||||
if (baseName == DeclBaseName::createConstructor())
|
||||
action.emplace(ImplicitMemberAction::ResolveImplicitInit);
|
||||
|
||||
if (member.isSimpleName() && !baseName.isSpecial()) {
|
||||
if (baseName.getIdentifier() == getASTContext().Id_CodingKeys) {
|
||||
action.emplace(ImplicitMemberAction::ResolveCodingKeys);
|
||||
}
|
||||
} else {
|
||||
auto argumentNames = member.getArgumentNames();
|
||||
if (member.isCompoundName() && argumentNames.size() != 1)
|
||||
return;
|
||||
|
||||
if (baseName == DeclBaseName::createConstructor() &&
|
||||
(member.isSimpleName() || argumentNames.front() == Context.Id_from)) {
|
||||
action.emplace(ImplicitMemberAction::ResolveDecodable);
|
||||
} else if (!baseName.isSpecial() &&
|
||||
baseName.getIdentifier() == Context.Id_encode &&
|
||||
(member.isSimpleName() ||
|
||||
argumentNames.front() == Context.Id_to)) {
|
||||
action.emplace(ImplicitMemberAction::ResolveEncodable);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto actionToTake = action) {
|
||||
(void)evaluateOrDefault(Context.evaluator,
|
||||
ResolveImplicitMemberRequest{this, actionToTake.getValue()}, false);
|
||||
}
|
||||
}
|
||||
|
||||
ClassDecl::ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc,
|
||||
MutableArrayRef<TypeLoc> Inherited,
|
||||
GenericParamList *GenericParams, DeclContext *Parent)
|
||||
|
||||
Reference in New Issue
Block a user