Skip to content

Commit 0cb18fb

Browse files
committed
fix: added fixes for global scope
1 parent 7b5fa0b commit 0cb18fb

12 files changed

Lines changed: 35 additions & 24 deletions

File tree

compiler/astoir_hir/src/scope.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl HIRGlobalScopeStorage {
6666
name: EntryKey,
6767
descriptor: HIRFunction,
6868
brctx: HIRBranchedContext,
69+
origin: &K,
6970
) -> DiagnosticResult<usize> {
7071
self.descriptors.push(descriptor);
7172
self.contexts.push(brctx);

compiler/astoir_hir_lowering/src/func.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ pub fn lower_ast_function_declaration(
135135
context.global_scope.scope.entry_to_ind.remove(&key);
136136
context.global_scope.scope.value_to_ind.remove(&entry);
137137
context.global_scope.descriptors.pop();
138+
//context.global_scope.contexts.pop();
138139
context.global_scope.scope.descriptor_counter -= 1;
140+
//context.global_scope.scope.ctx_counter -= 1;
139141

140142
// Append the new verison as a impl-containing function
141143

compiler/astoir_mir/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ pub fn build_call(
838838
ind: usize,
839839
args: Vec<BaseMIRValue>,
840840
) -> DiagnosticResult<Option<BaseMIRValue>> {
841-
let func = &ctx.functions[func];
841+
let func = &ctx.functions[&func];
842842

843843
for (arg, t) in args.iter().zip(func.arguments.iter()) {
844844
if !arg.vtype.is_truly_eq(t) {

compiler/astoir_mir/src/ctx.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
};
1717

1818
pub struct MIRContext {
19-
pub functions: Vec<MIRFunction>,
19+
pub functions: HashMap<usize, MIRFunction>,
2020
pub blocks: Vec<MIRBlock>,
2121

2222
pub block_to_func: HashMap<usize, usize>,
@@ -29,7 +29,7 @@ pub struct MIRContext {
2929
impl MIRContext {
3030
pub fn new() -> Self {
3131
MIRContext {
32-
functions: vec![],
32+
functions: HashMap::new(),
3333
ssa_hints: HintStorage::new(),
3434
blocks: vec![],
3535
writer: InstructionWriterPosition {
@@ -45,7 +45,7 @@ impl MIRContext {
4545

4646
self.blocks.push(MIRBlock::new(ind));
4747

48-
self.functions[func].blocks.push(ind);
48+
self.functions.get_mut(&func).unwrap().blocks.push(ind);
4949

5050
self.block_to_func.insert(ind, func);
5151

@@ -67,11 +67,10 @@ impl MIRContext {
6767
}
6868

6969
pub fn append_function(&mut self, func: MIRFunction) -> usize {
70-
let ind = self.functions.len();
70+
let id = func.id;
71+
self.functions.insert(id, func);
7172

72-
self.functions.push(func);
73-
74-
return ind;
73+
return id;
7574
}
7675

7776
pub fn append_inst(&mut self, inst: MIRInstruction) -> InstructionValue {
@@ -156,7 +155,7 @@ impl MIRContext {
156155
impl Display for MIRContext {
157156
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
158157
for func in &self.functions {
159-
writeln!(f, "{}", func)?;
158+
writeln!(f, "{}", func.1)?;
160159
}
161160

162161
for block in &self.blocks {

compiler/astoir_mir/src/funcs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ impl MIRFunction {
3131
arguments: Vec<Type>,
3232
return_type: Option<Type>,
3333
is_from_struct: bool,
34-
ctx: &MIRContext,
34+
id: usize,
3535
) -> Self {
3636
return MIRFunction {
3737
blocks: vec![],
3838
name: HashedString::new(name),
3939
arguments,
4040
return_type,
4141
is_from_struct,
42-
id: ctx.functions.len(),
42+
id,
4343
};
4444
}
4545

compiler/astoir_mir/src/insts/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl MIRInstruction {
294294
function,
295295
arguments: _,
296296
} => {
297-
let func = &ctx.functions[*function];
297+
let func = &ctx.functions[function];
298298

299299
return func.return_type.is_some();
300300
}
@@ -476,7 +476,7 @@ impl MIRInstruction {
476476
function,
477477
arguments: _,
478478
} => {
479-
let func = &ctx.functions[*function];
479+
let func = &ctx.functions[function];
480480

481481
return func.return_type.clone().unwrap();
482482
}

compiler/astoir_mir_lowering/src/funcs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn lower_hir_function_decl(
6262

6363
let name = fns.2.clone();
6464

65-
let mut func = MIRFunction::new(name, args, ret_type, requires_this, &cctx.mir_ctx);
65+
let mut func = MIRFunction::new(name, args, ret_type, requires_this, func_name);
6666
let block = func.append_entry_block(&mut cctx.mir_ctx);
6767

6868
cctx.mir_ctx.writer.move_end(block);
@@ -132,7 +132,7 @@ pub fn lower_hir_shadow_decl(
132132
ret_type = None
133133
}
134134

135-
let func = MIRFunction::new(name, args, ret_type, false, &ctx.mir_ctx);
135+
let func = MIRFunction::new(name, args, ret_type, false, func_name);
136136

137137
ctx.mir_ctx.append_function(func);
138138
return Ok(true);

compiler/astoir_mir_lowering/src/introductions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn handle_var_introduction_queue(
4747
}
4848
};
4949

50-
let fns = &ctx.hir_ctx.global_scope.implementations[*fns_ind].0;
50+
let fns = &ctx.hir_ctx.global_scope.contexts[*fns_ind];
5151

5252
let eligible = fns.is_eligible_for_ssa(new_var);
5353

compiler/astoir_mir_lowering/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use astoir_hir::{
66
};
77
use astoir_mir::{ctx::MIRContext, funcs::MIRFunction};
88
use compiler_typing::{
9-
SizedType, TypedGlobalScope, TypedGlobalScopeEntry, raw::RawType,
10-
structs::LoweredStructTypeContainer, tree::Type,
9+
SizedType, TypedGlobalScopeEntry, raw::RawType, structs::LoweredStructTypeContainer, tree::Type,
1110
};
1211
use compiler_utils::utils::indexed::IndexStorage;
1312
use diagnostics::{DiagnosticResult, unsure_panic};
@@ -62,9 +61,7 @@ pub fn lower_hir(ctx: HIRContext) -> DiagnosticResult<MIRContext> {
6261
descriptor_ind: _,
6362
impl_ind,
6463
} => {
65-
let node = lowering_ctx.hir_ctx.global_scope.implementations[impl_ind]
66-
.1
67-
.clone();
64+
let node = lowering_ctx.hir_ctx.global_scope.implementations[impl_ind].clone();
6865

6966
lower_hir_top_level(node, &mut lowering_ctx)?;
7067
}
@@ -95,7 +92,7 @@ pub fn lower_hir(ctx: HIRContext) -> DiagnosticResult<MIRContext> {
9592
ret_type = None
9693
}
9794

98-
let func = MIRFunction::new(name, args, ret_type, false, &mut lowering_ctx.mir_ctx);
95+
let func = MIRFunction::new(name, args, ret_type, false, entry.parent_index);
9996

10097
lowering_ctx.mir_ctx.append_function(func);
10198
}

compiler/astoir_mir_lowering/src/vars.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ pub fn lower_hir_variable_declaration(
3838
} => impl_ind,
3939

4040
_ => {
41+
println!("Curr entry: {}", func);
42+
println!("Entry dump: ");
43+
44+
for entry in ctx.hir_ctx.global_scope.scope.entries.clone() {
45+
println!("- {:#?}", entry);
46+
}
47+
4148
return Err(make_expected_simple_error_originless(
4249
&"function".to_string(),
4350
&ctx.hir_ctx.global_scope.scope.entries[func].entry_type,
@@ -46,7 +53,7 @@ pub fn lower_hir_variable_declaration(
4653
}
4754
};
4855

49-
let local_ctx = ctx.hir_ctx.global_scope.contexts[*fns_ind].0.clone();
56+
let local_ctx = ctx.hir_ctx.global_scope.contexts[*fns_ind].clone();
5057

5158
if local_ctx.is_eligible_for_ssa(variable) {
5259
if default_val.is_some() {

0 commit comments

Comments
 (0)