Front page | perl.perl5.porters |
Postings from November 2016
Pure attributes
From:
Karl Williamson
Date:
November 25, 2016 03:31
Subject:
Pure attributes
Message ID:
61d43b8b-2113-ccb0-fb2f-861fc88a194d@cpan.org
Karl and I have been having some back and forth on function attributes that I think would be better public. Here he's discussing his search for functions that can be flagged as __attribute_pure__.
--- start Karl ---
One thing I realized is that it is easy to make a mistake and claim that something is pure that really isn't. This can be the source of very subtle bugs that vary between platforms, as they can optimize differently.
I decided to not mark any static functions as pure, as the compiler is better at figuring that out than me. So, I limited myself to looking at ones that are linked to externally. I came up with this short possible list to look at sometime. I don't remember how I got it, whether it was just the name, or something else:
: Candidates for pure
: ApdR |I32 |looks_like_number|NN SV *const sv
: Apd |int |grok_infnan |NN const char** sp|NN const char *send
: Apd |int |grok_number |NN const char *pv|STRLEN len|NULLOK UV *valuep
: Apd |int |grok_number_flags|NN const char *pv|STRLEN len|NULLOK UV *valuep|U32 flags
: ApdR |bool |grok_numeric_radix|NN const char **sp|NN const char *send
: ApM |bool |_is_in_locale_category|const bool compiling|const int category
: Amd |I32 |sv_eq |NULLOK SV* sv1|NULLOK SV* sv2
: Apd |I32 |sv_eq_flags |NULLOK SV* sv1|NULLOK SV* sv2|const U32 flags
: Apd |STRLEN |sv_len |NULLOK SV *const sv
: Apd |STRLEN |sv_len_utf8 |NULLOK SV *const sv
: p |STRLEN |sv_len_utf8_nomg|NN SV *const sv
: Apdn |bool |isinfnan |NV nv
: p |bool |isinfnansv |NN SV *sv
--- cut Karl ---
Karl, it sounds like you're saying that the compiler is better at figuring out pureness of static functions than non-static functions. That's surprising to me, because it seems like the purity of a function wouldn't depend on its visibility. Can you say more?
Wouldn't grok_number and grok_number_flags not be pure because they set *valuep?
FYI, here's my list. Looks like we have exactly zero in common. :-)
+inRP |bool |should_warn_nl|NN const char *pv
+sP |bool |looks_like_bool|NN const OP* o
+snRP |bool |num_overflow |NV value|I32 fldsize|I32 frcsize
+iRnP |bool |path_is_searchable|NN const char *name
+snP |NV|mulexp10 |NV value|I32 exponent
+sP |bool |ckwarn_common |U32 w
+ApoP |bool |ckwarn |U32 w
+ApoP |bool |ckwarn_d |U32 w
-
Pure attributes
by Karl Williamson