@@ -127,11 +127,10 @@ InFlightSubstitution::InFlightSubstitution(TypeSubstitutionFn substType,
127127 BaselineLookupConformance(lookupConformance),
128128 Options(options) {
129129
130+ InitLimit = 0 ;
130131 LimitReached = 0 ;
131-
132- // FIXME: Make these configurable
133- RemainingCount = 1000 ;
134- RemainingDepth = 20 ;
132+ RemainingDepth = 0 ;
133+ RemainingCount = 0 ;
135134
136135 // FIXME: Don't substitute type parameters if one of the special flags is set.
137136 Props |= RecursiveTypeProperties::HasTypeParameter;
@@ -240,7 +239,17 @@ Type InFlightSubstitution::projectLaneFromPackType(Type substType,
240239 }
241240}
242241
243- bool InFlightSubstitution::checkLimits () {
242+ // / Note that the type is just used to recover an ASTContext.
243+ bool InFlightSubstitution::checkLimits (Type ty) {
244+ if (!InitLimit) {
245+ auto &ctx = ty->getASTContext ();
246+
247+ InitLimit = 1 ;
248+ RemainingCount = ctx.LangOpts .MaxSubstitutionCount ;
249+ RemainingDepth = ctx.LangOpts .MaxSubstitutionDepth ;
250+ return false ;
251+ }
252+
244253 if (RemainingCount == 0 || RemainingDepth == 0 ) {
245254 LimitReached = true ;
246255 return true ;
@@ -263,7 +272,7 @@ Type InFlightSubstitution::substType(SubstitutableType *origType,
263272 if (shouldSubstituteOpaqueArchetypes () &&
264273 substType->hasOpaqueArchetype () &&
265274 !substType->isEqual (origType)) {
266- if (checkLimits ()) {
275+ if (checkLimits (origType )) {
267276 return ErrorType::get (substType);
268277 }
269278
@@ -304,7 +313,7 @@ InFlightSubstitution::lookupConformance(Type dependentType,
304313 if (shouldSubstituteOpaqueArchetypes () && substConfRef &&
305314 substConfRef.getType ()->hasOpaqueArchetype () &&
306315 !substConfRef.getType ()->isEqual (dependentType)) {
307- if (checkLimits ()) {
316+ if (checkLimits (dependentType )) {
308317 return ProtocolConformanceRef::forInvalid ();
309318 }
310319 --RemainingCount;
0 commit comments