[erlang-questions] Problems With Smart Exceptions

Ulf Wiger ulf.wiger@REDACTED
Mon Dec 20 19:52:40 CET 2010


It seems as if an 80% solution could rather easily be made using
a core_transform, since the most interesting exceptions are explicit
in Core Erlang.

One question to the OTP team, though:

I made a very simple test module and inserted a 
-compile({core_transform, testmod}), in it.

Why is the core transform called twice?

…after some digging, it seems as if 

compile:clean_parse_transforms/1

should remove core_transform directives as well, right?


clean_parse_transforms(Fs) ->
    clean_parse_transforms_1(Fs, []).

clean_parse_transforms_1([{attribute,L,compile,C0}|Fs], Acc) when is_list(C0) ->
    C = lists:filter(fun({parse_transform,_}) -> false;
			(_) -> true
		     end, C0),
    clean_parse_transforms_1(Fs, [{attribute,L,compile,C}|Acc]);
clean_parse_transforms_1([{attribute,_,compile,{parse_transform,_}}|Fs], Acc) ->
    clean_parse_transforms_1(Fs, Acc);
clean_parse_transforms_1([F|Fs], Acc) ->
    clean_parse_transforms_1(Fs, [F|Acc]);
clean_parse_transforms_1([], Acc) -> reverse(Acc).

Now, core transforms are not documented at all, so I couldn't say if there
is some secret reason why they _should_ be called twice, but I'd wager
they shouldn't. :)

BR,
Ulf W

On 20 Dec 2010, at 18:25, Olivier BOUDEVILLE wrote:

> Hi,
> 
> I tried both versions (stable/devel) of the Smart Exceptions 
> parse-transform (as taken from https://github.com/thomasl/smart_exceptions
> ), but had not luck with either.
> 
> With the stable version, correct user code produced then unwanted 
> warnings, like "Warning: variable 'KeyIndex' exported from 'case' (line 
> 90)" for:
> 
> """
>  addEntry( Key, Value, HashTable ) ->
> 
>     KeyIndex = erlang:phash2( Key, size(HashTable) ) + 1,
> 
>     % Retrieve appropriate tuple slot:
>     PreviousList = element( KeyIndex, HashTable ),
> 
>     NewList = replaceBucket( Key, Value, PreviousList, [] ),
> 
>     setelement(KeyIndex,HashTable,NewList).
> """
> (line 90 is "KeyIndex = erlang:phash2( Key, size(HashTable) ) + 1"). 
> Many warnings like this one appeared, in the transformed code.
> 
> 
> With the devel version, I could check that the parse transform was 
> compiled and found at compile-time, but even when using the sample code in 
> http://www.erlang.org/faq/how_do_i.html#id55258 I still have the exact 
> same message that was output when this parse-transform was not used:
> 
> ''''
> Erlang R14B01 (erts-5.8.2) [source] [64-bit] [smp:8:8] [rq:8] 
> [async-threads:0] [hipe] [kernel-poll:false]
> 
> Eshell V5.8.2  (abort with ^G)
> 1>  c(crash, [{parse_transform, smart_exceptions}]).
> ./crash.erl:9: Warning: no clause will ever match
> {ok,crash}
> 2> crash:f().
> ** exception error: no match of right hand side value 5
>      in function  crash:g/0
> ''''
> 
> Am I doing something wrong?
> 
> A last question: shouldn't we expect a performance penalty when using this 
> parse-transform? I imagine that the transformed code could be (slighthly?) 
> less efficient if having to test for more matchings/wrap more exceptions?
> 
> Thanks in advance for any information,
> Best regards,
> 
> Olivier Boudeville.
> ---------------------------
> Olivier Boudeville
> 
> EDF R&D : 1, avenue du Général de Gaulle, 92140 Clamart, France
> Département SINETICS, groupe ASICS (I2A), bureau B-226
> Office : +33 1 47 65 59 58 / Mobile : +33 6 16 83 37 22 / Fax : +33 1 47 
> 65 27 13
> 
> 
> 
> Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à l'intention exclusive des destinataires et les informations qui y figurent sont strictement confidentielles. Toute utilisation de ce Message non conforme à sa destination, toute diffusion ou toute publication totale ou partielle, est interdite sauf autorisation expresse.
> 
> Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si vous avez reçu ce Message par erreur, merci de le supprimer de votre système, ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support que ce soit. Nous vous remercions également d'en avertir immédiatement l'expéditeur par retour du message.
> 
> Il est impossible de garantir que les communications par messagerie électronique arrivent en temps utile, sont sécurisées ou dénuées de toute erreur ou virus.
> ____________________________________________________
> 
> This message and any attachments (the 'Message') are intended solely for the addressees. The information contained in this Message is confidential. Any use of information contained in this Message not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval.
> 
> If you are not the addressee, you may not copy, forward, disclose or use any part of it. If you have received this message in error, please delete it and all copies from your system and notify the sender immediately by return message.
> 
> E-mail communication cannot be guaranteed to be timely secure, error or virus-free.

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com





More information about the erlang-questions mailing list