Skip to content

Commit fbbfd62

Browse files
committed
fix: fixed MIR
1 parent c55ffad commit fbbfd62

10 files changed

Lines changed: 31 additions & 48 deletions

File tree

compiler/astoir_mir_lowering/src/arrays.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn lower_hir_array_modify(
5454

5555
build_store(
5656
&mut ctx.mir_ctx,
57-
&ctx.hir_ctx.type_storage,
57+
&ctx.hir_ctx.global_scope,
5858
index_pointer,
5959
val,
6060
)?;

compiler/astoir_mir_lowering/src/casts.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ pub fn lower_cast(
2424

2525
let new_type = lower_hir_type(ctx, new_type)?;
2626

27-
if old_type
28-
.get_generic(&ctx.hir_ctx.type_storage)
29-
.is_enum_child()
30-
&& new_type
31-
.get_generic(&ctx.hir_ctx.type_storage)
32-
.is_enum_parent()
33-
{
27+
if old_type.get_generic().is_enum_child() && new_type.get_generic().is_enum_parent() {
3428
match ctx.mir_ctx.ssa_hints.vec[value.get_ssa_index()] {
3529
MIRValueHint::Pointer(_) => {
3630
ctx.mir_ctx.ssa_hints.vec[value.get_ssa_index()] =

compiler/astoir_mir_lowering/src/introductions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn handle_var_introduction_queue(
4444
} else {
4545
let ptr = build_stack_alloc(
4646
&mut ctx.mir_ctx,
47-
new_type.get_size(&new_type, false, &ctx.hir_ctx.type_storage),
47+
new_type.get_size(&new_type, false, &ctx.hir_ctx.global_scope),
4848
new_type,
4949
)?;
5050

@@ -57,7 +57,7 @@ pub fn handle_var_introduction_queue(
5757
);
5858
build_store(
5959
&mut ctx.mir_ctx,
60-
&ctx.hir_ctx.type_storage,
60+
&ctx.hir_ctx.global_scope,
6161
ptr.clone(),
6262
casted,
6363
)?;

compiler/astoir_mir_lowering/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ pub fn lower_hir_generic(
105105
hir_mir_indexes: HashMap::new(),
106106
};
107107

108-
let parent = match &ctx.hir_ctx.type_storage.types.vals[container.parent] {
108+
let parent = match &ctx.hir_ctx.global_scope.entries[container.parent].as_type_unsafe()
109+
{
109110
RawType::Enum(container) => container.clone(),
110111
_ => panic!("Enum parent not enum"),
111112
};
@@ -154,12 +155,11 @@ pub fn lower_hir_generic(
154155
Type::Generic(entry.1.clone(), info.0.clone(), info.1.clone()),
155156
)?;
156157

157-
entry_size =
158-
entry_size.max(lowered.get_generic(&ctx.hir_ctx.type_storage).get_size(
159-
&lowered,
160-
false,
161-
&ctx.hir_ctx.type_storage,
162-
))
158+
entry_size = entry_size.max(lowered.get_generic().get_size(
159+
&lowered,
160+
false,
161+
&ctx.hir_ctx.global_scope,
162+
))
163163
}
164164

165165
lowered_container

compiler/astoir_mir_lowering/src/lru.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn lower_hir_lru_step(
3434
.ssa_hints
3535
.get_hint(curr.get_ssa_index())
3636
.get_type()
37-
.get_generic(&ctx.hir_ctx.type_storage)
37+
.get_generic()
3838
{
3939
RawType::LoweredStruct(_, container) => container,
4040
_ => unsure_panic!("lower_hir_lru_step curr was not an actual thing"),

compiler/astoir_mir_lowering/src/math.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn lower_hir_math_operation(
4444
let left_val = lower_hir_value(block, left, ctx)?;
4545
let right_val = lower_hir_value(block, right, ctx)?;
4646

47-
let val = match left_val.vtype.get_generic(&ctx.hir_ctx.type_storage) {
47+
let val = match left_val.vtype.get_generic() {
4848
RawType::Integer(_, _) | RawType::FixedPoint(_, _, _) => {
4949
lower_hir_math_operation_int(left_val, right_val, operation.clone(), ctx)?
5050
}
@@ -62,7 +62,7 @@ pub fn lower_hir_math_operation(
6262
block,
6363
&mut ctx.mir_ctx,
6464
val.clone(),
65-
&ctx.hir_ctx.type_storage,
65+
&ctx.hir_ctx.global_scope,
6666
)?;
6767
}
6868

compiler/astoir_mir_lowering/src/type_tools.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn is_enum_value_of_kind<K: DiagnosticSpanOrigin>(
6868
hint_type.get_size(
6969
&Type::GenericLowered(hint_type.clone()),
7070
false,
71-
&ctx.hir_ctx.type_storage,
71+
&ctx.hir_ctx.global_scope,
7272
),
7373
)?;
7474

@@ -144,13 +144,7 @@ pub fn lower_hir_unwrap_cond(
144144
if unsafe_unwrap {
145145
cond = build_unsigned_int_const(&mut ctx.mir_ctx, 1, 1)?;
146146
} else {
147-
cond = is_enum_value_of_kind(
148-
block,
149-
original,
150-
new_type.get_generic(&ctx.hir_ctx.type_storage),
151-
ctx,
152-
&*node,
153-
)?
147+
cond = is_enum_value_of_kind(block, original, new_type.get_generic(), ctx, &*node)?
154148
}
155149

156150
if new_var.is_none() {
@@ -179,13 +173,7 @@ pub fn lower_hir_unwrap_value(
179173
let original = lower_hir_value(block, original, ctx)?;
180174
let new_type = lower_hir_type(ctx, new_type)?;
181175

182-
return cast_to_enum_child(
183-
block,
184-
original,
185-
new_type.get_generic(&ctx.hir_ctx.type_storage),
186-
ctx,
187-
&*node,
188-
);
176+
return cast_to_enum_child(block, original, new_type.get_generic(), ctx, &*node);
189177
}
190178

191179
panic!("Invalid node!")

compiler/astoir_mir_lowering/src/values/consts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ pub fn lower_hir_literal(
1414
) -> DiagnosticResult<BaseMIRValue> {
1515
match node.kind {
1616
HIRNodeKind::IntegerLiteral { value, int_type } => {
17-
if int_type.get_generic(&ctx.hir_ctx.type_storage).is_signed() {
17+
if int_type.get_generic().is_signed() {
1818
let val = build_signed_int_const(
1919
&mut ctx.mir_ctx,
2020
value,
21-
int_type.get_size(&int_type, true, &ctx.hir_ctx.type_storage),
21+
int_type.get_size(&int_type, true, &ctx.hir_ctx.global_scope),
2222
)?;
2323

2424
return Ok(val.into());
@@ -27,7 +27,7 @@ pub fn lower_hir_literal(
2727
let val = build_unsigned_int_const(
2828
&mut ctx.mir_ctx,
2929
value as u128,
30-
int_type.get_size(&int_type, true, &ctx.hir_ctx.type_storage),
30+
int_type.get_size(&int_type, true, &ctx.hir_ctx.global_scope),
3131
)?;
3232

3333
return Ok(val.into());

compiler/astoir_mir_lowering/src/values/structs.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,27 @@ pub fn lower_hir_struct_init(
1717
if let HIRNodeKind::StructInitializerTyped { t, fields } = node.kind {
1818
let mut values = vec![];
1919

20-
match t.get_generic(&ctx.hir_ctx.type_storage) {
20+
match t.get_generic() {
2121
RawType::Struct(_, _) => {
2222
for field in fields {
2323
values.push(lower_hir_value(block, field, ctx)?);
2424
}
2525
}
2626

2727
RawType::EnumEntry(container) => {
28-
let parent = match &ctx.hir_ctx.type_storage.types.vals[container.parent] {
29-
RawType::Enum(container) => container.clone(),
30-
_ => panic!("Enum parent not enum"),
31-
};
28+
let parent =
29+
match &ctx.hir_ctx.global_scope.entries[container.parent].as_type_unsafe() {
30+
RawType::Enum(container) => container.clone(),
31+
_ => panic!("Enum parent not enum"),
32+
};
3233

3334
let hint = build_unsigned_int_const(
3435
&mut ctx.mir_ctx,
3536
container.child as u128,
3637
parent.get_hint_type().get_size(
3738
&Type::GenericLowered(parent.get_hint_type()),
3839
false,
39-
&ctx.hir_ctx.type_storage,
40+
&ctx.hir_ctx.global_scope,
4041
),
4142
)?;
4243

@@ -50,7 +51,7 @@ pub fn lower_hir_struct_init(
5051
_ => panic!("Invalid type for a StructInitializedTyped"),
5152
}
5253

53-
let lowered_type = lower_hir_type(ctx, t)?.get_generic(&ctx.hir_ctx.type_storage);
54+
let lowered_type = lower_hir_type(ctx, t)?.get_generic();
5455

5556
return build_static_struct_const(&mut ctx.mir_ctx, lowered_type, values);
5657
}

compiler/astoir_mir_lowering/src/vars.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn lower_hir_variable_declaration(
5151

5252
let ptr = build_stack_alloc(
5353
&mut ctx.mir_ctx,
54-
lowered.get_size(&lowered, false, &ctx.hir_ctx.type_storage),
54+
lowered.get_size(&lowered, false, &ctx.hir_ctx.global_scope),
5555
lowered,
5656
)?;
5757

@@ -68,7 +68,7 @@ pub fn lower_hir_variable_declaration(
6868

6969
build_store(
7070
&mut ctx.mir_ctx,
71-
&ctx.hir_ctx.type_storage,
71+
&ctx.hir_ctx.global_scope,
7272
ptr.clone(),
7373
val,
7474
)?;
@@ -121,7 +121,7 @@ pub fn lower_hir_variable_assignment(
121121

122122
let val = lower_hir_value(block, val, ctx)?;
123123

124-
variable_ref.write(block, &mut ctx.mir_ctx, val, &ctx.hir_ctx.type_storage)?;
124+
variable_ref.write(block, &mut ctx.mir_ctx, val, &ctx.hir_ctx.global_scope)?;
125125
return Ok(true);
126126
}
127127

0 commit comments

Comments
 (0)