<div dir="ltr">I suppose, but I'm not sure ErrorAnd captures the intended meaning very well.  In any case, that's not super important at this stage since this isn't on the immediate horizon.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, May 1, 2017 at 5:43 PM Lang Hames <<a href="mailto:lhames@gmail.com">lhames@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Zachary,<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">... Then instead of Expected<T> you could have WithDiagnostics<T> that enforces the proper semantics.</blockquote><div><br></div><div>You mean something like an ErrorAnd<T>? Chris Bieneman floated that idea for some libObject code but we haven't got around to implementing it. If it were generically useful we could do something like that.</div><div><br></div><div>Cheers,</div><div>Lang.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 1, 2017 at 5:36 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Is there any chance of introducing something like make_status<T>() into llvm/Error.h, that constructs the llvm::Error in such a way that it still interoperates nicely with everything else?  Then instead of Expected<T> you could have WithDiagnostics<T> that enforces the proper semantics.</div><div class="m_-2013066891587853428HOEnZb"><div class="m_-2013066891587853428h5"><br><div class="gmail_quote"><div dir="ltr">On Mon, May 1, 2017 at 5:33 PM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, May 1, 2017 at 5:27 PM Jim Ingham <<a href="mailto:jingham@apple.com" target="_blank">jingham@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On May 1, 2017, at 4:52 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
><br>
> Yea, grouping the error and the result together is one of the most compelling features of it.  It's called Expected<T>, so where we would currently write something like:<br>
><br>
> int getNumberOfSymbols(Error &Err) {}<br>
><br>
> or<br>
><br>
> Error getNumberOfSymbols(int &Count) {}<br>
><br>
> You would now write:<br>
><br>
> Expected<int> getNumberOfSymbols() {<br>
>    if (foo) return 1;<br>
>    else return make_error<DWARFError>("No symbols!");<br>
> }<br>
><br>
> and on the caller side you write:<br>
><br>
> Error processAllSymbols() {<br>
>   if (auto Syms = getNumberOfSymbols()) {<br>
>     outs() << "There are " << *Syms << " symbols!";<br>
>   } else {<br>
>     return Syms.takeError();<br>
>     // alternatively, you could write:<br>
>     // consumeError(Syms.takeError());<br>
>     // return Error::success();<br>
>   }<br>
> }<br>
><br>
<br>
Interesting.<br>
<br>
This pattern doesn't quite work for fetching symbols - maybe that really is more suitable as a Status than an Error.  After all, number of symbols == 0 is not necessarily an error, there just might not have been any symbols (e.g. a fully stripped main); and I'm going to work on whatever symbols I get back, since there's nothing I can do about the ones that didn't make it.  I just want to propagate the error so the user knows that there was a problem.<br>
<br>
Jim<br></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>Sure, that was just a made up example.  You could imagine that being some private function deep in the implementation details of a symbol parser, where you've got some header that's supposed to be N bytes, and getNumberOfSymbols() seeks to offset 42 and reads a 4 byte value and returns it, but the function sees that there's only 40 bytes in the header, so it's not that there's no symbols, it's that something is seriously messed up.</div><div><br></div><div>In that case you could return an error such as this.</div><div><br></div><div>Of course, the person who called this function can either propagate it, deal with it some other way and mask it, or whatever.  Mostly I was just trying to show what the syntax looked like for grouping return values with errors. </div></div></div></blockquote></div>
</div></div></blockquote></div><br></div>
</blockquote></div>