Skip to content

Commit

Permalink
Removes redundant checks from unifier. (#6912)
Browse files Browse the repository at this point in the history
## Description

unify_structs was also unifying the fields and unify_enums was also
unifying the variants.

This was removed because comparing call paths and type parameters is
enough.

Fixes #6394

## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] 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).
- [ ] I have requested a review from the relevant team or maintainers.

Signed-off-by: Marcos Henrich <marcoshenrich@gmail.com>
  • Loading branch information
esdrubal authored Feb 11, 2025
1 parent bb7c99b commit 475fd78
Showing 1 changed file with 15 additions and 49 deletions.
64 changes: 15 additions & 49 deletions sway-core/src/type_system/unify/unifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sway_types::Span;

use crate::{
engine_threading::{Engines, PartialEqWithEngines, PartialEqWithEnginesContext, WithEngines},
language::{ty, CallPath},
language::CallPath,
type_system::{engine::Unification, priv_prelude::*},
};

Expand Down Expand Up @@ -149,16 +149,8 @@ impl<'a> Unifier<'a> {
received,
expected,
span,
(
r_decl.call_path.clone(),
r_decl.type_parameters.clone(),
r_decl.fields.clone(),
),
(
e_decl.call_path.clone(),
e_decl.type_parameters.clone(),
e_decl.fields.clone(),
),
(r_decl.call_path.clone(), r_decl.type_parameters.clone()),
(e_decl.call_path.clone(), e_decl.type_parameters.clone()),
);
}
// When we don't know anything about either term, assume that
Expand Down Expand Up @@ -250,16 +242,8 @@ impl<'a> Unifier<'a> {
received,
expected,
span,
(
r_decl.call_path.clone(),
r_decl.type_parameters.clone(),
r_decl.variants.clone(),
),
(
e_decl.call_path.clone(),
e_decl.type_parameters.clone(),
e_decl.variants.clone(),
),
(r_decl.call_path.clone(), r_decl.type_parameters.clone()),
(e_decl.call_path.clone(), e_decl.type_parameters.clone()),
);
}

Expand Down Expand Up @@ -387,21 +371,12 @@ impl<'a> Unifier<'a> {
received: TypeId,
expected: TypeId,
span: &Span,
r: (CallPath, Vec<TypeParameter>, Vec<ty::TyStructField>),
e: (CallPath, Vec<TypeParameter>, Vec<ty::TyStructField>),
r: (CallPath, Vec<TypeParameter>),
e: (CallPath, Vec<TypeParameter>),
) {
let (rn, rtps, rfs) = r;
let (en, etps, efs) = e;
if rn == en && rfs.len() == efs.len() && rtps.len() == etps.len() {
rfs.iter().zip(efs.iter()).for_each(|(rf, ef)| {
self.unify(
handler,
rf.type_argument.type_id,
ef.type_argument.type_id,
span,
false,
);
});
let (rn, rtps) = r;
let (en, etps) = e;
if rn == en && rtps.len() == etps.len() {
rtps.iter().zip(etps.iter()).for_each(|(rtp, etp)| {
self.unify(handler, rtp.type_id, etp.type_id, span, false);
});
Expand All @@ -425,21 +400,12 @@ impl<'a> Unifier<'a> {
received: TypeId,
expected: TypeId,
span: &Span,
r: (CallPath, Vec<TypeParameter>, Vec<ty::TyEnumVariant>),
e: (CallPath, Vec<TypeParameter>, Vec<ty::TyEnumVariant>),
r: (CallPath, Vec<TypeParameter>),
e: (CallPath, Vec<TypeParameter>),
) {
let (rn, rtps, rvs) = r;
let (en, etps, evs) = e;
if rn == en && rvs.len() == evs.len() && rtps.len() == etps.len() {
rvs.iter().zip(evs.iter()).for_each(|(rv, ev)| {
self.unify(
handler,
rv.type_argument.type_id,
ev.type_argument.type_id,
span,
false,
);
});
let (rn, rtps) = r;
let (en, etps) = e;
if rn == en && rtps.len() == etps.len() {
rtps.iter().zip(etps.iter()).for_each(|(rtp, etp)| {
self.unify(handler, rtp.type_id, etp.type_id, span, false);
});
Expand Down

0 comments on commit 475fd78

Please sign in to comment.