Skip to content

[Serialization] Compatibility fixes to deserialization safety and access-level #65161

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

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,17 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
OPT_disable_deserialization_safety)) {
Opts.EnableDeserializationSafety
= A->getOption().matches(OPT_enable_deserialization_safety);
} else if (auto A = Args.getLastArg(OPT_enable_access_control,
OPT_disable_access_control)) {
// Disable deserialization safety along with access control.
Opts.EnableDeserializationSafety
= A->getOption().matches(OPT_enable_access_control);
}

if (auto A = Args.getLastArg(OPT_enable_access_control,
OPT_disable_access_control)) {
Opts.EnableAccessControl
= A->getOption().matches(OPT_enable_access_control);
}

// Whether '/.../' regex literals are enabled. This implies experimental
Expand Down Expand Up @@ -616,12 +627,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Args.hasArg(OPT_warn_on_potentially_unavailable_enum_case);
Opts.WarnOnEditorPlaceholder |= Args.hasArg(OPT_warn_on_editor_placeholder);

if (auto A = Args.getLastArg(OPT_enable_access_control,
OPT_disable_access_control)) {
Opts.EnableAccessControl
= A->getOption().matches(OPT_enable_access_control);
}

if (auto A = Args.getLastArg(OPT_disable_typo_correction,
OPT_typo_correction_limit)) {
if (A->getOption().matches(OPT_disable_typo_correction))
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3146,7 +3146,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
// A decl is safe if formally accessible publicly.
auto accessScope = value->getFormalAccessScope(/*useDC=*/nullptr,
/*treatUsableFromInlineAsPublic=*/true);
if (accessScope.isPublic())
if (accessScope.isPublic() || accessScope.isPackage())
return true;

if (auto accessor = dyn_cast<AccessorDecl>(value))
Expand Down
5 changes: 5 additions & 0 deletions test/Sema/package-only-references.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
// RUN: -package-name MyPackage -I %t \
// RUN: -enable-experimental-feature AccessLevelOnImport

// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -package-name MyPackage -I %t \
// RUN: -enable-deserialization-safety \
// RUN: -enable-experimental-feature AccessLevelOnImport

/// A client outside of the package raises errors.
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -package-name NotMyPackage -I %t \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
// RUN: -disable-deserialization-safety 2>&1 \
// RUN: | %FileCheck --check-prefixes=NEEDED,UNSAFE %s

// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -verify -Xllvm -debug-only=Serialization \
// RUN: -disable-access-control 2>&1 \
// RUN: | %FileCheck --check-prefixes=NEEDED,UNSAFE %s

// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -verify -Xllvm -debug-only=Serialization \
// RUN: -enable-deserialization-safety 2>&1 \
Expand Down