Skip to content

Commit d06b839

Browse files
committed
Add -verify-all-substitution-maps frontend flag
1 parent 23f0d8c commit d06b839

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ namespace swift {
322322
/// `@differentiable` declaration attribute, etc.
323323
bool EnableExperimentalDifferentiableProgramming = false;
324324

325+
/// Enable verification when every SubstitutionMap is constructed.
326+
bool VerifyAllSubstitutionMaps = false;
327+
325328
/// Sets the target we are building for and updates platform conditions
326329
/// to match.
327330
///
@@ -512,6 +515,7 @@ namespace swift {
512515
/// Enable constraint solver support for experimental
513516
/// operator protocol designator feature.
514517
bool SolverEnableOperatorDesignatedTypes = false;
518+
515519
};
516520
} // end namespace swift
517521

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
548548

549549
def sil_verify_all : Flag<["-"], "sil-verify-all">,
550550
HelpText<"Verify SIL after each transform">;
551+
552+
def verify_all_substitution_maps : Flag<["-"], "verify-all-substitution-maps">,
553+
HelpText<"Verify all SubstitutionMaps on construction">;
551554

552555
def sil_debug_serialization : Flag<["-"], "sil-debug-serialization">,
553556
HelpText<"Do not eliminate functions in Mandatory Inlining/SILCombine dead "

lib/AST/SubstitutionMap.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ SubstitutionMap::SubstitutionMap(
5656
GenericSignature genericSig,
5757
ArrayRef<Type> replacementTypes,
5858
ArrayRef<ProtocolConformanceRef> conformances)
59-
: storage(Storage::get(genericSig, replacementTypes, conformances)) { }
59+
: storage(Storage::get(genericSig, replacementTypes, conformances)) {
60+
#ifndef NDEBUG
61+
if (genericSig->getASTContext().LangOpts.VerifyAllSubstitutionMaps)
62+
verify();
63+
#endif
64+
}
6065

6166
ArrayRef<Type> SubstitutionMap::getReplacementTypesBuffer() const {
6267
return storage ? storage->getReplacementTypes() : ArrayRef<Type>();
@@ -476,7 +481,7 @@ SubstitutionMap SubstitutionMap::subst(TypeSubstitutionFn subs,
476481
newConformances.push_back(
477482
conformance.subst(substType, subs, conformances, options));
478483
}
479-
484+
480485
oldConformances = oldConformances.slice(1);
481486
}
482487

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
565565
Target.isOSDarwin());
566566
Opts.EnableSILOpaqueValues |= Args.hasArg(OPT_enable_sil_opaque_values);
567567

568+
Opts.VerifyAllSubstitutionMaps |= Args.hasArg(OPT_verify_all_substitution_maps);
569+
568570
Opts.UseDarwinPreStableABIBit =
569571
(Target.isMacOSX() && Target.isMacOSXVersionLT(10, 14, 4)) ||
570572
(Target.isiOS() && Target.isOSVersionLT(12, 2)) ||
@@ -795,7 +797,7 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
795797
// Assumes exactly one of setMainExecutablePath() or setRuntimeIncludePath()
796798
// is called before setTargetTriple() and parseArgs().
797799
// TODO: improve the handling of RuntimeIncludePath.
798-
800+
799801
return false;
800802
}
801803

0 commit comments

Comments
 (0)