Skip to content

[Serialization] Move deserialization safety behind an env var or flag #63562

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
Feb 10, 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
3 changes: 2 additions & 1 deletion include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ namespace swift {

/// Enable early skipping deserialization of decls that are marked as
/// unsafe to read.
bool EnableDeserializationSafety = true;
bool EnableDeserializationSafety =
::getenv("SWIFT_ENABLE_DESERIALIZATION_SAFETY");

/// Whether to enable the new operator decl and precedencegroup lookup
/// behavior. This is a staging flag, and will be removed in the future.
Expand Down
6 changes: 4 additions & 2 deletions test/Serialization/Safety/override-internal-func.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
// RUN: -emit-module-interface-path %t/Lib.swiftinterface

/// Build against the swiftmodule.
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -enable-deserialization-safety

/// Build against the swiftinterface.
// RUN: rm %t/Lib.swiftmodule
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -enable-deserialization-safety

//--- Lib.swift

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

/// Build client.
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -verify -Xllvm -debug-only=Serialization 2>&1 \
// RUN: -verify -Xllvm -debug-only=Serialization \
// RUN: -enable-deserialization-safety 2>&1 \
// RUN: | %FileCheck --check-prefixes=SAFE %s

/// Decls skips by the deserialization safety logic.
Expand Down
13 changes: 13 additions & 0 deletions test/Serialization/Safety/skip-reading-internal-details.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
// 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 \
// RUN: | %FileCheck --check-prefixes=NEEDED,CLEAN,SAFE %s

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

/// Enable with env var.
// RUN: env SWIFT_ENABLE_DESERIALIZATION_SAFETY=true \
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
// RUN: -verify -Xllvm -debug-only=Serialization 2>&1 \
// RUN: | %FileCheck --check-prefixes=NEEDED,CLEAN,SAFE %s

Expand Down
5 changes: 4 additions & 1 deletion test/Serialization/Safety/unsafe-decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@

// RUN: %target-swift-frontend -emit-module %s \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -enable-deserialization-safety \
// RUN: -Xllvm -debug-only=Serialization 2>&1 | %swift-demangle --simplified \
// RUN: | %FileCheck --check-prefixes=SAFETY-PRIVATE,SAFETY-INTERNAL %s

// RUN: %target-swift-frontend -emit-module %s \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -enable-deserialization-safety \
// RUN: -Xllvm -debug-only=Serialization \
// RUN: -enable-testing 2>&1 \
// RUN: | %FileCheck --check-prefixes=DISABLED %s

/// Don't mark decls as unsafe when private import is enabled.
// RUN: %target-swift-frontend -emit-module %s \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -enable-deserialization-safety \
// RUN: -Xllvm -debug-only=Serialization \
// RUN: -enable-private-imports 2>&1 \
// RUN: | %FileCheck --check-prefixes=DISABLED %s

/// Don't mark decls as unsafe without library evolution.
// RUN: %target-swift-frontend -emit-module %s \
// RUN: -swift-version 5 \
// RUN: -enable-deserialization-safety -swift-version 5 \
// RUN: -Xllvm -debug-only=Serialization 2>&1 \
// RUN: | %FileCheck --check-prefixes=DISABLED %s

Expand Down
5 changes: 4 additions & 1 deletion test/Serialization/Safety/unsafe-extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@

// RUN: %target-swift-frontend -emit-module %s \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -enable-deserialization-safety \
// RUN: -Xllvm -debug-only=Serialization 2>&1 \
// RUN: | %FileCheck --check-prefixes=SAFETY-PRIVATE,SAFETY-INTERNAL %s

// RUN: %target-swift-frontend -emit-module %s \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -enable-deserialization-safety \
// RUN: -Xllvm -debug-only=Serialization \
// RUN: -enable-testing 2>&1 \
// RUN: | %FileCheck --check-prefixes=DISABLED %s

/// Don't mark decls as unsafe when private import is enabled.
// RUN: %target-swift-frontend -emit-module %s \
// RUN: -enable-library-evolution -swift-version 5 \
// RUN: -enable-deserialization-safety \
// RUN: -Xllvm -debug-only=Serialization \
// RUN: -enable-private-imports 2>&1 \
// RUN: | %FileCheck --check-prefixes=DISABLED %s

/// Don't mark decls as unsafe without library evolution.
// RUN: %target-swift-frontend -emit-module %s \
// RUN: -swift-version 5 \
// RUN: -enable-deserialization-safety -swift-version 5 \
// RUN: -Xllvm -debug-only=Serialization 2>&1 \
// RUN: | %FileCheck --check-prefixes=DISABLED %s

Expand Down