Skip to content

Commit a3420cf

Browse files
committed
fix: fixed some errors
1 parent 51e9199 commit a3420cf

13 files changed

Lines changed: 44 additions & 41 deletions

File tree

compiler/astoir_hir/src/ctx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
33
use std::collections::{HashMap, HashSet};
44

5-
use compiler_typing::{TypedGlobalScope, tree::Type};
5+
use compiler_typing::tree::Type;
66
use compiler_utils::{hash::SelfHash, utils::indexed::IndexStorage};
77
use diagnostics::{
88
DiagnosticResult, DiagnosticSpanOrigin,
99
builders::{make_cannot_find_func, make_cannot_find_var, make_doesnt_exist_in_era},
1010
};
1111

12-
use crate::{nodes::HIRNode, structs::HIRStructContainer};
12+
use crate::{nodes::HIRNode, scope::HIRGlobalScopeStorage, structs::HIRStructContainer};
1313

1414
pub type HIRFunction = (Option<Type>, Vec<(u64, Type)>, String);
1515

@@ -278,7 +278,7 @@ pub struct HIRContext {
278278
pub function_contexts: Vec<Option<HIRBranchedContext>>,
279279
pub static_variables: IndexStorage<Type>,
280280
pub struct_func_impls: HashMap<usize, HIRStructContainer>,
281-
pub global_scope: TypedGlobalScope,
281+
pub global_scope: HIRGlobalScopeStorage,
282282
}
283283

284284
#[derive(PartialEq)]
@@ -295,7 +295,7 @@ impl HIRContext {
295295
function_contexts: vec![],
296296
function_declarations: vec![],
297297
struct_func_impls: HashMap::new(),
298-
global_scope: TypedGlobalScope::new(),
298+
global_scope: HIRGlobalScopeStorage::new(),
299299
};
300300
}
301301

compiler/astoir_hir/src/nodes.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl HIRNode {
316316
return Ok(self.clone());
317317
}
318318

