Skip to content

Commit

Permalink
Fix rebasing issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Feb 3, 2025
1 parent 43a4835 commit cbf79c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
26 changes: 17 additions & 9 deletions sway-core/src/language/ty/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use crate::{
decl_engine::*,
fuel_prelude::fuel_tx::StorageSlot,
language::{parsed, ty::*, Purity},
language::{parsed, ty::*, Purity, Visibility},
semantic_analysis::namespace,
transform::AllowDeprecatedState,
type_system::*,
Expand Down Expand Up @@ -65,6 +65,7 @@ impl TyProgram {
handler: &Handler,
engines: &Engines,
root: &TyModule,
root_namespace: &mut namespace::Namespace,
kind: parsed::TreeType,
package_name: &str,
experimental: ExperimentalFeatures,
Expand All @@ -81,6 +82,7 @@ impl TyProgram {
handler,
engines,
&submodule.module,
root_namespace,
parsed::TreeType::Library,
package_name,
experimental,
Expand Down Expand Up @@ -424,22 +426,28 @@ impl TyProgram {
}

// check trait overlap
let mut unified_trait_map = root
.namespace
.root_module()
let mut unified_trait_map = root_namespace
.root_ref()
.current_package_root_module()
.root_lexical_scope()
.items
.implemented_traits
.clone();
unified_trait_map.check_overlap_and_extend(handler, unified_trait_map.clone(), engines)?;

for (_, submodule) in root.submodules.iter() {
for (submod_name, submodule) in root.submodules.iter() {
root_namespace.push_submodule(
handler,
engines,
submod_name.clone(),
Visibility::Public,
submodule.mod_name_span.clone(),
)?;

unified_trait_map.check_overlap_and_extend(
handler,
submodule
.module
.namespace
.module(engines)
root_namespace
.current_module()
.root_lexical_scope()
.items
.implemented_traits
Expand Down
17 changes: 10 additions & 7 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
sync::Arc,
};

use itertools::Itertools;
use sway_error::{
error::CompileError,
handler::{ErrorEmitted, Handler},
Expand Down Expand Up @@ -463,6 +464,7 @@ impl TraitMap {
})
}

#[allow(clippy::too_many_arguments)]
fn insert_inner(
&mut self,
trait_name: TraitName,
Expand Down Expand Up @@ -651,7 +653,7 @@ impl TraitMap {
let callpath = CallPath {
prefixes: self_entry.key.name.prefixes.clone(),
suffix: self_entry.key.name.suffix.name.clone(),
is_absolute: self_entry.key.name.is_absolute,
callpath_type: self_entry.key.name.callpath_type,
};
println!(
"get_traits_types {:?} {}",
Expand Down Expand Up @@ -690,8 +692,7 @@ impl TraitMap {
.key
.impl_type_parameters
.iter()
.map(|tp| tp.trait_constraints.iter().map(|tc| (tc, tp.clone())))
.flatten()
.flat_map(|tp| tp.trait_constraints.iter().map(|tc| (tc, tp.clone())))
.collect::<Vec<_>>();

for other_entry in other.get_impls(engines, self_entry.key.type_id, true) {
Expand All @@ -705,8 +706,7 @@ impl TraitMap {
.key
.impl_type_parameters
.iter()
.map(|tp| tp.trait_constraints.iter().map(|tc| (tc, tp.clone())))
.flatten()
.flat_map(|tp| tp.trait_constraints.iter().map(|tc| (tc, tp.clone())))
.collect::<Vec<_>>();
let other_tcs_satisfied = other_tcs.iter().all(|(tc, tp)| {
if let Some(tc_type_ids) = traits_types.get(&tc.trait_name) {
Expand Down Expand Up @@ -745,8 +745,11 @@ impl TraitMap {
});

if other_tcs_satisfied && self_tcs_satisfied {
for (trait_item_name1, _) in self_entry.value.trait_items.clone() {
for (trait_item_name2, _) in other_entry.value.trait_items.clone() {
let entry_items = self_entry.value.trait_items.keys().sorted();
for trait_item_name1 in entry_items {
let other_entry_items =
other_entry.value.trait_items.keys().sorted();
for trait_item_name2 in other_entry_items {
if trait_item_name1 == trait_item_name2 {
handler.emit_err(CompileError::InternalOwned(
format!("Overlapped item {}", trait_item_name1),
Expand Down
4 changes: 3 additions & 1 deletion sway-core/src/semantic_analysis/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ impl TyProgram {
namespace: ctx.namespace.root_ref().clone(),
})?;

let experimental = ctx.experimental;
let (kind, declarations, configurables) = Self::validate_root(
handler,
engines,
&root,
ctx.namespace_mut(),
*kind,
package_name,
ctx.experimental,
experimental,
)
.map_err(|error| TypeCheckFailed {
error,
Expand Down

0 comments on commit cbf79c8

Please sign in to comment.