                 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)
-                }
+                deleteCandidates(instr.inputs)
             }
         }
 

    /// Returns the indices of the start of the inlineable functions.
    private func identifyInlineableFunctions(in code: Code) -> [Int] {
        var candidates = [Variable: (callCount: Int, index: Int)]()
        // Contains the output variable of all active subroutine definitions. As some subroutines don't have outputs (e.g. class methods), entries can also be nil.
        var activeSubroutineDefinitions = [Variable?]()
        for instr in code {
            switch instr.op {
                // Currently we only inline plain functions as that guarantees that the resulting code is always valid.

                }

                // Can't inline functions that are passed as arguments to other functions.
                deleteCandidates(instr.inputs.dropFirst())
            case is LoadArguments:
                // Can't inline functions if they access their arguments.
                if let function = activeSubroutineDefinitions.last! {
