diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 58d3fdc8743..249a227bb7e 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -322,6 +322,9 @@ namespace swift { /// `@differentiable` declaration attribute, etc. bool EnableExperimentalDifferentiableProgramming = false; + /// Enable verification when every SubstitutionMap is constructed. + bool VerifyAllSubstitutionMaps = false; + /// Sets the target we are building for and updates platform conditions /// to match. /// @@ -512,6 +515,7 @@ namespace swift { /// Enable constraint solver support for experimental /// operator protocol designator feature. bool SolverEnableOperatorDesignatedTypes = false; + }; } // end namespace swift diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index b18dfb561dd..74c9385047e 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -548,6 +548,9 @@ def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">, def sil_verify_all : Flag<["-"], "sil-verify-all">, HelpText<"Verify SIL after each transform">; + +def verify_all_substitution_maps : Flag<["-"], "verify-all-substitution-maps">, + HelpText<"Verify all SubstitutionMaps on construction">; def sil_debug_serialization : Flag<["-"], "sil-debug-serialization">, HelpText<"Do not eliminate functions in Mandatory Inlining/SILCombine dead " diff --git a/lib/AST/SubstitutionMap.cpp b/lib/AST/SubstitutionMap.cpp index 0ecde91a8c4..026111141f8 100644 --- a/lib/AST/SubstitutionMap.cpp +++ b/lib/AST/SubstitutionMap.cpp @@ -56,7 +56,12 @@ SubstitutionMap::SubstitutionMap( GenericSignature genericSig, ArrayRef replacementTypes, ArrayRef conformances) - : storage(Storage::get(genericSig, replacementTypes, conformances)) { } + : storage(Storage::get(genericSig, replacementTypes, conformances)) { +#ifndef NDEBUG + if (genericSig->getASTContext().LangOpts.VerifyAllSubstitutionMaps) + verify(); +#endif +} ArrayRef SubstitutionMap::getReplacementTypesBuffer() const { return storage ? storage->getReplacementTypes() : ArrayRef(); @@ -476,7 +481,7 @@ SubstitutionMap SubstitutionMap::subst(TypeSubstitutionFn subs, newConformances.push_back( conformance.subst(substType, subs, conformances, options)); } - + oldConformances = oldConformances.slice(1); } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 3ea35141fb5..12db9b35232 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -565,6 +565,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args, Target.isOSDarwin()); Opts.EnableSILOpaqueValues |= Args.hasArg(OPT_enable_sil_opaque_values); + Opts.VerifyAllSubstitutionMaps |= Args.hasArg(OPT_verify_all_substitution_maps); + Opts.UseDarwinPreStableABIBit = (Target.isMacOSX() && Target.isMacOSXVersionLT(10, 14, 4)) || (Target.isiOS() && Target.isOSVersionLT(12, 2)) || @@ -795,7 +797,7 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, // Assumes exactly one of setMainExecutablePath() or setRuntimeIncludePath() // is called before setTargetTriple() and parseArgs(). // TODO: improve the handling of RuntimeIncludePath. - + return false; }