Represent external bindings as a dag rather than as a tree #6838
Labels
big
this task is hard and will take a while
code quality
dependencies
dev-experience
Anything to do with the developer experience
performance
Everything related to performance, speed wise or memory wise.
The
namespace
module is responsible for keeping track of the name bindings in the compiled program, including bindings in external libraries.forc-pkg
is responsible for building aRoot
struct which initially holds a copy of all external bindings, and is then passed to the compiler which populates the struct with bindings from the current package.We used to do a lot of cloning of external library bindings, and #6291 eliminated quite a lot of that cloning. However, we still clone
Root
objects in quite a few places, and in particular we represent the dependency graph as a tree rather than a dag, with cloning of nodes with in-degree > 1 (see the illustration in #6291). In general this means that our dependency graph still has a potential exponential blowup in the number of dependencies.The external packages in the dependency graph should instead be represented as a flat map from package names to
Root
structs. The externals should be made available to theNamespace
struct, so that paths to external libraries can be resolved. This would make it possible to only have a singleRoot
struct for each package, thus making the representation linear in the size of the dependency graph.This would also fix the issue of paths leaking into packages where the paths no longer making sense, e.g.,
The path
A::MyTrait
doesn't make sense when viewed from packageC
because it doesn't know about packageA
. This could lead to problems with coherence, as well as potential name clashes if there are multiple libraries with the same name in the dependency graph.The text was updated successfully, but these errors were encountered: