Currently, each unboxed closure definition generates its own unique type, functions however do not exhibit the same behavior. This RFC proposes the addition of a unique compiler-generated zero-sized anonymous type for each function definition.
This allows a normal function to be used in place where any unboxed closure would, with the exact same generated code as if the function was an unboxed closure with no captures. As it stands the function would instead be passed as a pointer, which leads to pointless indirection and missed optimizations.
As this causes a function to be equivalent (bar the coercions to
fn() and calling syntax) to a struct with no fields implementing
FnOnce, it may lead to further simplification of the language and the compiler.
Each function shall have its own anonymous, zero-sized type, henceforth referred to as a “function type”. Each function type should implement
FnOnce. Any reference of a function as a literal should result in the instantiation of that functions associated type. Every function type should also be coercible to an appropriate
The superfluous type information may lead to slowdowns during compilation. This is also introduces extra coercion rules which may be undesirable.
None currently proposed.