Skip to content

Commit 1464446

Browse files
authored
fix(ty): aggregate constraints (#2)
- Add `TypeVar::Field` to reference a field in another variable - Add `NonConcreteType::Tuple` - Alter `Constraints::Aggregate` to count the number of fields, rather than the specific `TypeVarId`s - General updates to solver
2 parents b4b2ba0 + a568aaa commit 1464446

24 files changed

Lines changed: 1023 additions & 836 deletions

src/ir/thir.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
use crate::prelude::*;
1+
use crate::{
2+
prelude::*,
3+
ty::{TypeVarId, TypeVars},
4+
};
25

36
use hir::*;
47

58
#[derive(Clone, Debug)]
69
pub struct Thir<'hir> {
710
pub hir: &'hir Hir,
811
pub types: HashMap<TypeVarId, TypeId>,
12+
pub type_vars: TypeVars,
913
}
1014

1115
impl Deref for Thir<'_> {
@@ -17,11 +21,16 @@ impl Deref for Thir<'_> {
1721
}
1822

1923
impl<'hir> Thir<'hir> {
20-
pub fn new(hir: &'hir Hir, types: HashMap<TypeVarId, TypeId>) -> Self {
21-
Self { hir, types }
24+
pub fn new(hir: &'hir Hir, types: HashMap<TypeVarId, TypeId>, type_vars: TypeVars) -> Self {
25+
Self {
26+
hir,
27+
types,
28+
type_vars,
29+
}
2230
}
2331

24-
pub fn type_of(&self, id: impl Into<TypeVarId>) -> TypeId {
25-
self.types[&id.into()]
32+
pub fn type_of(&self, id: impl Into<TypeVar>) -> TypeId {
33+
let var = self.type_vars.get(id.into());
34+
self.types[&var]
2635
}
2736
}

src/passes/mir_gen.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ impl<'ctx, 'hir, 'thir> MirGen<'ctx, 'hir, 'thir> {
9292
// If the block resolves to a value of the same type as the return value, then it's an
9393
// implicit return.
9494
let body = &self.thir[function.entry];
95-
if let Some(result) = block.operand
96-
&& self.thir.type_of(body.expression) == function.return_ty
97-
{
95+
if let Some(result) = block.operand {
96+
assert_eq!(
97+
self.thir.type_of(body.expression),
98+
function.return_ty,
99+
"ty check bug: body expression must match function return"
100+
);
101+
98102
let place = self.mir.places.insert(return_local.into());
99103
self.mir.add_statement(
100104
block.exit,

src/passes/snapshots/lumina2__passes__thir_gen__test__assign.snap

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,39 @@ expression: "Assign { variable: ExpressionId(0), value: ExpressionId(0) }"
44
---
55
[
66
(
7-
Expression(
8-
ExpressionId(
9-
0,
10-
),
7+
TypeVarId(
8+
4,
119
),
1210
Eq(
13-
Expression(
14-
ExpressionId(
15-
0,
16-
),
11+
TypeVarId(
12+
4,
1713
),
1814
),
1915
),
2016
(
21-
Expression(
22-
ExpressionId(
23-
1,
24-
),
17+
TypeVarId(
18+
0,
2519
),
2620
Eq(
27-
Type(
28-
TypeId(
29-
1,
30-
),
21+
TypeVarId(
22+
1,
3123
),
3224
),
3325
),
3426
(
35-
Expression(
36-
ExpressionId(
37-
0,
38-
),
27+
TypeVarId(
28+
4,
3929
),
4030
Aggregate(
41-
[],
31+
0,
4232
),
4333
),
4434
(
45-
Expression(
46-
ExpressionId(
47-
0,
48-
),
35+
TypeVarId(
36+
4,
4937
),
5038
Aggregate(
51-
[],
39+
0,
5240
),
5341
),
5442
]
Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
---
22
source: src/passes/thir_gen.rs
3-
expression: pass.constraints
3+
expression: "*pass.constraints"
44
---
55
[
66
(
7-
Expression(
8-
ExpressionId(
9-
4,
10-
),
7+
TypeVarId(
8+
0,
119
),
1210
Integer(
1311
Any,
1412
),
1513
),
1614
(
17-
Expression(
18-
ExpressionId(
19-
4,
20-
),
15+
TypeVarId(
16+
0,
2117
),
2218
Eq(
23-
Expression(
24-
ExpressionId(
25-
3,
26-
),
19+
TypeVarId(
20+
4,
2721
),
2822
),
2923
),
3024
(
31-
Expression(
32-
ExpressionId(
33-
0,
34-
),
25+
TypeVarId(
26+
5,
3527
),
3628
Aggregate(
37-
[],
29+
0,
3830
),
3931
),
4032
]

src/passes/snapshots/lumina2__passes__thir_gen__test__equal.snap

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,38 @@ expression: "Binary { lhs: ExpressionId(0), operation: Equal, rhs: ExpressionId(
44
---
55
[
66
(
7-
Expression(
8-
ExpressionId(
9-
0,
10-
),
7+
TypeVarId(
8+
4,
119
),
1210
Aggregate(
13-
[],
11+
0,
1412
),
1513
),
1614
(
17-
Expression(
18-
ExpressionId(
19-
0,
20-
),
15+
TypeVarId(
16+
4,
2117
),
2218
Aggregate(
23-
[],
19+
0,
2420
),
2521
),
2622
(
27-
Expression(
28-
ExpressionId(
29-
0,
30-
),
23+
TypeVarId(
24+
4,
3125
),
3226
Eq(
33-
Expression(
34-
ExpressionId(
35-
0,
36-
),
27+
TypeVarId(
28+
4,
3729
),
3830
),
3931
),
4032
(
41-
Expression(
42-
ExpressionId(
43-
1,
44-
),
33+
TypeVarId(
34+
0,
4535
),
4636
Eq(
47-
Type(
48-
TypeId(
49-
4,
50-
),
37+
TypeVarId(
38+
2,
5139
),
5240
),
5341
),
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
---
22
source: src/passes/thir_gen.rs
3-
expression: pass.constraints
3+
expression: "*pass.constraints"
44
---
55
[
66
(
7-
Expression(
8-
ExpressionId(
9-
1,
10-
),
7+
TypeVarId(
8+
0,
119
),
1210
Integer(
1311
Any,
1412
),
1513
),
1614
(
17-
Expression(
18-
ExpressionId(
19-
0,
20-
),
15+
TypeVarId(
16+
4,
2117
),
2218
Aggregate(
23-
[],
19+
0,
2420
),
2521
),
2622
]

src/passes/snapshots/lumina2__passes__thir_gen__test__greater.snap

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,54 @@ expression: "Binary { lhs: ExpressionId(0), operation: Greater, rhs: ExpressionI
44
---
55
[
66
(
7-
Expression(
8-
ExpressionId(
9-
0,
10-
),
7+
TypeVarId(
8+
4,
119
),
1210
Aggregate(
13-
[],
11+
0,
1412
),
1513
),
1614
(
17-
Expression(
18-
ExpressionId(
19-
0,
20-
),
15+
TypeVarId(
16+
4,
2117
),
2218
Aggregate(
23-
[],
19+
0,
2420
),
2521
),
2622
(
27-
Expression(
28-
ExpressionId(
29-
0,
30-
),
23+
TypeVarId(
24+
4,
3125
),
3226
Eq(
33-
Expression(
34-
ExpressionId(
35-
0,
36-
),
27+
TypeVarId(
28+
4,
3729
),
3830
),
3931
),
4032
(
41-
Expression(
42-
ExpressionId(
43-
0,
44-
),
33+
TypeVarId(
34+
4,
4535
),
4636
Integer(
4737
Any,
4838
),
4939
),
5040
(
51-
Expression(
52-
ExpressionId(
53-
0,
54-
),
41+
TypeVarId(
42+
4,
5543
),
5644
Integer(
5745
Any,
5846
),
5947
),
6048
(
61-
Expression(
62-
ExpressionId(
63-
1,
64-
),
49+
TypeVarId(
50+
0,
6551
),
6652
Eq(
67-
Type(
68-
TypeId(
69-
4,
70-
),
53+
TypeVarId(
54+
2,
7155
),
7256
),
7357
),

src/passes/snapshots/lumina2__passes__thir_gen__test__inferred.snap

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@ expression: Inferred(ExpressionId(0))
44
---
55
[
66
(
7-
Binding(
8-
BindingId(
9-
0,
10-
),
7+
TypeVarId(
8+
0,
119
),
1210
Eq(
13-
Expression(
14-
ExpressionId(
15-
0,
16-
),
11+
TypeVarId(
12+
1,
1713
),
1814
),
1915
),
2016
(
21-
Expression(
22-
ExpressionId(
23-
0,
24-
),
17+
TypeVarId(
18+
1,
2519
),
2620
Aggregate(
27-
[],
21+
0,
2822
),
2923
),
3024
]

0 commit comments

Comments
 (0)