@@ -228,31 +228,32 @@ public static SimplifiedOpInfo simplifyInfo(OpEnvironment env, OpInfo info) {
228228 ) {
229229 int ioIndex = SimplificationUtils .findMutableArgIndex (Types .raw (info
230230 .opType ()));
231- // If IO index is -1, output is returned - no need to copy.
232- if (ioIndex == -1 ) {
233- return null ;
231+ if (ioIndex > -1 && !(isIdentity (inFocusers .get (ioIndex )) && isIdentity (outSimplifier ))) {
232+ // Otherwise, we need an Op to convert the simple output back into the
233+ // pre-focused input
234+ // Determine simple output type.
235+ var simpleOut = outType (info .outputType (), outSimplifier );
236+ // Determine unfocused input type.
237+ var focuserInfo = Ops .info (inFocusers .get (ioIndex ));
238+ Map <TypeVariable <?>, Type > typeAssigns = new HashMap <>();
239+ GenericAssignability .inferTypeVariables ( //
240+ new Type [] { focuserInfo .outputType () }, //
241+ new Type [] { info .inputTypes ().get (ioIndex ) }, //
242+ typeAssigns //
243+ );
244+ var unfocusedInput = Nil .of (Types .mapVarToTypes ( //
245+ focuserInfo .inputTypes ().get (0 ), //
246+ typeAssigns //
247+ ));
248+ // Match a copier
249+ return Ops .rich (env .unary ("engine.copy" , h ) //
250+ .inType (simpleOut ) //
251+ .outType (unfocusedInput ) //
252+ .computer ());
234253 }
235- // Otherwise, we need an Op to convert the simple output back into the
236- // pre-focused input
237- // Determine simple output type.
238- var simpleOut = outType (info .outputType (), outSimplifier );
239- // Determine unfocused input type.
240- var focuserInfo = Ops .info (inFocusers .get (ioIndex ));
241- Map <TypeVariable <?>, Type > typeAssigns = new HashMap <>();
242- GenericAssignability .inferTypeVariables ( //
243- new Type [] { focuserInfo .outputType () }, //
244- new Type [] { info .inputTypes ().get (ioIndex ) }, //
245- typeAssigns //
246- );
247- var unfocusedInput = Nil .of (Types .mapVarToTypes ( //
248- focuserInfo .inputTypes ().get (0 ), //
249- typeAssigns //
250- ));
251- // Match a copier
252- return Ops .rich (env .unary ("engine.copy" , h ) //
253- .inType (simpleOut ) //
254- .outType (unfocusedInput ) //
255- .computer ());
254+ // No mutable parameter and/or pathway is an identity pathway, so no copy
255+ // op necessary
256+ return null ;
256257 }
257258
258259 /**
0 commit comments