@@ -3171,6 +3171,7 @@ namespace {
3171
3171
SILParameterInfo param) {
3172
3172
// If we're bridging a concrete type to `id` via Any, skip the Any
3173
3173
// boxing.
3174
+
3174
3175
// TODO: Generalize. Similarly, when bridging from NSFoo -> Foo -> NSFoo,
3175
3176
// we should elide the bridge altogether and pass the original object.
3176
3177
auto paramObjTy = param.getType ();
@@ -3186,9 +3187,8 @@ namespace {
3186
3187
origParamType, param);
3187
3188
3188
3189
return SGF.emitNativeToBridgedValue (emitted.loc ,
3189
- std::move (emitted.value ).getScalarValue (),
3190
- Rep, param.getType ());
3191
-
3190
+ std::move (emitted.value ).getAsSingleValue (SGF, emitted.loc ),
3191
+ Rep, param.getType ());
3192
3192
}
3193
3193
3194
3194
enum class ExistentialPeepholeOptionality {
@@ -3277,15 +3277,24 @@ namespace {
3277
3277
AbstractionPattern origParamType,
3278
3278
SILParameterInfo param) {
3279
3279
auto origArgExpr = argExpr;
3280
- (void ) origArgExpr;
3281
3280
// Look through existential erasures.
3282
3281
ExistentialPeepholeOptionality optionality;
3283
3282
std::tie (argExpr, optionality) = lookThroughExistentialErasures (argExpr);
3284
3283
3284
+ // TODO: Only do the peephole for trivially-lowered types, since we
3285
+ // unfortunately don't plumb formal types through
3286
+ // emitNativeToBridgedValue, so can't correctly construct the
3287
+ // substitution for the call to _bridgeAnythingToObjectiveC for function
3288
+ // or metatype values.
3289
+ if (!argExpr->getType ()->isLegalSILType ()) {
3290
+ argExpr = origArgExpr;
3291
+ optionality = ExistentialPeepholeOptionality::Nonoptional;
3292
+ }
3293
+
3285
3294
// Emit the argument.
3286
3295
auto contexts = getRValueEmissionContexts (loweredSubstArgType, param);
3287
3296
ManagedValue emittedArg = SGF.emitRValue (argExpr, contexts.ForEmission )
3288
- .getScalarValue ( );
3297
+ .getAsSingleValue (SGF, argExpr );
3289
3298
3290
3299
// Early exit if we already exactly match the parameter type.
3291
3300
if (emittedArg.getType () == param.getSILType ()) {
0 commit comments