Skip to content

Commit

Permalink
Remove duplicate type checker definitions in favor of UnifyCheck (F…
Browse files Browse the repository at this point in the history
…uelLabs#4593)

## Description

This is based on FuelLabs#4184 and fuses all duplicate type subset checkers in
favor of using `UnifyCheck` and `TypeInfo` equality.

## 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).
- [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.

Co-authored-by: Marcos Henrich <[email protected]>
  • Loading branch information
IGI-111 and esdrubal authored May 31, 2023
1 parent d026ddb commit 48104d0
Show file tree
Hide file tree
Showing 6 changed files with 480 additions and 695 deletions.
29 changes: 10 additions & 19 deletions sway-core/src/semantic_analysis/namespace/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use crate::{
CompileResult, Ident,
};

use super::{
module::Module, root::Root, submodule_namespace::SubmoduleNamespace,
trait_map::are_equal_minus_dynamic_types, Path, PathBuf,
};
use super::{module::Module, root::Root, submodule_namespace::SubmoduleNamespace, Path, PathBuf};

use sway_error::error::CompileError;
use sway_types::{span::Span, Spanned};
Expand Down Expand Up @@ -270,6 +267,8 @@ impl Namespace {
let decl_engine = engines.de();
let type_engine = engines.te();

let unify_check = UnifyCheck::non_dynamic_equality(engines);

let matching_item_decl_refs = check!(
self.find_items_for_type(type_id, method_prefix, method_name, self_type, engines,),
return err(warnings, errors),
Expand All @@ -294,19 +293,13 @@ impl Namespace {
for decl_ref in matching_method_decl_refs.clone().into_iter() {
let method = decl_engine.get_function(&decl_ref);
if method.parameters.len() == args_buf.len()
&& !method.parameters.iter().zip(args_buf.iter()).any(|(p, a)| {
!are_equal_minus_dynamic_types(
engines,
p.type_argument.type_id,
a.return_type,
)
})
&& method
.parameters
.iter()
.zip(args_buf.iter())
.all(|(p, a)| unify_check.check(p.type_argument.type_id, a.return_type))
&& (matches!(type_engine.get(annotation_type), TypeInfo::Unknown)
|| are_equal_minus_dynamic_types(
engines,
annotation_type,
method.return_type.type_id,
))
|| unify_check.check(annotation_type, method.return_type.type_id))
{
maybe_method_decl_refs.push(decl_ref);
}
Expand Down Expand Up @@ -356,9 +349,7 @@ impl Namespace {
warnings,
errors
);
if !are_equal_minus_dynamic_types(
engines, p1_type_id, p2_type_id,
) {
if !unify_check.check(p1_type_id, p2_type_id) {
params_equal = false;
break;
}
Expand Down
Loading

0 comments on commit 48104d0

Please sign in to comment.