Previously we had two types, Type and Bound, which were mutually recursive. Type was also exposed in the public API as a type representing an incomplete Simplicity type. Bound was exposed in the public API for a couple of reasons which this PR eliminates.
However, because Type is both public and unusable without a live type inference context, this means that it needs to contain an Arc<Context>. But this means that if we have a self-referential type, this leaks to a somewhat-convoluted reference cycle in which a Type holds an Arc<Context> which owns a set of Bounds which contain the original Type. If you are skeptical of this, try running the test harness in valgrind before and after the last commit of this PR -- you will see that previously we were leaking memory in the memory_leak unit test but now we are not.
This completes the "type inference overhaul" needed to eliminate the memory leak in infinitely-sized types.
Previously we had two types,
Type
andBound
, which were mutually recursive.Type
was also exposed in the public API as a type representing an incomplete Simplicity type.Bound
was exposed in the public API for a couple of reasons which this PR eliminates.However, because
Type
is both public and unusable without a live type inference context, this means that it needs to contain anArc<Context>
. But this means that if we have a self-referential type, this leaks to a somewhat-convoluted reference cycle in which aType
holds anArc<Context>
which owns a set ofBound
s which contain the originalType
. If you are skeptical of this, try running the test harness in valgrind before and after the last commit of this PR -- you will see that previously we were leaking memory in thememory_leak
unit test but now we are not.This completes the "type inference overhaul" needed to eliminate the memory leak in infinitely-sized types.