reflect icon indicating copy to clipboard operation
reflect copied to clipboard

Make derive a pure function

Open 8BitMate opened this issue 5 years ago • 0 comments

At this point, a call to derive may return a different output between two calls on the same input. This has to do with how new generic parameters are created based on two global counters, and because some values are cached inside the library! macro. To make derive a pure function, the functions generated by the library! macro, which currently contains cached values, has to be pure functions as well.

One of the reasons we cache things in the library! macro in the first place is to make two calls to the same method less expensive, but not the only reason. We currently cache the generated RuntimeFunction::SELF and RuntimeParent::SELF methods. It is currently not possible to remove the caching of RuntimeParent::SELF without breaking something. If a Parent has generic parameters and several methods, each of its methods must refer to the same parent. If we removed the caching, each call to RuntimeParent::SELF would generate new generic parameters, and thus each method would refer to a different Parent.

A possible solution to this is to split generic parameters in two. We can have generic parameters that represent a parameter definition. These parameters only need to be unique for a definition of an impl, trait, or type definition, but do not have to be unique between definitions. We can then have a separate kind of parameters that are unique between definition and will be the ones used for inference purposes and in the output impls.

8BitMate avatar May 19 '20 10:05 8BitMate