[eeps] EEP 049: Value-Based Error Handling Mechanisms

José Valim jose.valim@REDACTED
Thu Oct 29 15:41:39 CET 2020


For Elixir, we end-up duplicating the else clause on all <- patterns. This
was the implementation that performed better but it makes Dialyzer unhappy.
In a nutshell, you convert each X <- Y into:

case Y of
  X -> rest_of_begin
  ...AllClausesInCase -> ...
end

It may be easier to implement.

We also discussed an approach where the else clauses would be moved to an
anonymous function that we would call on every failed <-, to reduce the
code duplication. However, that was expensive. There have been discussions
about inlining anonymous function calls in the compiler, or at least
removing the intermediate anonymous function "object", which may make it a
better implementation.


On Thu, Oct 29, 2020 at 3:19 PM Fred Hebert <mononcqc@REDACTED> wrote:

> Quick update to mention I've managed to set things up in a way where only
> rewrites using case expressions could be used to make things work (assuming
> tokenizer support for the other constructs):
> https://gist.github.com/ferd/2f1134fd88615354fbf89c068216b259
>
> I guess the question I have there is whether we feel this is acceptable,
> or way too risky when it comes to constructs such as parse transforms which
> work with the AST. It feels like this is a change that causes "minimal
> displacement" but ends up being a much larger burden down the road when
> people writing tools that work on Erlang code and abstract representations
> have to be aware of these translations and subtle variations in order to
> maintain user-intended semantics intact. Would it make sense to look at a
> much deeper integration introducing new forms all the way to core erlang
> (which could likely ignore begin ... else ... end and rewrite with case
> expressions there)?
>
> EEPs tend to come with a reference implementation so I'm starting to look
> at ways I can feasibly pull this off on my own.
>
> On Fri, Oct 23, 2020 at 9:57 AM Fred Hebert <mononcqc@REDACTED> wrote:
>
>> On Fri, Oct 23, 2020 at 7:32 AM Björn Gustavsson <bjorn@REDACTED>
>> wrote:
>>
>>>
>>> We have handled the addition of new keywords in the past by having an
>>> option to disable them (keeping the new keywords as atoms). That we
>>> will allow the compilation of old code that uses the keyword as an
>>> atom. (We did that when we introduced try/catch.)
>>>
>>
>> Sounds good to me.
>>
>> I'd be fine speccing the addition of an 'else-style' keyword for begin
>> ... end. A funny thing to consider is that if we add 'else', people will
>> be really confused about why begin ... end has it but not if ... end. I
>> figure this is out of scope for this specific RFC, but worth pointing out
>> regardless.
>>
>> I'll try to find slack time over the next week or two to edit EEP-49,
>> including the quoted workaround and possibly some additional research. But
>> to do a tl:dr;, this is heading for:
>>
>>    - begin ... end with an optional begin ... else ... end variant
>>    - The "unwrap expression" is replaced by a "match or return"
>>    mechanism.
>>    - since there is no longer any unwrapping we can switch form <~ to <-
>>    as an operator and keep rather familiar semantics
>>    - the else keyword (or anything else that takes its place) would
>>    require compiler options that specify using it as an atom to allow
>>    compilation of older modules which do not use the construct and rely on the
>>    same keyword.
>>
>> I'm gonna have to look into whether this can still be safely emulated
>> with simple case expression being shifted around or if it requires fancier
>> a lower-level rewrite. I doubt it can be that easy to do because we have to
>> intersperse non-conditional code in there and a goto-like mechanism could
>> make more sense (an option would also be to use a ref with a throw/catch,
>> but I'd rather avoid the cost of generating a ref per block of
>> conditionals). Anyway, while I look into this, that'll give time to get
>> more potential feedback or information from the OTP team, which Kenneth has
>> hinted at.
>>
> _______________________________________________
> eeps mailing list
> eeps@REDACTED
> http://erlang.org/mailman/listinfo/eeps
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/eeps/attachments/20201029/ba4eabc7/attachment.htm>


More information about the eeps mailing list