319-
if self_type.can_transmute(&t, &context.global_scope) {
319+
if self_type.can_transmute(&t, &context.global_scope.scope) {
320320
match &self.kind {
321321
HIRNodeKind::IntegerLiteral { value, int_type: _ } => {
322322
return Ok(self.with(HIRNodeKind::IntegerLiteral {
@@ -326,7 +326,7 @@ impl HIRNode {
326326
}
327327

328328
HIRNodeKind::ArrayVariableInitializerValue { vals } => {
329-
if can_transmute_inner(&self_type, &t, &context.global_scope) {
329+
if can_transmute_inner(&self_type, &t, &context.global_scope.scope) {
330330
let mut new_vals = vec![];
331331
let inner = t.get_inner_type();
332332

@@ -346,7 +346,7 @@ impl HIRNode {
346346
}
347347

348348
HIRNodeKind::ArrayVariableInitializerValueSameValue { size, val } => {
349-
if can_transmute_inner(&self_type, &t, &context.global_scope) {
349+
if can_transmute_inner(&self_type, &t, &context.global_scope.scope) {
350350
let new_val = Box::new(val.use_as(
351351
context,
352352
curr_ctx,
@@ -379,23 +379,23 @@ impl HIRNode {
379379
return Err(make_diff_type(
380380
origin,
381381
&"unnamed".to_string(),
382-
&t.faulty_lowering_generic(&context.global_scope),
382+
&t.faulty_lowering_generic(&context.global_scope.scope),
383383
&self
384384
.get_node_type(context, curr_ctx)
385385
.unwrap()
386-
.faulty_lowering_generic(&context.global_scope),
386+
.faulty_lowering_generic(&context.global_scope.scope),
387387
v,
388388
)
389389
.into());
390390
}
391391

392392
return Err(make_diff_type_val(
393393
origin,
394-
&t.faulty_lowering_generic(&context.global_scope),
394+
&t.faulty_lowering_generic(&context.global_scope.scope),
395395
&self
396396
.get_node_type(context, curr_ctx)
397397
.unwrap()
398-
.faulty_lowering_generic(&context.global_scope),
398+
.faulty_lowering_generic(&context.global_scope.scope),
399399
)
400400
.into());
401401
}

compiler/astoir_hir/src/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn resolve_to_type<K: DiagnosticSpanOrigin>(
2929
return Err(make_req_type_kind(origin, &"field-having".to_string()).into());
3030
}
3131

32-
for field in destination.get_fields(&context.global_scope) {
32+
for field in destination.get_fields(&context.global_scope.scope) {
3333
let identity = SelfHash { hash: field };
3434

3535
if !fields.contains_key(&identity) {
@@ -39,7 +39,7 @@ pub fn resolve_to_type<K: DiagnosticSpanOrigin>(
3939
let val = fields[&identity].clone();
4040

4141
let field_data = destination
42-
.get_field(&context.global_scope, field)?
42+
.get_field(&context.global_scope.scope, field)?
4343
.1
4444
.resolve(&destination);
4545

compiler/astoir_hir/src/scope.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
//! HIR version of the global scope in order to store descriptors and implementations
22
3-
use std::collections::btree_map::Entry;
4-
53
use compiler_global_scope::key::EntryKey;
6-
use compiler_typing::{
7-
TypedGlobalScope, TypedGlobalScopeEntry, bounds::traits, raw::RawType, tree::Type,
8-
};
4+
use compiler_typing::{TypedGlobalScope, TypedGlobalScopeEntry, raw::RawType, tree::Type};
95
use diagnostics::{DiagnosticResult, DiagnosticSpanOrigin};
106

117
use crate::{ctx::HIRFunction, nodes::HIRNode};
128

139
/// The HIR version of `GlobalScopeStorage`. Contains the descriptors and implementations.
1410
/// Every function to append, gather will automatically handle descriptors and implementations if needed
11+
#[derive(Debug)]
1512
pub struct HIRGlobalScopeStorage {
1613
pub scope: TypedGlobalScope,
1714
pub descriptors: Vec<HIRFunction>,

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.global_scope,
57+
&ctx.hir_ctx.global_scope.scope,
5858
index_pointer,
5959
val,
6060
)?;

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.global_scope),
47+
new_type.get_size(&new_type, false, &ctx.hir_ctx.global_scope.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.global_scope,
60+
&ctx.hir_ctx.global_scope.scope,
6161
ptr.clone(),
6262
casted,
6363
)?;

compiler/astoir_mir_lowering/src/lib.rs

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

108-
let parent = match &ctx.hir_ctx.global_scope.entries[container.parent].as_type_unsafe()
109-
{
110-
RawType::Enum(container) => container.clone(),
111-
_ => panic!("Enum parent not enum"),
112-
};
108+
let parent =
109+
match &ctx.hir_ctx.global_scope.scope.entries[container.parent].as_type_unsafe() {
110+
RawType::Enum(container) => container.clone(),
111+
_ => panic!("Enum parent not enum"),
112+
};
113113

114114
lowered_container
115115
.fields
@@ -158,7 +158,7 @@ pub fn lower_hir_generic(
158158
entry_size = entry_size.max(lowered.get_generic().get_size(
159159
&lowered,
160160
false,
161-
&ctx.hir_ctx.global_scope,
161+
&ctx.hir_ctx.global_scope.scope,
162162
))
163163
}
164164

compiler/astoir_mir_lowering/src/math.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn lower_hir_math_operation(
6262
block,
6363
&mut ctx.mir_ctx,
6464
val.clone(),
65-
&ctx.hir_ctx.global_scope,
65+
&ctx.hir_ctx.global_scope.scope,
6666
)?;
6767
}
6868

compiler/astoir_mir_lowering/src/type_tools.rs

Lines changed: 1 addition & 1 deletion
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.global_scope,
71+
&ctx.hir_ctx.global_scope.scope,
7272
),
7373
)?;
7474

compiler/astoir_mir_lowering/src/values/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn lower_hir_literal(
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.global_scope),
21+
int_type.get_size(&int_type, true, &ctx.hir_ctx.global_scope.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.global_scope),
30+
int_type.get_size(&int_type, true, &ctx.hir_ctx.global_scope.scope),
3131
)?;
3232

3333
return Ok(val.into());

0 commit comments

Comments
 (0)