Skip to content

Commit 6da902e

Browse files
committed
Add an option to completely disable SIL verification.
This is useful to disable SIL verification in an assert build of the compiler.
1 parent d73686a commit 6da902e

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

include/swift/AST/SILOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class SILOptions {
7373
/// Controls whether or not paranoid verification checks are run.
7474
bool VerifyAll = false;
7575

76+
/// If true, no SIL verification is done at all.
77+
bool VerifyNone = false;
78+
7679
/// Are we debugging sil serialization.
7780
bool DebugSerialization = false;
7881

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
550550
def sil_verify_all : Flag<["-"], "sil-verify-all">,
551551
HelpText<"Verify SIL after each transform">;
552552

553+
def sil_verify_none : Flag<["-"], "sil-verify-none">,
554+
HelpText<"Completely disable SIL verification">;
555+
553556
def verify_all_substitution_maps : Flag<["-"], "verify-all-substitution-maps">,
554557
HelpText<"Verify all SubstitutionMaps on construction">;
555558

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
984984
Opts.DisableSILPerfOptimizations |= Args.hasArg(OPT_disable_sil_perf_optzns);
985985
Opts.CrossModuleOptimization |= Args.hasArg(OPT_CrossModuleOptimization);
986986
Opts.VerifyAll |= Args.hasArg(OPT_sil_verify_all);
987+
Opts.VerifyNone |= Args.hasArg(OPT_sil_verify_none);
987988
Opts.DebugSerialization |= Args.hasArg(OPT_sil_debug_serialization);
988989
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
989990
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5232,33 +5232,37 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
52325232
// Out of Line Verifier Run Functions
52335233
//===----------------------------------------------------------------------===//
52345234

5235+
static bool verificationEnabled(const SILModule &M) {
5236+
#ifdef NDEBUG
5237+
if (!M.getOptions().VerifyAll)
5238+
return false;
5239+
#endif
5240+
return !M.getOptions().VerifyNone;
5241+
}
5242+
52355243
/// verify - Run the SIL verifier to make sure that the SILFunction follows
52365244
/// invariants.
52375245
void SILFunction::verify(bool SingleFunction) const {
5238-
#ifdef NDEBUG
5239-
if (!getModule().getOptions().VerifyAll)
5246+
if (!verificationEnabled(getModule()))
52405247
return;
5241-
#endif
5248+
52425249
// Please put all checks in visitSILFunction in SILVerifier, not here. This
52435250
// ensures that the pretty stack trace in the verifier is included with the
52445251
// back trace when the verifier crashes.
52455252
SILVerifier(*this, SingleFunction).verify();
52465253
}
52475254

52485255
void SILFunction::verifyCriticalEdges() const {
5249-
#ifdef NDEBUG
5250-
if (!getModule().getOptions().VerifyAll)
5256+
if (!verificationEnabled(getModule()))
52515257
return;
5252-
#endif
5258+
52535259
SILVerifier(*this, /*SingleFunction=*/true).verifyBranches(this);
52545260
}
52555261

52565262
/// Verify that a property descriptor follows invariants.
52575263
void SILProperty::verify(const SILModule &M) const {
5258-
#ifdef NDEBUG
5259-
if (!M.getOptions().VerifyAll)
5264+
if (!verificationEnabled(M))
52605265
return;
5261-
#endif
52625266

52635267
auto *decl = getDecl();
52645268
auto *dc = decl->getInnermostDeclContext();
@@ -5310,10 +5314,9 @@ void SILProperty::verify(const SILModule &M) const {
53105314

53115315
/// Verify that a vtable follows invariants.
53125316
void SILVTable::verify(const SILModule &M) const {
5313-
#ifdef NDEBUG
5314-
if (!M.getOptions().VerifyAll)
5317+
if (!verificationEnabled(M))
53155318
return;
5316-
#endif
5319+
53175320
for (auto &entry : getEntries()) {
53185321
// All vtable entries must be decls in a class context.
53195322
assert(entry.Method.hasDecl() && "vtable entry is not a decl");
@@ -5361,10 +5364,9 @@ void SILVTable::verify(const SILModule &M) const {
53615364

53625365
/// Verify that a witness table follows invariants.
53635366
void SILWitnessTable::verify(const SILModule &M) const {
5364-
#ifdef NDEBUG
5365-
if (!M.getOptions().VerifyAll)
5367+
if (!verificationEnabled(M))
53665368
return;
5367-
#endif
5369+
53685370
if (isDeclaration())
53695371
assert(getEntries().empty() &&
53705372
"A witness table declaration should not have any entries.");
@@ -5414,10 +5416,9 @@ void SILDefaultWitnessTable::verify(const SILModule &M) const {
54145416

54155417
/// Verify that a global variable follows invariants.
54165418
void SILGlobalVariable::verify() const {
5417-
#ifdef NDEBUG
5418-
if (!getModule().getOptions().VerifyAll)
5419+
if (!verificationEnabled(getModule()))
54195420
return;
5420-
#endif
5421+
54215422
assert(getLoweredType().isObject()
54225423
&& "global variable cannot have address type");
54235424

@@ -5439,10 +5440,9 @@ void SILGlobalVariable::verify() const {
54395440

54405441
/// Verify the module.
54415442
void SILModule::verify() const {
5442-
#ifdef NDEBUG
5443-
if (!getOptions().VerifyAll)
5443+
if (!verificationEnabled(*this))
54445444
return;
5445-
#endif
5445+
54465446
// Uniquing set to catch symbol name collisions.
54475447
llvm::DenseSet<StringRef> symbolNames;
54485448

0 commit comments

Comments
 (0)