Skip to content

Commit 475fd78

Browse files
authored
Removes redundant checks from unifier. (#6912)
## 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>
1 parent bb7c99b commit 475fd78

File tree

1 file changed

+15
-49
lines changed

1 file changed

+15
-49
lines changed

sway-core/src/type_system/unify/unifier.rs

+15-49
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use sway_types::Span;
55

66
use crate::{
77
engine_threading::{Engines, PartialEqWithEngines, PartialEqWithEnginesContext, WithEngines},
8-
language::{ty, CallPath},
8+
language::CallPath,
99
type_system::{engine::Unification, priv_prelude::*},
1010
};
1111

@@ -149,16 +149,8 @@ impl<'a> Unifier<'a> {
149149
received,
150150
expected,
151151
span,
152-
(
153-
r_decl.call_path.clone(),
154-
r_decl.type_parameters.clone(),
155-
r_decl.fields.clone(),
156-
),
157-
(
158-
e_decl.call_path.clone(),
159-
e_decl.type_parameters.clone(),
160-
e_decl.fields.clone(),
161-
),
152+
(r_decl.call_path.clone(), r_decl.type_parameters.clone()),
153+
(e_decl.call_path.clone(), e_decl.type_parameters.clone()),
162154
);
163155
}
164156
// When we don't know anything about either term, assume that
@@ -250,16 +242,8 @@ impl<'a> Unifier<'a> {
250242
received,
251243
expected,
252244
span,
253-
(
254-
r_decl.call_path.clone(),
255-
r_decl.type_parameters.clone(),
256-
r_decl.variants.clone(),
257-
),
258-
(
259-
e_decl.call_path.clone(),
260-
e_decl.type_parameters.clone(),
261-
e_decl.variants.clone(),
262-
),
245+
(r_decl.call_path.clone(), r_decl.type_parameters.clone()),
246+
(e_decl.call_path.clone(), e_decl.type_parameters.clone()),
263247
);
264248
}
265249

@@ -387,21 +371,12 @@ impl<'a> Unifier<'a> {
387371
received: TypeId,
388372
expected: TypeId,
389373
span: &Span,
390-
r: (CallPath, Vec<TypeParameter>, Vec<ty::TyStructField>),
391-
e: (CallPath, Vec<TypeParameter>, Vec<ty::TyStructField>),
374+
r: (CallPath, Vec<TypeParameter>),
375+
e: (CallPath, Vec<TypeParameter>),
392376
) {
393-
let (rn, rtps, rfs) = r;
394-
let (en, etps, efs) = e;
395-
if rn == en && rfs.len() == efs.len() && rtps.len() == etps.len() {
396-
rfs.iter().zip(efs.iter()).for_each(|(rf, ef)| {
397-
self.unify(
398-
handler,
399-
rf.type_argument.type_id,
400-
ef.type_argument.type_id,
401-
span,
402-
false,
403-
);
404-
});
377+
let (rn, rtps) = r;
378+
let (en, etps) = e;
379+
if rn == en && rtps.len() == etps.len() {
405380
rtps.iter().zip(etps.iter()).for_each(|(rtp, etp)| {
406381
self.unify(handler, rtp.type_id, etp.type_id, span, false);
407382
});
@@ -425,21 +400,12 @@ impl<'a> Unifier<'a> {
425400
received: TypeId,
426401
expected: TypeId,
427402
span: &Span,
428-
r: (CallPath, Vec<TypeParameter>, Vec<ty::TyEnumVariant>),
429-
e: (CallPath, Vec<TypeParameter>, Vec<ty::TyEnumVariant>),
403+
r: (CallPath, Vec<TypeParameter>),
404+
e: (CallPath, Vec<TypeParameter>),
430405
) {
431-
let (rn, rtps, rvs) = r;
432-
let (en, etps, evs) = e;
433-
if rn == en && rvs.len() == evs.len() && rtps.len() == etps.len() {
434-
rvs.iter().zip(evs.iter()).for_each(|(rv, ev)| {
435-
self.unify(
436-
handler,
437-
rv.type_argument.type_id,
438-
ev.type_argument.type_id,
439-
span,
440-
false,
441-
);
442-
});
406+
let (rn, rtps) = r;
407+
let (en, etps) = e;
408+
if rn == en && rtps.len() == etps.len() {
443409
rtps.iter().zip(etps.iter()).for_each(|(rtp, etp)| {
444410
self.unify(handler, rtp.type_id, etp.type_id, span, false);
445411
});

0 commit comments

Comments
 (0)