Context
Since Elixir 1.13, Macro.Env.fetch_alias/2 has existed as a mechanism to resolve an alias to its fully-qualified name. This has the limitation, however, that you cannot use the actual alias in the lookup.
iex> alias Foo.Bar, as: Baz
iex> Macro.Env.fetch_alias(__ENV__, :Baz)
{:ok, Foo.Bar}
iex> Macro.Env.fetch_alias(__ENV__, Baz)
:error
There is not a mechanism to go the other way without relying on the private aliases field in a Macro.Env struct.
Proposal
Introduce a new function, Macro.Env.fetch_aliased_as/2, that is able to look up the name that a module is aliased as. Additionally, extend the behavior of both Macro.Env.fetch_aliased_as/2 and Macro.Env.fetch_alias/2 to accept qualified atoms.
iex> alias Foo.Bar, as: Baz
Baz
iex> Macro.Env.fetch_alias(__ENV__, :Baz)
{:ok, Foo.Bar}
iex> Macro.Env.fetch_alias(__ENV__, Baz)
{:ok, Foo.Bar}
iex> Macro.Env.fetch_alias(__ENV__, :Unknown)
:error
iex> Macro.Env.fetch_aliased_as(__ENV__, :"Foo.Bar")
{:ok, Baz}
iex> Macro.Env.fetch_aliased_as(__ENV__, Foo.Bar}
{:ok, Baz}
iex> Macro.Env.fetch_aliased_as(__ENV__, Foo.Unknown)
:error
I'll submit a PR shortly for this change, but am happy to wait for any discussion that might happen here before it's acted on.