You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The existing join algorithm suffers from several drawbacks:
- It can be slow due to the use of a quadratic algorithm, taking up to
60% of the total compilation time in -O3 mode in pathological cases
(lambda_to_flambda_primitives.ml). See also #3300.
- It is inefficient as it computes the join of all types appearing in
*any* joined environment prior to filtering out the types that are
not needed, instead of first computing the types whose join will be
needed.
- It is sensitive to the names of local variables that only exist in
some of the joined environments but not in the target environment.
- It relies on a global binding time of variables across all joined
environments and the target environment that does not exist, as
figured in #3278. Subsequently, it can lose aliasing information,
and breaks typing env invariants by recording the same variable as
defined multiple times (with dubious semantics).
This patch implements a new join algorithm, based on a n-way join of types.
The new algorithm is:
- Faster, as it avoids quadratic complexity (outside of complex nesting
of env extensions). Compared to the existing join algorithm (with
advanced meet), on my machine, the new join algorithm is 30x faster
on the pathological lambda_to_flambda_primitives.ml, taking only
around 10% of the total compilation time and speeding up the
compilation of the file by 3.5x. On camlinternalFormat.ml, the new
join is about 2.5-3x faster, reducing the time spent in the join from
20% to less than 10% and speeding up the total compilation time by
about 20%.
- More efficient, as it only computes a join if it can possibly result
in a more precise type, i.e. if the variable has been assigned a new
type in all joined environments (otherwise the existing type in the
target environment is already the most precise).
- Independent of the names of local variables.
- Only depends on a consistent binding time *order* of the shared
variables (defined in both the target environment and all joined
environments), which is respected. Since the result is independent of
the binding times of local / existential variables, the typing env
invariants are respected.
0 commit comments