                 }
 
                 // Can't inline functions that are passed as arguments to other functions.
-                for v in instr.inputs.dropFirst() {
-                    candidates.removeValue(forKey: v)
-                }
+                deleteCandidates(instr.inputs.dropFirst())
             case is LoadArguments:
                 // Can't inline functions if they access their arguments.
                 if let function = activeSubroutineDefinitions.last! {

                Assert(instr.op is Return || !(instr.op.requiredContext.contains(.subroutine)))

                // Can't inline functions that are used as inputs for other instructions.
                for v in instr.inputs {
                    candidates.removeValue(forKey: v)
                }
            }
        }


                // TODO remove this special handling (and the asserts) once class constructors and methods are also subroutines
                Assert(!(instr.op is BeginAnySubroutine))
                activeSubroutineDefinitions.append(nil)
                // Currently needed as BeginClass can have inputs. Refactor this when refactoring classes.
                deleteCandidates(instr.inputs)
            case is BeginMethod:
                Assert(!(instr.op is BeginAnySubroutine))
                // This closes a subroutine and starts a new one, so is effectively a nop.
