1

Found this in Ecto.Repo.Supervisor and I was wondering where the other options to __info__/1 are documented:

  def compile_config(repo, opts) do
  # (...)
    behaviours =
      for {:behaviour, behaviours} <- adapter.__info__(:attributes),
          behaviour <- behaviours,
          do: behaviour

  # (...)
  end

The Module documentation only mentions that

After a module is compiled, using many of the functions in this module will raise errors, since it is out of their scope to inspect runtime data. Most of the runtime data can be inspected via the __info__/1 function attached to each compiled module.

toraritte
  • 6,300
  • 3
  • 46
  • 67
  • 1
    That's interesting. The `Module` page on hexdocs [had `__info__/1` documented](https://hexdocs.pm/elixir/1.6.0/Module.html#__info__/1) in Elixir `1.6.X`, but it isn't there in the `1.7.X` and `master` docs (even though it's there in the source). – Sheharyar Oct 30 '18 at 08:26
  • I assume that it has been omitted to discourage direct usage. Probably because it looks like OO inheritance than clean FP? – toraritte Oct 30 '18 at 14:20
  • All methods starting with `__` are automatically omitted **unless** the @doc is explicitly specified, which in this case is. – Sheharyar Oct 30 '18 at 16:54
  • So [`Module` docs for `1.6.6`](https://hexdocs.pm/elixir/1.6.6/Module.html#__info__/1) still has an entry for `__info__/1`, but it is missing starting with [`1.7.0-rc.0`](https://hexdocs.pm/elixir/1.7.0-rc.0/Module.html#__info__/1). – toraritte Oct 30 '18 at 17:09
  • Did a diff between tags `1.6.6` and `1.7.0-rc.0`, but other then finding a new supported atom (`:deprecated`), I didn't not see any changes that would exclude `__info__/1` from the docs. (Used commands in [How to compare two tags?](https://stackoverflow.com/questions/3211809/how-to-compare-two-tags)) Isn't [`ex_doc`](https://github.com/elixir-lang/ex_doc) used for generating documentation? It's an external library so maybe changes in there caused this? – toraritte Oct 30 '18 at 17:44
  • Exactly, I believe something changed in ExDoc, not Elixir. – Sheharyar Oct 30 '18 at 17:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182816/discussion-between-toraritte-and-sheharyar). – toraritte Oct 30 '18 at 17:59

2 Answers2

1

The Module documentation has been updated to include __info__/1 since 1.8.0.

See also a related bug ticket (that might have been created because this question).

user272735
  • 10,473
  • 9
  • 65
  • 96
0

Found it in Module's source:

 @doc """
  Provides runtime information about functions and macros defined by the
  module, etc.
  Each module gets an `__info__/1` function when it's compiled. The function
  takes one of the following atoms:
    * `:functions` - keyword list of public functions along with their arities
    * `:macros` - keyword list of public macros along with their arities
    * `:module` - the module atom name
    * `:md5` - the MD5 of the module
    * `:compile` - a list with compiler metadata
    * `:attributes` - a list with all persisted attributes
  """
  def __info__(kind)

Undocumented atoms

:deprecated - shows deprecated functions in a module that are prefixed with the @deprecated attribute (included in 1.7.0-rc.0)


Test drive

Trying out the above behaviour = snippet above in a Phoenix project:

$ iex -S mix phx.server

iex(3)> Ecto.Adapters.Postgres.__info__(:attributes)
[
  vsn: [168581197275628950002173003256895919063],
  behaviour: [Ecto.Adapter],
  behaviour: [Ecto.Adapter.Migration],
  behaviour: [Ecto.Adapter.Queryable],
  behaviour: [Ecto.Adapter.Schema],
  behaviour: [Ecto.Adapter.Transaction],
  behaviour: [Ecto.Adapter.Storage],
  behaviour: [Ecto.Adapter.Structure]
]

iex(4)> for {:behaviour, behaviours} <- 
...(4)>     Ecto.Adapters.Postgres.__info__(:attributes),
...(4)>   behaviour <- behaviours, 
...(4)>   do: behaviour
[Ecto.Adapter, Ecto.Adapter.Migration, Ecto.Adapter.Queryable,
 Ecto.Adapter.Schema, Ecto.Adapter.Transaction, Ecto.Adapter.Storage,
 Ecto.Adapter.Structure]
toraritte
  • 6,300
  • 3
  • 46
  • 67