From e1a057aef398040009997fb413e02fb8cd807642 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Fri, 12 Jul 2019 12:36:19 -0700 Subject: [PATCH] [SwiftASTManipulator] Stop overriding access control. Defer this work to the compiler. Also fixes --- lit/SwiftREPL/OpenClass.test | 2 +- lit/SwiftREPL/ProtocolExtended.test | 11 ++++ .../Swift/SwiftASTManipulator.cpp | 57 ------------------- .../Swift/SwiftASTManipulator.h | 2 - .../Swift/SwiftExpressionParser.cpp | 7 +-- 5 files changed, 13 insertions(+), 66 deletions(-) create mode 100644 lit/SwiftREPL/ProtocolExtended.test diff --git a/lit/SwiftREPL/OpenClass.test b/lit/SwiftREPL/OpenClass.test index 4239f8e337b8..770f8170e6b2 100644 --- a/lit/SwiftREPL/OpenClass.test +++ b/lit/SwiftREPL/OpenClass.test @@ -25,4 +25,4 @@ class Baz: Foo { override func foo() -> Int { return 4 } } -// CHECK: error: overriding non-open instance method outside of its defining module +// CHECK: error: instance method overrides a 'final' instance method diff --git a/lit/SwiftREPL/ProtocolExtended.test b/lit/SwiftREPL/ProtocolExtended.test new file mode 100644 index 000000000000..4412a551ea06 --- /dev/null +++ b/lit/SwiftREPL/ProtocolExtended.test @@ -0,0 +1,11 @@ +// RUN: %lldb --repl < %s 2>&1 | FileCheck %s + +struct Foo {} + +extension Foo: CustomStringConvertible { + var description: String { + return "foo" + } +} + +// CHECK-NOT: error: diff --git a/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp b/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp index acea882d2914..241cfe2408a7 100644 --- a/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp +++ b/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp @@ -662,63 +662,6 @@ class AssignmentMaker { }; } -void SwiftASTManipulator::MakeDeclarationsPublic() { - if (!IsValid()) - return; - - class Publicist : public swift::ASTWalker { - static bool canMakePublic(swift::Decl *decl) { - // Properties within structs that have attached property wrappers - // shouldn't have their access reset; it impacts the implicit memberwise - // initializer. - if (llvm::isa(decl->getDeclContext())) { - if (auto var = llvm::dyn_cast(decl)) { - if (var->hasAttachedPropertyWrapper() || - var->getOriginalWrappedProperty()) - return false; - - return true; - } - - if (auto accessor = llvm::dyn_cast(decl)) { - return canMakePublic(accessor->getStorage()); - } - } - return true; - } - - bool walkToDeclPre(swift::Decl *D) override { - if (!canMakePublic(D)) - return true; - - if (auto *VD = llvm::dyn_cast(D)) { - auto access = swift::AccessLevel::Public; - - // We're making declarations 'public' so that they can be accessed from - // later expressions, but in the case of classes we also want to be able - // to subclass them, and override any overridable members. That is, we - // should use 'open' when it is possible and correct to do so, rather - // than just 'public'. - if (llvm::isa(VD) || VD->isPotentiallyOverridable()) { - if (!VD->isFinal()) - access = swift::AccessLevel::Open; - } - - VD->overwriteAccess(access); - if (auto *ASD = llvm::dyn_cast(D)) - ASD->overwriteSetterAccess(access); - } - return true; - } - }; - - Publicist p; - - for (swift::Decl *decl : m_source_file.Decls) { - decl->walk(p); - } -} - static bool hasInit(swift::PatternBindingDecl *pattern_binding) { for (unsigned i = 0, e = pattern_binding->getNumPatternEntries(); i != e; ++i) if (pattern_binding->getInit(i)) diff --git a/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.h b/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.h index 4213550fb221..540aba2e005b 100644 --- a/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.h +++ b/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.h @@ -155,8 +155,6 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase { bool RewriteResult(); - void MakeDeclarationsPublic(); - void FindVariableDeclarations(llvm::SmallVectorImpl &found_declarations, bool repl); diff --git a/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp b/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp index 54910a7217a7..6cfb6ec363ee 100644 --- a/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp +++ b/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp @@ -921,8 +921,7 @@ static swift::ASTContext *SetupASTContext( swift_ast_context->GetLanguageOptions().DebuggerSupport = true; // No longer part of debugger support, set it separately. swift_ast_context->GetLanguageOptions().EnableDollarIdentifiers = true; - swift_ast_context->GetLanguageOptions().EnableAccessControl = - (repl || playground); + swift_ast_context->GetLanguageOptions().EnableAccessControl = false; swift_ast_context->GetLanguageOptions().EnableTargetOSChecking = false; if (disable_objc_runtime()) @@ -1509,10 +1508,6 @@ unsigned SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager, log->PutCString(s.c_str()); } - if (repl) { - parsed_expr->code_manipulator->MakeDeclarationsPublic(); - } - Status error; if (!playground) { parsed_expr->code_manipulator->FixupResultAfterTypeChecking(error);