From 209463be223ea946326cc88cc3c4e5281c80b613 Mon Sep 17 00:00:00 2001 From: rudy Date: Fri, 19 Nov 2021 10:34:44 +0100 Subject: [PATCH] chore(Lambda): simplify and extract null parameter detection --- compiler/lib/Support/Jit.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/compiler/lib/Support/Jit.cpp b/compiler/lib/Support/Jit.cpp index 0d810383a..02ea96a6e 100644 --- a/compiler/lib/Support/Jit.cpp +++ b/compiler/lib/Support/Jit.cpp @@ -54,11 +54,23 @@ JITLambda::create(llvm::StringRef name, mlir::ModuleOp &module, return std::move(lambda); } +llvm::Error hasSomeNull(llvm::MutableArrayRef args) { + auto pos = 0; + for (auto arg : args) { + if (arg == nullptr) { + auto msg = + "invoke: argument at pos " + llvm::Twine(pos) + " is null or missing"; + return llvm::make_error( + msg, llvm::inconvertibleErrorCode()); + } + pos++; + } + return llvm::Error::success(); +} + llvm::Error JITLambda::invokeRaw(llvm::MutableArrayRef args) { - if (!args.empty() && llvm::find(args, nullptr) != args.end()) { - return llvm::make_error( - "invoke: some arguments are null or missing", - llvm::inconvertibleErrorCode()); + if (auto hasSomeNullError = hasSomeNull(args)) { + return hasSomeNullError; } return this->engine->invokePacked(this->name, args); }