-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Requestify Class Ancestry Flags #26794
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3820,8 +3820,6 @@ ClassDecl::ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc, | |
= static_cast<unsigned>(CircularityCheck::Unchecked); | ||
Bits.ClassDecl.InheritsSuperclassInits = 0; | ||
Bits.ClassDecl.RawForeignKind = 0; | ||
Bits.ClassDecl.Ancestry = 0; | ||
Bits.ClassDecl.AncestryComputed = 0; | ||
Bits.ClassDecl.HasMissingDesignatedInitializers = 0; | ||
Bits.ClassDecl.HasMissingVTableEntries = 0; | ||
Bits.ClassDecl.IsIncompatibleWithWeakReferences = 0; | ||
|
@@ -3956,16 +3954,20 @@ bool ClassDecl::inheritsSuperclassInitializers() { | |
return Bits.ClassDecl.InheritsSuperclassInits; | ||
} | ||
|
||
AncestryOptions ClassDecl::checkAncestry() const { | ||
// See if we've already computed this. | ||
if (Bits.ClassDecl.AncestryComputed) | ||
return AncestryOptions(Bits.ClassDecl.Ancestry); | ||
|
||
AncestryOptions ClassDecl::checkAncestry() const { | ||
return AncestryOptions(evaluateOrDefault(getASTContext().evaluator, | ||
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. Can you have the request return AncestryOptions instead of AncestryFlags to avoid the coercion? 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. OptionSet doesn’t have an equality operator for good reason (see the file). I’m sure Sufficiently Magic Template Nonsense will let us do this eventually. |
||
ClassAncestryFlagsRequest{const_cast<ClassDecl *>(this)}, | ||
AncestryFlags())); | ||
} | ||
|
||
llvm::Expected<AncestryFlags> | ||
ClassAncestryFlagsRequest::evaluate(Evaluator &evaluator, ClassDecl *value) const { | ||
llvm::SmallPtrSet<const ClassDecl *, 8> visited; | ||
|
||
AncestryOptions result; | ||
const ClassDecl *CD = this; | ||
auto *M = getParentModule(); | ||
const ClassDecl *CD = value; | ||
auto *M = value->getParentModule(); | ||
|
||
do { | ||
// If we hit circularity, we will diagnose at some point in typeCheckDecl(). | ||
|
@@ -4000,10 +4002,39 @@ AncestryOptions ClassDecl::checkAncestry() const { | |
CD = CD->getSuperclassDecl(); | ||
} while (CD != nullptr); | ||
|
||
// Save the result for later. | ||
const_cast<ClassDecl *>(this)->Bits.ClassDecl.Ancestry = result.toRaw(); | ||
const_cast<ClassDecl *>(this)->Bits.ClassDecl.AncestryComputed = 1; | ||
return result; | ||
return AncestryFlags(result.toRaw()); | ||
} | ||
|
||
void swift::simple_display(llvm::raw_ostream &out, AncestryFlags value) { | ||
AncestryOptions opts(value); | ||
out << "{ "; | ||
// If we have more than one bit set, we need to print the separator. | ||
bool wantsSeparator = false; | ||
auto printBit = [&wantsSeparator, &out](bool val, StringRef name) { | ||
if (wantsSeparator) { | ||
out << ", "; | ||
} | ||
|
||
if (!wantsSeparator) { | ||
wantsSeparator = true; | ||
} | ||
|
||
out << name; | ||
if (val) { | ||
out << " = true"; | ||
} else { | ||
out << " = false"; | ||
} | ||
}; | ||
printBit(opts.contains(AncestryFlags::ObjC), "ObjC"); | ||
printBit(opts.contains(AncestryFlags::ObjCMembers), "ObjCMembers"); | ||
printBit(opts.contains(AncestryFlags::Generic), "Generic"); | ||
printBit(opts.contains(AncestryFlags::Resilient), "Resilient"); | ||
printBit(opts.contains(AncestryFlags::ResilientOther), "ResilientOther"); | ||
printBit(opts.contains(AncestryFlags::ClangImported), "ClangImported"); | ||
printBit(opts.contains(AncestryFlags::RequiresStoredPropertyInits), | ||
"RequiresStoredPropertyInits"); | ||
out << " }"; | ||
} | ||
|
||
bool ClassDecl::isSuperclassOf(ClassDecl *other) const { | ||
|
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.
Since these are used rather frequently, I would imagine making this request ExternallyCached would still be profitable. Or maybe not...