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

find_method_for_type improvements #6744

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
15 changes: 15 additions & 0 deletions sway-core/src/engine_threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ impl<T: OrdWithEngines> OrdWithEngines for Option<T> {
}
}

impl<T: OrdWithEngines> OrdWithEngines for Vec<T> {
fn cmp(&self, other: &Self, ctx: &OrdWithEnginesContext) -> Ordering {
match self.len().cmp(&other.len()) {
Ordering::Less => Ordering::Less,
Ordering::Equal => self
.iter()
.zip(other.iter())
.fold(Ordering::Equal, |accumulator, values| {
accumulator.then_with(|| values.0.cmp(values.1, ctx))
}),
Ordering::Greater => Ordering::Greater,
}
}
}

impl<T: OrdWithEngines> OrdWithEngines for Box<T> {
fn cmp(&self, other: &Self, ctx: &OrdWithEnginesContext) -> Ordering {
(**self).cmp(&(**other), ctx)
Expand Down
19 changes: 19 additions & 0 deletions sway-core/src/language/ty/declaration/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,25 @@ impl TyFunctionDecl {
_ => Some(false),
}
}

pub fn is_from_blanket_impl(&self, engines: &Engines) -> bool {
if let Some(TyDecl::ImplSelfOrTrait(existing_impl_trait)) = self.implementing_type.clone() {
let existing_trait_decl = engines
.de()
.get_impl_self_or_trait(&existing_impl_trait.decl_id);
if !existing_trait_decl.impl_type_parameters.is_empty()
&& matches!(
*engines
.te()
.get(existing_trait_decl.implementing_for.type_id),
TypeInfo::UnknownGeneric { .. }
)
{
return true;
}
}
false
}
}

