Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.

[SwiftASTManipulator] Stop overriding access control. #1790

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lit/SwiftREPL/OpenClass.test
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions lit/SwiftREPL/ProtocolExtended.test
Original file line number Diff line number Diff line change
@@ -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:
57 changes: 0 additions & 57 deletions source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp
Original file line number Diff line number Diff line change
@@ -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<swift::StructDecl>(decl->getDeclContext())) {
if (auto var = llvm::dyn_cast<swift::VarDecl>(decl)) {
if (var->hasAttachedPropertyWrapper() ||
var->getOriginalWrappedProperty())
return false;

return true;
}

if (auto accessor = llvm::dyn_cast<swift::AccessorDecl>(decl)) {
return canMakePublic(accessor->getStorage());
}
}
return true;
}

bool walkToDeclPre(swift::Decl *D) override {
if (!canMakePublic(D))
return true;

if (auto *VD = llvm::dyn_cast<swift::ValueDecl>(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<swift::ClassDecl>(VD) || VD->isPotentiallyOverridable()) {
if (!VD->isFinal())
access = swift::AccessLevel::Open;
}

VD->overwriteAccess(access);
if (auto *ASD = llvm::dyn_cast<swift::AbstractStorageDecl>(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))
2 changes: 0 additions & 2 deletions source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.h
Original file line number Diff line number Diff line change
@@ -155,8 +155,6 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {

bool RewriteResult();

void MakeDeclarationsPublic();

void
FindVariableDeclarations(llvm::SmallVectorImpl<size_t> &found_declarations,
bool repl);
Original file line number Diff line number Diff line change
@@ -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);