Wraps a lazily computed value. Also circumvents cycles during implicit search, or wrong implicit divergences
as illustrated below, and holds the corresponding implicit value lazily.
The following implicit search sometimes fails to compile, because of a wrongly reported implicit divergence,
When looking for an implicit Lazy[TC[T]], the Lazy.mkLazy macro will itself trigger the implicit search
for a TC[T]. If this search itself triggers searches for types wrapped in Lazy, these will be done
only once, their result put in a lazy val, and a reference to this lazy val will be returned as the corresponding
value. It will then wrap all the resulting values together, and return a reference to the first one.
E.g. with the above example definitions, when looking up for an implicit TC[CC], the returned tree roughly looks
like
TC.genericTC(
Generic[CC], // actually, the tree returned by Generic.materialize, not written here for the sake of brevity
Lazy {
lazyval impl1: TC[List[CC] :: HNil] = TC.hconsTC(
Lazy(impl2),
TC.hnilTC
)
lazyval impl2: TC[List[CC]] = TC.listTC(TC.genericTC(
Generic[CC], // actually, the tree returned by Generic.materialize
Lazy(impl1) // cycles to the initial TC[List[CC] :: HNil]
))
impl1
}
)
Wraps a lazily computed value. Also circumvents cycles during implicit search, or wrong implicit divergences as illustrated below, and holds the corresponding implicit value lazily.
The following implicit search sometimes fails to compile, because of a wrongly reported implicit divergence,
This wrongly reported implicit divergence can be circumvented by wrapping some of the implicit values in
Lazy
,When looking for an implicit
Lazy[TC[T]]
, theLazy.mkLazy
macro will itself trigger the implicit search for aTC[T]
. If this search itself triggers searches for types wrapped inLazy
, these will be done only once, their result put in alazy val
, and a reference to thislazy val
will be returned as the corresponding value. It will then wrap all the resulting values together, and return a reference to the first one.E.g. with the above example definitions, when looking up for an implicit
TC[CC]
, the returned tree roughly looks like