Skip to content

Commit 6202bf6

Browse files
committed
Converted polymorph collection to use index set instead of hash set
1 parent 1a622d7 commit 6202bf6

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

Diff for: src/resolve/collect_polymorphs.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
use crate::asg::{self};
2-
use std::collections::HashSet;
1+
use crate::asg::{Type, TypeKind};
2+
use indexmap::IndexSet;
33

4-
pub fn collect_polymorphs(map: &mut HashSet<String>, ty: &asg::Type) {
4+
pub fn collect_polymorphs(map: &mut IndexSet<String>, ty: &Type) {
55
match &ty.kind {
6-
asg::TypeKind::Unresolved => panic!(),
7-
asg::TypeKind::Boolean
8-
| asg::TypeKind::Integer(_, _)
9-
| asg::TypeKind::CInteger(_, _)
10-
| asg::TypeKind::IntegerLiteral(_)
11-
| asg::TypeKind::FloatLiteral(_)
12-
| asg::TypeKind::Floating(_) => (),
13-
asg::TypeKind::Ptr(inner) => collect_polymorphs(map, inner.as_ref()),
14-
asg::TypeKind::Void => (),
15-
asg::TypeKind::Never => (),
16-
asg::TypeKind::AnonymousStruct() => todo!(),
17-
asg::TypeKind::AnonymousUnion() => todo!(),
18-
asg::TypeKind::AnonymousEnum(_) => (),
19-
asg::TypeKind::FixedArray(fixed_array) => collect_polymorphs(map, &fixed_array.inner),
20-
asg::TypeKind::FuncPtr(_) => todo!(),
21-
asg::TypeKind::Enum(_, _) => (),
22-
asg::TypeKind::Structure(_, _, params) | asg::TypeKind::TypeAlias(_, _, params) => {
6+
TypeKind::Unresolved => panic!(),
7+
TypeKind::Boolean
8+
| TypeKind::Integer(_, _)
9+
| TypeKind::CInteger(_, _)
10+
| TypeKind::IntegerLiteral(_)
11+
| TypeKind::FloatLiteral(_)
12+
| TypeKind::Floating(_) => (),
13+
TypeKind::Ptr(inner) => collect_polymorphs(map, inner.as_ref()),
14+
TypeKind::Void => (),
15+
TypeKind::Never => (),
16+
TypeKind::AnonymousStruct() => todo!(),
17+
TypeKind::AnonymousUnion() => todo!(),
18+
TypeKind::AnonymousEnum(_) => (),
19+
TypeKind::FixedArray(fixed_array) => collect_polymorphs(map, &fixed_array.inner),
20+
TypeKind::FuncPtr(_) => todo!(),
21+
TypeKind::Enum(_, _) => (),
22+
TypeKind::Structure(_, _, params) | TypeKind::TypeAlias(_, _, params) => {
2323
for parameter in params {
2424
collect_polymorphs(map, parameter);
2525
}
2626
}
27-
asg::TypeKind::Polymorph(name) => {
27+
TypeKind::Polymorph(name) => {
2828
if !map.contains(name) {
2929
map.insert(name.into());
3030
}
3131
}
32-
asg::TypeKind::Trait(_, _, parameters) => {
32+
TypeKind::Trait(_, _, parameters) => {
3333
for parameter in parameters {
3434
collect_polymorphs(map, parameter);
3535
}

Diff for: src/resolve/impl_head/for_alls.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use crate::{resolve::error::ResolveError, source_files::Source};
2-
use std::collections::{HashMap, HashSet};
2+
use indexmap::IndexSet;
3+
use std::collections::HashMap;
34

45
#[derive(Debug, Default)]
56
pub struct ForAlls {
6-
substitution_polys: HashSet<String>,
7+
substitution_polys: IndexSet<String>,
78
trait_to_impl: HashMap<String, String>,
89
impl_to_trait: HashMap<String, String>,
910
}
1011

1112
impl ForAlls {
12-
pub fn new(substitution_polys: HashSet<String>) -> Self {
13+
pub fn new(substitution_polys: IndexSet<String>) -> Self {
1314
Self {
1415
substitution_polys,
1516
trait_to_impl: Default::default(),

Diff for: src/resolve/impl_head/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use crate::{
1313
workspace::fs::FsNodeId,
1414
};
1515
use for_alls::ForAlls;
16-
use std::collections::{HashMap, HashSet};
16+
use indexmap::IndexSet;
17+
use std::collections::HashMap;
1718

1819
pub fn create_impl_heads(
1920
ctx: &mut ResolveCtx,
@@ -98,7 +99,7 @@ fn ensure_satisfies_trait_func(
9899
));
99100
}
100101

101-
let mut mappings = HashSet::new();
102+
let mut mappings = IndexSet::new();
102103
for sub in expected.values() {
103104
collect_polymorphs(&mut mappings, sub);
104105
}

0 commit comments

Comments
 (0)