Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move access to externals to Namespace #6999

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,7 @@ pub fn check(
if let Ok(typed_program) = programs.typed.as_ref() {
if let TreeType::Library = typed_program.kind.tree_type() {
let mut lib_root = typed_program.namespace.root_ref().clone();
lib_root.current_package_root_module_mut().set_span(
lib_root.root_module_mut().set_span(
Span::new(
manifest.entry_string()?,
0,
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/ir_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn compile_program<'eng>(
engines,
&mut ctx,
entry_function,
namespace.root_ref(),
namespace,
&logged_types,
&messages_types,
&test_fns,
Expand All @@ -176,7 +176,7 @@ pub fn compile_program<'eng>(
engines,
&mut ctx,
entry_function,
namespace.root_ref(),
namespace,
&logged_types,
&messages_types,
&test_fns,
Expand All @@ -189,7 +189,7 @@ pub fn compile_program<'eng>(
&mut ctx,
entry_function.as_ref(),
abi_entries,
namespace.root_ref(),
namespace,
declarations,
&logged_types,
&messages_types,
Expand All @@ -200,7 +200,7 @@ pub fn compile_program<'eng>(
ty::TyProgramKind::Library { .. } => compile::compile_library(
engines,
&mut ctx,
namespace.root_ref(),
namespace,
&logged_types,
&messages_types,
&test_fns,
Expand Down
42 changes: 23 additions & 19 deletions sway-core/src/ir_generation/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(super) fn compile_script(
engines: &Engines,
context: &mut Context,
entry_function: &DeclId<ty::TyFunctionDecl>,
namespace: &namespace::Root,
namespace: &namespace::Namespace,
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
test_fns: &[(Arc<ty::TyFunctionDecl>, DeclRefFunction)],
Expand Down Expand Up @@ -80,7 +80,7 @@ pub(super) fn compile_predicate(
engines: &Engines,
context: &mut Context,
entry_function: &DeclId<ty::TyFunctionDecl>,
namespace: &namespace::Root,
namespace: &namespace::Namespace,
logged_types: &HashMap<TypeId, LogId>,
messages_types: &HashMap<TypeId, MessageId>,
test_fns: &[(Arc<ty::TyFunctionDecl>, DeclRefFunction)],
Expand Down Expand Up @@ -133,7 +133,7 @@ pub(super) fn compile_contract(
context: &mut Context,
entry_function: Option<&DeclId<ty::TyFunctionDecl>>,
abi_entries: &[DeclId<ty::TyFunctionDecl>],
namespace: &namespace::Root,
namespace: &namespace::Namespace,
declarations: &[ty::TyDecl],
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
Expand Down Expand Up @@ -224,7 +224,7 @@ pub(super) fn compile_contract(
pub(super) fn compile_library(
engines: &Engines,
context: &mut Context,
namespace: &namespace::Root,
namespace: &namespace::Namespace,
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
test_fns: &[(Arc<ty::TyFunctionDecl>, DeclRefFunction)],
Expand Down Expand Up @@ -255,25 +255,29 @@ pub(crate) fn compile_constants_for_package(
engines: &Engines,
context: &mut Context,
module: Module,
namespace: &namespace::Root,
namespace: &namespace::Namespace,
) -> Result<Module, Vec<CompileError>> {
let mut md_mgr = MetadataManager::default();
// Traverses the tree of externals and collects all constants
fn traverse(
engines: &Engines,
context: &mut Context,
module: Module,
current: &namespace::Root,
) -> Result<Module, Vec<CompileError>> {
let mut md_mgr = MetadataManager::default();

// Collect constant for all dependencies
for ext_package in current.external_packages.values() {
traverse(engines, context, module, ext_package)?;
}

// Collect constant for all dependencies
for ext_package in namespace.external_packages().values() {
compile_constants_for_package(engines, context, module, ext_package)?;
}
compile_constants(engines, context, &mut md_mgr, module, current.root_module())
.map_err(|err| vec![err])?;

compile_constants(
engines,
context,
&mut md_mgr,
module,
namespace.current_package_root_module(),
)
.map_err(|err| vec![err])?;
Ok(module)
}

Ok(module)
traverse(engines, context, module, namespace.root_ref())
}

fn compile_constants(
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/language/call_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl CallPath {
CallPathDisplayType::Regular => {}
CallPathDisplayType::StripPackagePrefix => {
if let Some(first) = self.prefixes.first() {
if namespace.root_ref().current_package_root_module().name() == first {
if namespace.current_package_name() == first {
display_path = display_path.lshift();
}
}
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ pub fn parsed_to_ast(
engines,
&mut ctx,
module,
typed_program.namespace.root_ref(),
&typed_program.namespace,
) {
errs.into_iter().for_each(|err| {
handler.emit_err(err.clone());
Expand Down
Loading
Loading