This is an archive of the discontinued LLVM Phabricator instance.

[IRLinker] make IRLinker::AddLazyFor optional (llvm::unique_function). NFC
ClosedPublic

Authored by nickdesaulniers on Mar 14 2022, 11:27 AM.

Details

Summary

2 of the 3 callsite of IRMover::move() pass empty lambda functions. Just
make this parameter llvm::unique_function.

Came about via discussion in D120781. Probably worth making this change
regardless of the resolution of D120781.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2022, 11:27 AM
nickdesaulniers requested review of this revision.Mar 14 2022, 11:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2022, 11:27 AM
dexonsmith accepted this revision.Mar 14 2022, 1:26 PM

LGTM. I have a slight preference for llvm::unique_function<> instead of Optional<std::function<>>, but if you have a reason to prefer what's in the patch that's fine with me.

llvm/include/llvm/Linker/IRMover.h
79–80

What about using llvm::unique_function instead? You can pass nullptr to this parameter. You'd want document here in the API that nullptr was an acceptable input.

(Not sure on tradeoffs between unique_function<> and Optional<function<>>... I have the general impression that unique_function is a bit nicer since it can take move-only function objects.)

This revision is now accepted and ready to land.Mar 14 2022, 1:26 PM
nickdesaulniers marked an inline comment as done.
nickdesaulniers retitled this revision from [IRLinker] make IRLinker::AddLazyFor Optional. NFC to [IRLinker] make IRLinker::AddLazyFor optional (llvm::unique_function). NFC.
nickdesaulniers edited the summary of this revision. (Show Details)
  • prefer llvm::unique_function over llvm::Optional<std::function<>>

LGTM. I have a slight preference for llvm::unique_function<> instead of Optional<std::function<>>, but if you have a reason to prefer what's in the patch that's fine with me.

TIL; was using llvm::Optional out of naivete of llvm::unique_function. Thanks for the recommendation.

This revision was landed with ongoing or failed builds.Mar 14 2022, 2:38 PM
This revision was automatically updated to reflect the committed changes.