Skip to content

Commit 472fdf9

Browse files
committed
Refactored and cleaned up polymorph matching code
1 parent 8667975 commit 472fdf9

File tree

10 files changed

+529
-435
lines changed

10 files changed

+529
-435
lines changed

Diff for: src/resolve/expr/call/infer_impl.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,19 @@ pub fn infer_callee_missing_impl_args(
2525
continue;
2626
};
2727

28-
// TODO: PERFORMANCE: Optimize this and remove unnecessary cloning.
29-
// We should really change `match_type` and friends to produce a type match solution
30-
// instead of modifying the poly catalog.
3128
let from_env = caller.impl_params.params.iter().filter(|(_, param_trait)| {
32-
let mut catalog_plus_match = catalog.clone();
33-
34-
if catalog_plus_match
35-
.match_types(ctx, &expected_trait.args, &param_trait.args)
29+
if catalog
30+
.extend_if_match_all_types(ctx, &expected_trait.args, &param_trait.args)
3631
.is_err()
3732
{
3833
return false;
3934
}
4035

41-
catalog_plus_match
36+
catalog
4237
.resolver()
4338
.resolve_trait(expected_trait)
4439
.map_or(false, |expected_trait| {
45-
if param_trait.trait_ref == expected_trait.trait_ref {
46-
*catalog = catalog_plus_match;
47-
true
48-
} else {
49-
false
50-
}
40+
param_trait.trait_ref == expected_trait.trait_ref
5141
})
5242
});
5343

Diff for: src/resolve/expr/call/specified_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn try_register_specified_impl(
177177
));
178178
}
179179

180-
match catalog.match_types(
180+
match catalog.extend_if_match_all_types(
181181
ctx,
182182
param_generic_trait.args.as_slice(),
183183
arg_concrete_trait.args.as_slice(),

Diff for: src/resolve/func_haystack.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ impl FuncHaystack {
158158
argument: &TypedExpr,
159159
param_type: &asg::Type,
160160
) -> bool {
161-
catalog.match_type(ctx, param_type, &argument.ty).is_ok()
161+
catalog
162+
.extend_if_match_type(ctx, param_type, &argument.ty)
163+
.is_ok()
162164
}
163165

164166
fn find_local(

Diff for: src/resolve/func_head.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ pub fn resolve_parameters(
143143
})
144144
}
145145

146-
pub fn create_func_impl_params<'a>(
147-
type_ctx: &ResolveTypeCtx<'a>,
146+
pub fn create_func_impl_params(
147+
type_ctx: &ResolveTypeCtx,
148148
head: &FuncHead,
149149
) -> Result<ImplParams, ResolveError> {
150150
let mut params = IndexMap::default();

0 commit comments

Comments
 (0)