<#11269 Explore replacing monomorphization with im...
# github-notifications
c
#11269 Explore replacing monomorphization with implicit conversion Issue created by stuhood We currently "monomorphize" `@rule`s in the
RuleGraph
by creating a distinct copy of a
@rule
per set of
Param
types that it might be used with. This is quite complicated, and a lot of time has been invested in making it "mostly work"... but the implementation is not perfect, and we've needed to apply constraints that can be difficult to reason about. A motivation for monomorphization is that it avoids needing
eq
or
hash
implementations for positional arguments to
@rules
which are computed from `Param`s, rather than being `Param`s themselves. That is of questionable value relative to the complexity it incurs. And additionally, because monomorphization creates additional copies of
@rules
, it's likely that we are memoizing less than we could be. * * * An alternative to monomorphization would be to instead treat the preparation of the positional arguments to a
@rule
as similar to "implicit conversion" (a native concept in Scala, and possible via the
Deref
trait in Rust). This would involve optionally recursing to do "type conversion" via other rules (such as from
Addresses
to
Targets
) before invoking a
@rule
. For the purposes of these conversions, it's likely possible to keep a global lookup table of conversions that are possible, rather than actually encoding the conversion as a dependency of the
RuleGraph
entry. pantsbuild/pants