Skip to content

Commit

Permalink
Merge 9698e8a into 6ee40a3
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcnn authored Mar 5, 2024
2 parents 6ee40a3 + 9698e8a commit 6c5cf66
Show file tree
Hide file tree
Showing 13 changed files with 499 additions and 534 deletions.
26 changes: 13 additions & 13 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1594,19 +1594,19 @@ pub fn dependency_namespace(
node: NodeIx,
engines: &Engines,
contract_id_value: Option<ContractIdConst>,
) -> Result<namespace::Module, vec1::Vec1<CompileError>> {
) -> Result<namespace::Root, vec1::Vec1<CompileError>> {
// TODO: Clean this up when config-time constants v1 are removed.
let node_idx = &graph[node];
let name = Some(Ident::new_no_span(node_idx.name.clone()));
let mut namespace = if let Some(contract_id_value) = contract_id_value {
let mut root_module = if let Some(contract_id_value) = contract_id_value {
namespace::Module::default_with_contract_id(engines, name.clone(), contract_id_value)?
} else {
namespace::Module::default()
};

namespace.is_external = true;
namespace.name = name;
namespace.visibility = Visibility::Public;
root_module.is_external = true;
root_module.name = name;
root_module.visibility = Visibility::Public;

// Add direct dependencies.
let mut core_added = false;
Expand Down Expand Up @@ -1640,7 +1640,7 @@ pub fn dependency_namespace(
ns
}
};
namespace.insert_submodule(dep_name, dep_namespace);
root_module.insert_submodule(dep_name, dep_namespace);
let dep = &graph[dep_node];
if dep.name == CORE {
core_added = true;
Expand All @@ -1651,29 +1651,29 @@ pub fn dependency_namespace(
if !core_added {
if let Some(core_node) = find_core_dep(graph, node) {
let core_namespace = &lib_namespace_map[&core_node];
namespace.insert_submodule(CORE.to_string(), core_namespace.clone());
root_module.insert_submodule(CORE.to_string(), core_namespace.clone());
}
}

let _ = namespace.star_import_with_reexports(
let mut root = namespace::Root::from(root_module);

let _ = root.star_import_with_reexports(
&Handler::default(),
engines,
&[CORE, PRELUDE].map(|s| Ident::new_no_span(s.into())),
&[],
true,
);

if has_std_dep(graph, node) {
let _ = namespace.star_import_with_reexports(
let _ = root.star_import_with_reexports(
&Handler::default(),
engines,
&[STD, PRELUDE].map(|s| Ident::new_no_span(s.into())),
&[],
true,
);
}

Ok(namespace)
Ok(root)
}

/// Find the `std` dependency, if it is a direct one, of the given node.
Expand Down Expand Up @@ -1750,7 +1750,7 @@ pub fn compile(
pkg: &PackageDescriptor,
profile: &BuildProfile,
engines: &Engines,
namespace: namespace::Module,
namespace: namespace::Root,
source_map: &mut SourceMap,
) -> Result<CompiledPackage> {
let mut metrics = PerformanceData::default();
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 @@ -320,7 +320,7 @@ impl CallPath {
.get(&self.suffix)
{
synonym_prefixes = use_synonym.0.clone();
is_absolute = use_synonym.3;
is_absolute = true;
let submodule = namespace.module().submodule(&[use_synonym.0[0].clone()]);
if let Some(submodule) = submodule {
is_external = submodule.is_external;
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ pub fn parsed_to_ast(
handler: &Handler,
engines: &Engines,
parse_program: &parsed::ParseProgram,
initial_namespace: namespace::Module,
initial_namespace: namespace::Root,
build_config: Option<&BuildConfig>,
package_name: &str,
retrigger_compilation: Option<Arc<AtomicBool>>,
Expand Down Expand Up @@ -638,7 +638,7 @@ pub fn compile_to_ast(
handler: &Handler,
engines: &Engines,
input: Arc<str>,
initial_namespace: namespace::Module,
initial_namespace: namespace::Root,
build_config: Option<&BuildConfig>,
package_name: &str,
retrigger_compilation: Option<Arc<AtomicBool>>,
Expand Down Expand Up @@ -735,7 +735,7 @@ pub fn compile_to_asm(
handler: &Handler,
engines: &Engines,
input: Arc<str>,
initial_namespace: namespace::Module,
initial_namespace: namespace::Root,
build_config: BuildConfig,
package_name: &str,
) -> Result<CompiledAsm, ErrorEmitted> {
Expand Down Expand Up @@ -892,7 +892,7 @@ pub fn compile_to_bytecode(
handler: &Handler,
engines: &Engines,
input: Arc<str>,
initial_namespace: namespace::Module,
initial_namespace: namespace::Root,
build_config: BuildConfig,
source_map: &mut SourceMap,
package_name: &str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ impl<'a, 'b> AutoImplAbiEncodeContext<'a, 'b> {
Ident::new_no_span("core".into()),
Ident::new_no_span("codec".into()),
],
true,
);

!handler.has_errors()
Expand Down Expand Up @@ -585,7 +584,6 @@ impl<'a, 'b> AutoImplAbiEncodeContext<'a, 'b> {
Ident::new_no_span("core".into()),
Ident::new_no_span("codec".into()),
],
true,
);

if import_handler.has_errors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,8 @@ mod tests {
expr: Expression,
type_annotation: TypeId,
) -> Result<ty::TyExpression, ErrorEmitted> {
let mut namespace = Namespace::init_root(namespace::Module::default());
let mut root_module = namespace::Module::default();
let mut namespace = Namespace::init_root(root_module);
let ctx = TypeCheckContext::from_namespace(&mut namespace, engines)
.with_type_annotation(type_annotation);
ty::TyExpression::type_check(handler, ctx, expr)
Expand Down
16 changes: 4 additions & 12 deletions sway-core/src/semantic_analysis/ast_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ impl ty::TyAstNode {
ImportType::Star => {
// try a standard starimport first
let star_import_handler = Handler::default();
let import =
ctx.star_import(&star_import_handler, &path, a.is_absolute);
let import = ctx.star_import(&star_import_handler, &path);
if import.is_ok() {
handler.append(star_import_handler);
import
Expand All @@ -62,7 +61,6 @@ impl ty::TyAstNode {
&variant_import_handler,
path,
enum_name,
a.is_absolute,
);
if variant_import.is_ok() {
handler.append(variant_import_handler);
Expand All @@ -78,18 +76,13 @@ impl ty::TyAstNode {
}
}
ImportType::SelfImport(_) => {
ctx.self_import(handler, &path, a.alias.clone(), a.is_absolute)
ctx.self_import(handler, &path, a.alias.clone())
}
ImportType::Item(ref s) => {
// try a standard item import first
let item_import_handler = Handler::default();
let import = ctx.item_import(
&item_import_handler,
&path,
s,
a.alias.clone(),
a.is_absolute,
);
let import =
ctx.item_import(&item_import_handler, &path, s, a.alias.clone());

if import.is_ok() {
handler.append(item_import_handler);
Expand All @@ -104,7 +97,6 @@ impl ty::TyAstNode {
enum_name,
s,
a.alias.clone(),
a.is_absolute,
);
if variant_import.is_ok() {
handler.append(variant_import_handler);
Expand Down
7 changes: 3 additions & 4 deletions sway-core/src/semantic_analysis/namespace/lexical_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub(crate) enum GlobImport {
}

pub(super) type SymbolMap = im::OrdMap<Ident, ty::TyDecl>;
// The final `bool` field of `UseSynonyms` is true if the `Vec<Ident>` path is absolute.
pub(super) type UseSynonyms = im::HashMap<Ident, (Vec<Ident>, GlobImport, ty::TyDecl, bool)>;
// The `Vec<Ident>` path is absolute.
pub(super) type UseSynonyms = im::HashMap<Ident, (Vec<Ident>, GlobImport, ty::TyDecl)>;
pub(super) type UseAliases = im::HashMap<String, Ident>;

/// Represents a lexical scope integer-based identifier, which can be used to reference
Expand Down Expand Up @@ -261,8 +261,7 @@ impl Items {
append_shadowing_error(ident, decl, false, false, &item, const_shadowing_mode);
}

if let Some((ident, (_, GlobImport::No, decl, _))) = self.use_synonyms.get_key_value(&name)
{
if let Some((ident, (_, GlobImport::No, decl))) = self.use_synonyms.get_key_value(&name) {
append_shadowing_error(
ident,
decl,
Expand Down
Loading

0 comments on commit 6c5cf66

Please sign in to comment.