Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/ir/thir.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use crate::prelude::*;
use crate::{
prelude::*,
ty::{TypeVarId, TypeVars},
};

use hir::*;

#[derive(Clone, Debug)]
pub struct Thir<'hir> {
pub hir: &'hir Hir,
pub types: HashMap<TypeVarId, TypeId>,
pub type_vars: TypeVars,
}

impl Deref for Thir<'_> {
Expand All @@ -17,11 +21,16 @@ impl Deref for Thir<'_> {
}

impl<'hir> Thir<'hir> {
pub fn new(hir: &'hir Hir, types: HashMap<TypeVarId, TypeId>) -> Self {
Self { hir, types }
pub fn new(hir: &'hir Hir, types: HashMap<TypeVarId, TypeId>, type_vars: TypeVars) -> Self {
Self {
hir,
types,
type_vars,
}
}

pub fn type_of(&self, id: impl Into<TypeVarId>) -> TypeId {
self.types[&id.into()]
pub fn type_of(&self, id: impl Into<TypeVar>) -> TypeId {
let var = self.type_vars.get(id.into());
self.types[&var]
}
}
10 changes: 7 additions & 3 deletions src/passes/mir_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ impl<'ctx, 'hir, 'thir> MirGen<'ctx, 'hir, 'thir> {
// If the block resolves to a value of the same type as the return value, then it's an
// implicit return.
let body = &self.thir[function.entry];
if let Some(result) = block.operand
&& self.thir.type_of(body.expression) == function.return_ty
{
if let Some(result) = block.operand {
assert_eq!(
self.thir.type_of(body.expression),
function.return_ty,
"ty check bug: body expression must match function return"
);

let place = self.mir.places.insert(return_local.into());
self.mir.add_statement(
block.exit,
Expand Down
40 changes: 14 additions & 26 deletions src/passes/snapshots/lumina2__passes__thir_gen__test__assign.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,39 @@ expression: "Assign { variable: ExpressionId(0), value: ExpressionId(0) }"
---
[
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Eq(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
),
),
(
Expression(
ExpressionId(
1,
),
TypeVarId(
0,
),
Eq(
Type(
TypeId(
1,
),
TypeVarId(
1,
),
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Aggregate(
[],
0,
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Aggregate(
[],
0,
),
),
]
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
---
source: src/passes/thir_gen.rs
expression: pass.constraints
expression: "*pass.constraints"
---
[
(
Expression(
ExpressionId(
4,
),
TypeVarId(
0,
),
Integer(
Any,
),
),
(
Expression(
ExpressionId(
4,
),
TypeVarId(
0,
),
Eq(
Expression(
ExpressionId(
3,
),
TypeVarId(
4,
),
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
5,
),
Aggregate(
[],
0,
),
),
]
40 changes: 14 additions & 26 deletions src/passes/snapshots/lumina2__passes__thir_gen__test__equal.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,38 @@ expression: "Binary { lhs: ExpressionId(0), operation: Equal, rhs: ExpressionId(
---
[
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Aggregate(
[],
0,
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Aggregate(
[],
0,
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Eq(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
),
),
(
Expression(
ExpressionId(
1,
),
TypeVarId(
0,
),
Eq(
Type(
TypeId(
4,
),
TypeVarId(
2,
),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
---
source: src/passes/thir_gen.rs
expression: pass.constraints
expression: "*pass.constraints"
---
[
(
Expression(
ExpressionId(
1,
),
TypeVarId(
0,
),
Integer(
Any,
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Aggregate(
[],
0,
),
),
]
52 changes: 18 additions & 34 deletions src/passes/snapshots/lumina2__passes__thir_gen__test__greater.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,54 @@ expression: "Binary { lhs: ExpressionId(0), operation: Greater, rhs: ExpressionI
---
[
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Aggregate(
[],
0,
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Aggregate(
[],
0,
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Eq(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Integer(
Any,
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
4,
),
Integer(
Any,
),
),
(
Expression(
ExpressionId(
1,
),
TypeVarId(
0,
),
Eq(
Type(
TypeId(
4,
),
TypeVarId(
2,
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@ expression: Inferred(ExpressionId(0))
---
[
(
Binding(
BindingId(
0,
),
TypeVarId(
0,
),
Eq(
Expression(
ExpressionId(
0,
),
TypeVarId(
1,
),
),
),
(
Expression(
ExpressionId(
0,
),
TypeVarId(
1,
),
Aggregate(
[],
0,
),
),
]
Loading