@@ -3862,6 +3862,19 @@ TypeConverter::getConstantAbstractionPattern(SILDeclRef constant) {
38623862 return None;
38633863}
38643864
3865+ TypeExpansionContext
3866+ TypeConverter::getCaptureTypeExpansionContext (SILDeclRef constant) {
3867+ auto found = CaptureTypeExpansionContexts.find (constant);
3868+ if (found != CaptureTypeExpansionContexts.end ()) {
3869+ return found->second ;
3870+ }
3871+ // Insert a minimal type expansion context into the cache, so that further
3872+ // attempts to change it raise an error.
3873+ auto minimal = TypeExpansionContext::minimal ();
3874+ CaptureTypeExpansionContexts.insert ({constant, minimal});
3875+ return minimal;
3876+ }
3877+
38653878void TypeConverter::setAbstractionPattern (AbstractClosureExpr *closure,
38663879 AbstractionPattern pattern) {
38673880 auto existing = ClosureAbstractionPatterns.find (closure);
@@ -3873,6 +3886,31 @@ void TypeConverter::setAbstractionPattern(AbstractClosureExpr *closure,
38733886 }
38743887}
38753888
3889+ void TypeConverter::setCaptureTypeExpansionContext (SILDeclRef constant,
3890+ SILModule &M) {
3891+ if (!hasLoweredLocalCaptures (constant)) {
3892+ return ;
3893+ }
3894+
3895+ TypeExpansionContext context = constant.isSerialized ()
3896+ ? TypeExpansionContext::minimal ()
3897+ : TypeExpansionContext::maximal (constant.getAnyFunctionRef ()->getAsDeclContext (),
3898+ M.isWholeModule ());
3899+
3900+ auto existing = CaptureTypeExpansionContexts.find (constant);
3901+ if (existing != CaptureTypeExpansionContexts.end ()) {
3902+ assert (existing->second == context
3903+ && " closure shouldn't be emitted with different capture type expansion contexts" );
3904+ } else {
3905+ // Lower in the context of the closure. Since the set of captures is a
3906+ // private contract between the closure and its enclosing context, we
3907+ // don't need to keep its capture types opaque.
3908+ // The exception is if it's inlinable, in which case it might get inlined into
3909+ // some place we need to keep opaque types opaque.
3910+ CaptureTypeExpansionContexts.insert ({constant, context});
3911+ }
3912+ }
3913+
38763914static void countNumberOfInnerFields (unsigned &fieldsCount, TypeConverter &TC,
38773915 SILType Ty,
38783916 TypeExpansionContext expansion) {
0 commit comments