       // Note that arguments are captured by reference in the current frame.
       locals.top![node.symbol!] = builder.buildPartialApply(
         function: fn,
-        arguments: node.captures
-          .sorted(by: { a, b in a.name < b.name })
-          .map({ locals.top![$0]! }),
+        arguments: node.captures.map { locals.top![$0]! },
         type: fnTy)
     }
 

      // Restore the insertion point.
      builder.currentBlock = previousBlock
      locals.pop()

      // FIXME: Handle closures.
      // The idea would be to assign they symbol in the local regster mapping with a partial
      // application that embeds the closure, pretty much the same way SIL does.
    }

    // NOTE: Generic functions are represented unspecialized in AIR, so that borrow checking can be

  public func visit(_ node: FunDecl) throws {
    // Get the type of the declared function.
    var fnTy = builder.unit.getFunctionType(of: node.type! as! FunctionType)

    // Constructors and methods shall not have closures.
    assert(
      node.captures.isEmpty || (node.kind != .constructor && node.kind != .method),
      "constructor and methods shall not have closures")

    if node.symbol!.isMethod {
      // Methods (and destructors?) are static functions that take the self symbol and return the
      // "actual" method as a closure.
      let symbols = node.innerScope!.symbols["self"]!
      assert(symbols.count == 1)
      let methTy = fnTy.codomain as! AIRFunctionType
      fnTy = builder.unit.getFunctionType(
        from: [builder.unit.getType(of: symbols[0].type!)] + methTy.domain,
        to: methTy.codomain)
    } else if !node.captures.isEmpty {
      // If the function captures symbols, we need to emit a context-free version of the it, which
      // gets the captured values as parameters. This boils down to extending the domain.
      let additional = node.captures.map { builder.unit.getType(of: $0.type!) }
      fnTy = builder.unit.getFunctionType(from: additional + fnTy.domain, to: fnTy.codomain)
    }