#[derive(Debug, Clone)]
Expand Down
2 changes: 0 additions & 2 deletions sway-core/src/language/ty/expression/expression_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
engine_threading::*,
has_changes,
language::{ty::*, *},
namespace::TryInsertingTraitImplOnFailure,
semantic_analysis::{
TyNodeDepGraphEdge, TyNodeDepGraphEdgeInfo, TypeCheckAnalysis, TypeCheckAnalysisContext,
TypeCheckContext, TypeCheckFinalization, TypeCheckFinalizationContext,
Expand Down Expand Up @@ -833,7 +832,6 @@ impl ReplaceDecls for TyExpressionVariant {
.map(|a| a.1.return_type)
.collect::<VecDeque<_>>(),
None,
TryInsertingTraitImplOnFailure::Yes,
)?;
method = (*decl_engine.get(&implementing_type_method_ref)).clone();
}
Expand Down
6 changes: 2 additions & 4 deletions sway-core/src/semantic_analysis/ast_node/declaration/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
DeclId,
},
language::ty::{TyAbiDecl, TyFunctionDecl},
namespace::{IsExtendingExistingImpl, IsImplSelf, TryInsertingTraitImplOnFailure},
namespace::{IsExtendingExistingImpl, IsImplSelf},
semantic_analysis::{
symbol_collection_context::SymbolCollectionContext, TypeCheckAnalysis,
TypeCheckAnalysisContext, TypeCheckFinalization, TypeCheckFinalizationContext,
Expand Down Expand Up @@ -116,7 +116,6 @@ impl ty::TyAbiDecl {
ctx.type_annotation(),
&Default::default(),
None,
TryInsertingTraitImplOnFailure::No,
) {
let superabi_impl_method =
ctx.engines.de().get_function(&superabi_impl_method_ref);
Expand Down Expand Up @@ -291,7 +290,6 @@ impl ty::TyAbiDecl {
ctx.type_annotation(),
&Default::default(),
None,
TryInsertingTraitImplOnFailure::No,
) {
let superabi_method =
ctx.engines.de().get_function(&superabi_method_ref);
Expand Down Expand Up @@ -367,7 +365,6 @@ impl ty::TyAbiDecl {
ctx.type_annotation(),
&Default::default(),
None,
TryInsertingTraitImplOnFailure::No,
) {
let superabi_impl_method =
ctx.engines.de().get_function(&superabi_impl_method_ref);
Expand Down Expand Up @@ -421,6 +418,7 @@ impl ty::TyAbiDecl {
&Handler::default(),
CallPath::ident_to_fullpath(self.name.clone(), ctx.namespace()),
vec![],
vec![],
type_id,
&all_items,
&self.span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ impl TyDecl {
handler,
impl_trait.trait_name.clone(),
impl_trait.trait_type_arguments.clone(),
impl_trait.impl_type_parameters.clone(),
impl_trait.implementing_for.type_id,
&impl_trait.items,
&impl_trait.span,
Expand Down Expand Up @@ -319,6 +320,7 @@ impl TyDecl {
handler,
impl_trait.trait_name.clone(),
impl_trait.trait_type_arguments.clone(),
impl_trait.impl_type_parameters.clone(),
impl_trait.implementing_for.type_id,
impl_trait_items,
&impl_trait.span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ impl TyImplSelfOrTrait {
handler,
impl_trait.trait_name.clone(),
impl_trait.trait_type_arguments.clone(),
impl_trait.impl_type_parameters.clone(),
impl_trait.implementing_for.type_id,
&impl_trait.items,
&impl_trait.span,
Expand Down Expand Up @@ -760,6 +761,7 @@ fn type_check_trait_implementation(
&Handler::default(),
trait_name.clone(),
trait_type_arguments.to_vec(),
impl_type_parameters.to_vec(),
implementing_for,
&this_supertrait_impld_method_refs
.values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl TyTraitDecl {
handler,
CallPath::ident_to_fullpath(name.clone(), ctx.namespace),
new_type_parameters.iter().map(|x| x.into()).collect(),
new_type_parameters.clone(),
self_type,
&dummy_interface_surface,
&span,
Expand Down Expand Up @@ -238,6 +239,7 @@ impl TyTraitDecl {
handler,
CallPath::ident_to_fullpath(name.clone(), ctx.namespace()),
new_type_parameters.iter().map(|x| x.into()).collect(),
new_type_parameters.clone(),
self_type,
&dummy_interface_surface,
&span,
Expand Down Expand Up @@ -596,6 +598,7 @@ impl TyTraitDecl {
&Handler::default(),
trait_name.clone(),
type_arguments.to_vec(),
type_parameters.to_vec(),
type_id,
&all_items,
&trait_name.span(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,7 @@ impl ty::TyExpression {
handler,
abi_name.clone(),
vec![],
vec![],
return_type,
&abi_items,
span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
ty::{self, TyDecl, TyExpression, TyFunctionSig},
*,
},
namespace::TryInsertingTraitImplOnFailure,
semantic_analysis::*,
type_system::*,
};
Expand Down Expand Up @@ -831,7 +830,6 @@ pub(crate) fn resolve_method_name(
ctx.type_annotation(),
&arguments_types,
None,
TryInsertingTraitImplOnFailure::Yes,
)?;

(decl_ref, type_id)
Expand Down Expand Up @@ -868,7 +866,6 @@ pub(crate) fn resolve_method_name(
ctx.type_annotation(),
&arguments_types,
None,
TryInsertingTraitImplOnFailure::Yes,
)?;

(decl_ref, type_id)
Expand All @@ -892,7 +889,6 @@ pub(crate) fn resolve_method_name(
ctx.type_annotation(),
&arguments_types,
None,
TryInsertingTraitImplOnFailure::Yes,
)?;

(decl_ref, type_id)
Expand All @@ -917,7 +913,6 @@ pub(crate) fn resolve_method_name(
ctx.type_annotation(),
&arguments_types,
Some(*as_trait),
TryInsertingTraitImplOnFailure::Yes,
)?;

(decl_ref, type_id)
Expand Down
Loading
Loading