Merge pull request #76250 from ktoso/wip-experimental-isolated-deinit

This commit is contained in:
Konrad `ktoso` Malawski
2024-10-03 17:19:10 +09:00
committed by GitHub
88 changed files with 4172 additions and 504 deletions

View File

@@ -182,6 +182,18 @@ static bool shouldPrintAllSemanticDetails(const PrintOptions &options) {
return false;
}
bool PrintOptions::excludeAttr(const DeclAttribute *DA) const {
if (excludeAttrKind(DA->getKind())) {
return true;
}
if (auto CA = dyn_cast<CustomAttr>(DA)) {
if (std::any_of(ExcludeCustomAttrList.begin(), ExcludeCustomAttrList.end(),
[CA](CustomAttr *other) { return other == CA; }))
return true;
}
return false;
}
/// Forces printing types with the `some` keyword, instead of the full stable
/// reference.
struct PrintWithOpaqueResultTypeKeywordRAII {
@@ -849,7 +861,13 @@ class PrintAST : public ASTVisitor<PrintAST> {
if (D->getDeclContext()->isLocalContext())
return;
printAccess(D->getFormalAccess());
if (Options.SuppressIsolatedDeinit &&
D->getFormalAccess() == AccessLevel::Open &&
usesFeatureIsolatedDeinit(D)) {
printAccess(AccessLevel::Public);
} else {
printAccess(D->getFormalAccess());
}
bool shouldSkipSetterAccess =
llvm::is_contained(Options.ExcludeAttrList, DeclAttrKind::SetterAccess);
@@ -1244,6 +1262,10 @@ void PrintAST::printAttributes(const Decl *D) {
// Save the current number of exclude attrs to restore once we're done.
unsigned originalExcludeAttrCount = Options.ExcludeAttrList.size();
// ExcludeCustomAttrList stores instances of attributes, which are specific
// for each decl They cannot be shared across different decls.
assert(Options.ExcludeCustomAttrList.empty());
if (Options.PrintImplicitAttrs) {
// Don't print a redundant 'final' if we are printing a 'static' decl.
@@ -1335,9 +1357,19 @@ void PrintAST::printAttributes(const Decl *D) {
Options.ExcludeAttrList.push_back(DeclAttrKind::Borrowing);
}
if (isa<DestructorDecl>(D) && Options.SuppressIsolatedDeinit) {
Options.ExcludeAttrList.push_back(DeclAttrKind::Nonisolated);
Options.ExcludeAttrList.push_back(DeclAttrKind::Isolated);
if (auto globalActor = D->getGlobalActorAttr()) {
Options.ExcludeCustomAttrList.push_back(globalActor->first);
}
}
attrs.print(Printer, Options, D);
Options.ExcludeAttrList.resize(originalExcludeAttrCount);
Options.ExcludeCustomAttrList.clear();
}
void PrintAST::printTypedPattern(const TypedPattern *TP) {
@@ -3172,6 +3204,13 @@ suppressingFeatureBitwiseCopyable2(PrintOptions &options,
action();
}
static void
suppressingFeatureIsolatedDeinit(PrintOptions &options,
llvm::function_ref<void()> action) {
llvm::SaveAndRestore<bool> scope(options.SuppressIsolatedDeinit, true);
action();
}
static void
suppressingFeatureAllowUnsafeAttribute(PrintOptions &options,
llvm::function_ref<void()> action) {