[PATCH] D20550: Linker: error_code'ify the IR mover. NFC.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue May 24 13:17:42 PDT 2016


lhames added a comment.

Following on from the discussion on http://reviews.llvm.org/D20592 (I might write up a blog post on this soon, but this is the quick version):

While developing Error I tried transitioning MachOObjectFile to use the new type and quickly ran into a problem: The libObject API had a lot of clients, and those clients all used std::error_code. Trying to fix all the clients resulted in an impractically large patch, and I realized that other people making the switch would run into the same problem. For that reason I decided that during this transition period the best thing to do was require Error and error_code be convertible from one another (same with Expected and ErrorOr). This allows us to change APIs very surgically, right down to changes in individual variables / functions, by just wrapping the types with the conversion operators when used. That's great for incrementally moving over from std::error_code to Error, but leaves us with this wart: For now every Error needs to be convertible into an equivalent error_code. Often that means that the easiest way to transition an API to Error is to introduce a new std::error_category (as you've done), update the API to return Error, and then construct your error values using:

  errorCodeToError(<insert error code here>);

After you've updated the API you can start selectively adding custom error classes and mapping them to errors in your category. Eventually, once everyone is moved over, we can remove the error category and just deal with the custom error type.


http://reviews.llvm.org/D20550





More information about the llvm-commits mailing list