Is there a reason iolist_size/1 is not a guard BIF like length/1, byte_size/1 and bit_size/1?

Is there a reason iolist_size/1 is not a guard BIF like length/1, byte_size/1 and bit_size/1?

Cheers,
Mark

4 Likes

There are a couple of strict and some not-so-strict rules that decide whether something should be a guard BIF or not.

My un-official (possibly incorrect) guard bif rules

  1. It must not have any side effects
  2. It must be auto-imported (that is callable without a prefix)
  3. It should be O(1) in execution time (length, is_map_key, and possibly others that I forget are exceptions here)
  4. It should operate on basic types (that is not on abstract types such as iodata())

iolist_size/1 breaks rule #3 and #4, so therefore it should not be a guard bif.

There used to be a technical reason for iolist_size/1 to not be a guard bif, but that limitation was removed a couple of releases ago.

11 Likes