Latest Results
Refactor: Access to externals moved from `Root` to `Namespace` (#6999)
## Description
Fixes #6846 .
The dependency graph is currently represented as a tree structure in the
field `Root::external_packages` field. Since the dependency graph is in
general a dag, there is a potential exponential blowup in representing
it as a tree structure, so we would like to instead represent it using a
linear structure.
In order to create a linear structure we will need to move the
dependency graph out of the `Root` struct, so that `Root` objects can be
inserted into the dependency graph without causing issues with Rust.
This PR is a step towards that goal in that moves almost all the code
that accesses `external_packages` from `impl Root` to `impl Namespace`.
In particular:
- The functions that perform imports have been moved. This also allows
some minor simplifications of the code, since imports are only ever
performed with the destination being the current module.
- The module visibility check has been moved, and simplified.
- Various helper functions have been moved, and simplified.
- `module_mut_from_absolute_path` has been moved, and mutable access to
external modules has been eliminated.
`module_from_absolute_path` has not yet been moved, since this function
is used by `sway-lsp`, which does not have access to a `Namespace`
object. This will be fixed as part of the datastructure change.
Additionally, a few other refactorings have taken place:
- The `ResolvedDeclaration` type has been moved to its own file.
- `Root` has been renamed to `Package`, with variables and fields
renamed accordingly.
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers. Mergejjcnn/externals_to_namespace Active Branches
#69860%
#7015-34%
#69670%
© 2025 CodSpeed Technology