mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/main' into rebranch
This commit is contained in:
@@ -336,10 +336,6 @@ set(SWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS "2.0" CACHE STRING
|
|||||||
# User-configurable debugging options.
|
# User-configurable debugging options.
|
||||||
#
|
#
|
||||||
|
|
||||||
option(SWIFT_AST_VERIFIER
|
|
||||||
"Enable the AST verifier in the built compiler, and run it on every compilation"
|
|
||||||
TRUE)
|
|
||||||
|
|
||||||
option(SWIFT_SIL_VERIFY_ALL
|
option(SWIFT_SIL_VERIFY_ALL
|
||||||
"Run SIL verification after each transform when building Swift files in the build process"
|
"Run SIL verification after each transform when building Swift files in the build process"
|
||||||
FALSE)
|
FALSE)
|
||||||
|
|||||||
@@ -367,6 +367,20 @@ namespace swift {
|
|||||||
// FrontendOptions.
|
// FrontendOptions.
|
||||||
bool AllowModuleWithCompilerErrors = false;
|
bool AllowModuleWithCompilerErrors = false;
|
||||||
|
|
||||||
|
/// A helper enum to represent whether or not we customized the default
|
||||||
|
/// ASTVerifier behavior via a frontend flag. By default, we do not
|
||||||
|
/// customize.
|
||||||
|
///
|
||||||
|
/// NOTE: The default behavior is to run the ASTVerifier only when asserts
|
||||||
|
/// are enabled. This just allows for one to customize that behavior.
|
||||||
|
enum class ASTVerifierOverrideKind {
|
||||||
|
NoOverride = 0,
|
||||||
|
EnableVerifier = 1,
|
||||||
|
DisableVerifier = 2,
|
||||||
|
};
|
||||||
|
ASTVerifierOverrideKind ASTVerifierOverride =
|
||||||
|
ASTVerifierOverrideKind::NoOverride;
|
||||||
|
|
||||||
/// Sets the target we are building for and updates platform conditions
|
/// Sets the target we are building for and updates platform conditions
|
||||||
/// to match.
|
/// to match.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -769,4 +769,20 @@ def bad_file_descriptor_retry_count:
|
|||||||
Separate<["-"], "bad-file-descriptor-retry-count">,
|
Separate<["-"], "bad-file-descriptor-retry-count">,
|
||||||
HelpText<"Number of retrying opening a file if previous open returns a bad "
|
HelpText<"Number of retrying opening a file if previous open returns a bad "
|
||||||
"file descriptor error.">;
|
"file descriptor error.">;
|
||||||
|
|
||||||
|
def enable_ast_verifier : Flag<["-"], "enable-ast-verifier">,
|
||||||
|
HelpText<"Run the AST verifier during compilation. NOTE: This lets the user "
|
||||||
|
"override the default behavior on whether or not the ASTVerifier "
|
||||||
|
"is run. The default behavior is to run the verifier when asserts "
|
||||||
|
"are enabled and not run it when asserts are disabled. NOTE: "
|
||||||
|
"Can not be used if disable-ast-verifier is used as well">;
|
||||||
|
|
||||||
|
def disable_ast_verifier : Flag<["-"], "disable-ast-verifier">,
|
||||||
|
HelpText<"Do not run the AST verifier during compilation. NOTE: This lets "
|
||||||
|
"the user override the default behavior on whether or not the "
|
||||||
|
"ASTVerifier is run. The default behavior is to run the verifier "
|
||||||
|
"when asserts are enabled and not run it when asserts are "
|
||||||
|
"disabled. NOTE: Can not be used if enable-ast-verifier is used "
|
||||||
|
"as well">;
|
||||||
|
|
||||||
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]
|
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]
|
||||||
|
|||||||
@@ -3686,15 +3686,36 @@ public:
|
|||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
static bool shouldVerifyGivenContext(const ASTContext &ctx) {
|
||||||
|
using ASTVerifierOverrideKind = LangOptions::ASTVerifierOverrideKind;
|
||||||
|
switch (ctx.LangOpts.ASTVerifierOverride) {
|
||||||
|
case ASTVerifierOverrideKind::EnableVerifier:
|
||||||
|
return true;
|
||||||
|
case ASTVerifierOverrideKind::DisableVerifier:
|
||||||
|
return false;
|
||||||
|
case ASTVerifierOverrideKind::NoOverride:
|
||||||
|
#ifndef NDEBUG
|
||||||
|
// asserts. Default behavior is to run.
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
// no-asserts. Default behavior is not to run the verifier.
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
llvm_unreachable("Covered switch isn't covered?!");
|
||||||
|
}
|
||||||
|
|
||||||
void swift::verify(SourceFile &SF) {
|
void swift::verify(SourceFile &SF) {
|
||||||
#if !(defined(NDEBUG) || defined(SWIFT_DISABLE_AST_VERIFIER))
|
if (!shouldVerifyGivenContext(SF.getASTContext()))
|
||||||
|
return;
|
||||||
Verifier verifier(SF, &SF);
|
Verifier verifier(SF, &SF);
|
||||||
SF.walk(verifier);
|
SF.walk(verifier);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool swift::shouldVerify(const Decl *D, const ASTContext &Context) {
|
bool swift::shouldVerify(const Decl *D, const ASTContext &Context) {
|
||||||
#if !(defined(NDEBUG) || defined(SWIFT_DISABLE_AST_VERIFIER))
|
if (!shouldVerifyGivenContext(Context))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (const auto *ED = dyn_cast<ExtensionDecl>(D)) {
|
if (const auto *ED = dyn_cast<ExtensionDecl>(D)) {
|
||||||
return shouldVerify(ED->getExtendedNominal(), Context);
|
return shouldVerify(ED->getExtendedNominal(), Context);
|
||||||
}
|
}
|
||||||
@@ -3706,15 +3727,13 @@ bool swift::shouldVerify(const Decl *D, const ASTContext &Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void swift::verify(Decl *D) {
|
void swift::verify(Decl *D) {
|
||||||
#if !(defined(NDEBUG) || defined(SWIFT_DISABLE_AST_VERIFIER))
|
if (!shouldVerifyGivenContext(D->getASTContext()))
|
||||||
|
return;
|
||||||
|
|
||||||
Verifier V = Verifier::forDecl(D);
|
Verifier V = Verifier::forDecl(D);
|
||||||
D->walk(V);
|
D->walk(V);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,14 +144,3 @@ endif()
|
|||||||
# headers.
|
# headers.
|
||||||
# For more information see the comment at the top of lib/CMakeLists.txt.
|
# For more information see the comment at the top of lib/CMakeLists.txt.
|
||||||
add_dependencies(swiftAST intrinsics_gen clang-tablegen-targets)
|
add_dependencies(swiftAST intrinsics_gen clang-tablegen-targets)
|
||||||
|
|
||||||
set(swift_ast_verifier_flag)
|
|
||||||
if(SWIFT_AST_VERIFIER)
|
|
||||||
set(swift_ast_verifier_flag " -USWIFT_DISABLE_AST_VERIFIER")
|
|
||||||
else()
|
|
||||||
set(swift_ast_verifier_flag " -DSWIFT_DISABLE_AST_VERIFIER=1")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set_property(SOURCE ASTVerifier.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
|
|
||||||
"${swift_ast_verifier_flag}")
|
|
||||||
|
|
||||||
|
|||||||
@@ -689,6 +689,21 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
|||||||
Opts.AllowModuleWithCompilerErrors = true;
|
Opts.AllowModuleWithCompilerErrors = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto A =
|
||||||
|
Args.getLastArg(OPT_enable_ast_verifier, OPT_disable_ast_verifier)) {
|
||||||
|
using ASTVerifierOverrideKind = LangOptions::ASTVerifierOverrideKind;
|
||||||
|
if (A->getOption().matches(OPT_enable_ast_verifier)) {
|
||||||
|
Opts.ASTVerifierOverride = ASTVerifierOverrideKind::EnableVerifier;
|
||||||
|
} else if (A->getOption().matches(OPT_disable_ast_verifier)) {
|
||||||
|
Opts.ASTVerifierOverride = ASTVerifierOverrideKind::DisableVerifier;
|
||||||
|
} else {
|
||||||
|
// This is an assert since getLastArg should not have let us get here if
|
||||||
|
// we did not have one of enable/disable specified.
|
||||||
|
llvm_unreachable(
|
||||||
|
"Should have found one of enable/disable ast verifier?!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return HadError || UnsupportedOS || UnsupportedArch;
|
return HadError || UnsupportedOS || UnsupportedArch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,6 +167,9 @@ void SILModule::checkForLeaks() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SILModule::checkForLeaksAfterDestruction() {
|
void SILModule::checkForLeaksAfterDestruction() {
|
||||||
|
// Disabled in release (non-assert) builds because this check fails in rare
|
||||||
|
// cases in lldb, causing crashes. rdar://70826934
|
||||||
|
#ifndef NDEBUG
|
||||||
int numAllocated = SILInstruction::getNumCreatedInstructions() -
|
int numAllocated = SILInstruction::getNumCreatedInstructions() -
|
||||||
SILInstruction::getNumDeletedInstructions();
|
SILInstruction::getNumDeletedInstructions();
|
||||||
|
|
||||||
@@ -174,6 +177,7 @@ void SILModule::checkForLeaksAfterDestruction() {
|
|||||||
llvm::errs() << "Leaking " << numAllocated << " instructions!\n";
|
llvm::errs() << "Leaking " << numAllocated << " instructions!\n";
|
||||||
llvm_unreachable("leaking instructions");
|
llvm_unreachable("leaking instructions");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SILModule> SILModule::createEmptyModule(
|
std::unique_ptr<SILModule> SILModule::createEmptyModule(
|
||||||
|
|||||||
@@ -83,9 +83,6 @@ if "@SWIFT_STDLIB_ASSERTIONS@" == "TRUE":
|
|||||||
else:
|
else:
|
||||||
config.available_features.add('swift_stdlib_no_asserts')
|
config.available_features.add('swift_stdlib_no_asserts')
|
||||||
|
|
||||||
if "@SWIFT_AST_VERIFIER@" == "TRUE":
|
|
||||||
config.available_features.add('swift_ast_verifier')
|
|
||||||
|
|
||||||
if "@SWIFT_OPTIMIZED@" == "TRUE":
|
if "@SWIFT_OPTIMIZED@" == "TRUE":
|
||||||
config.available_features.add("optimized_stdlib")
|
config.available_features.add("optimized_stdlib")
|
||||||
|
|
||||||
|
|||||||
@@ -116,11 +116,11 @@ EnableSpeculativeDevirtualization("enable-spec-devirt",
|
|||||||
llvm::cl::desc("Enable Speculative Devirtualization pass."));
|
llvm::cl::desc("Enable Speculative Devirtualization pass."));
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
enum EnforceExclusivityMode {
|
enum class EnforceExclusivityMode {
|
||||||
Unchecked, // static only
|
Unchecked, // static only
|
||||||
Checked, // static and dynamic
|
Checked, // static and dynamic
|
||||||
DynamicOnly,
|
DynamicOnly,
|
||||||
None
|
None,
|
||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
@@ -203,6 +203,16 @@ SILVerifyNone("sil-verify-none",
|
|||||||
llvm::cl::init(false),
|
llvm::cl::init(false),
|
||||||
llvm::cl::desc("Completely disable SIL verification"));
|
llvm::cl::desc("Completely disable SIL verification"));
|
||||||
|
|
||||||
|
/// Customize the default behavior
|
||||||
|
static llvm::cl::opt<bool> EnableASTVerifier(
|
||||||
|
"enable-ast-verifier", llvm::cl::Hidden, llvm::cl::init(false),
|
||||||
|
llvm::cl::desc("Override the default behavior and Enable the ASTVerifier"));
|
||||||
|
|
||||||
|
static llvm::cl::opt<bool> DisableASTVerifier(
|
||||||
|
"disable-ast-verifier", llvm::cl::Hidden, llvm::cl::init(false),
|
||||||
|
llvm::cl::desc(
|
||||||
|
"Override the default behavior and force disable the ASTVerifier"));
|
||||||
|
|
||||||
static llvm::cl::opt<bool>
|
static llvm::cl::opt<bool>
|
||||||
RemoveRuntimeAsserts("remove-runtime-asserts",
|
RemoveRuntimeAsserts("remove-runtime-asserts",
|
||||||
llvm::cl::Hidden,
|
llvm::cl::Hidden,
|
||||||
@@ -310,6 +320,22 @@ static void runCommandLineSelectedPasses(SILModule *Module,
|
|||||||
Module->verify();
|
Module->verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
using ASTVerifierOverrideKind = LangOptions::ASTVerifierOverrideKind;
|
||||||
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
static Optional<ASTVerifierOverrideKind> getASTOverrideKind() {
|
||||||
|
assert(!(EnableASTVerifier && DisableASTVerifier) &&
|
||||||
|
"Can only set one of EnableASTVerifier/DisableASTVerifier?!");
|
||||||
|
if (EnableASTVerifier)
|
||||||
|
return ASTVerifierOverrideKind::EnableVerifier;
|
||||||
|
|
||||||
|
if (DisableASTVerifier)
|
||||||
|
return ASTVerifierOverrideKind::DisableVerifier;
|
||||||
|
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
// This function isn't referenced outside its translation unit, but it
|
// This function isn't referenced outside its translation unit, but it
|
||||||
// can't use the "static" keyword because its address is used for
|
// can't use the "static" keyword because its address is used for
|
||||||
// getMainExecutable (since some platforms don't support taking the
|
// getMainExecutable (since some platforms don't support taking the
|
||||||
@@ -362,7 +388,9 @@ int main(int argc, char **argv) {
|
|||||||
Invocation.getLangOptions().DisableAvailabilityChecking = true;
|
Invocation.getLangOptions().DisableAvailabilityChecking = true;
|
||||||
Invocation.getLangOptions().EnableAccessControl = false;
|
Invocation.getLangOptions().EnableAccessControl = false;
|
||||||
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
|
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
|
||||||
|
if (auto overrideKind = getASTOverrideKind()) {
|
||||||
|
Invocation.getLangOptions().ASTVerifierOverride = *overrideKind;
|
||||||
|
}
|
||||||
Invocation.getLangOptions().EnableExperimentalConcurrency =
|
Invocation.getLangOptions().EnableExperimentalConcurrency =
|
||||||
EnableExperimentalConcurrency;
|
EnableExperimentalConcurrency;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
// RUN: not %target-sil-opt %s
|
// RUN: not %target-sil-opt -enable-ast-verifier %s
|
||||||
// REQUIRES: swift_ast_verifier
|
|
||||||
import Swift func g(@opened(Any
|
import Swift func g(@opened(Any
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
// See https://swift.org/LICENSE.txt for license information
|
// See https://swift.org/LICENSE.txt for license information
|
||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
|
|
||||||
// RUN: not %target-swift-frontend %s -emit-ir
|
// RUN: not %target-swift-frontend -enable-ast-verifier %s -emit-ir
|
||||||
// REQUIRES: swift_ast_verifier
|
|
||||||
|
|
||||||
switch{case.b(u){
|
switch{case.b(u){
|
||||||
|
|||||||
Reference in New Issue
Block a user