Skip to content

Commit 52e7053

Browse files
committed
feat: added branched contexts inside of HIR global scope
1 parent 1022eb9 commit 52e7053

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

compiler/astoir_hir/src/ctx.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use diagnostics::{
1212
use crate::{nodes::HIRNode, scope::HIRGlobalScopeStorage, structs::HIRStructContainer};
1313

1414
pub type HIRFunction = (Option<Type>, Vec<(u64, Type)>, String);
15+
pub type HIRFunctionImpl = (HIRBranchedContext, Box<HIRNode>);
1516

1617
/// The function HIR context. Contains a mapping from element name hash to element index and other variable information.
1718
/// Uses a branch based system to contain variables.

compiler/astoir_hir/src/scope.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ use compiler_global_scope::key::EntryKey;
44
use compiler_typing::{TypedGlobalScope, TypedGlobalScopeEntry, raw::RawType, tree::Type};
55
use diagnostics::{DiagnosticResult, DiagnosticSpanOrigin};
66

7-
use crate::{ctx::HIRFunction, nodes::HIRNode};
7+
use crate::{
8+
ctx::{HIRBranchedContext, HIRFunction, HIRFunctionImpl},
9+
nodes::HIRNode,
10+
};
811

912
/// The HIR version of `GlobalScopeStorage`. Contains the descriptors and implementations.
1013
/// Every function to append, gather will automatically handle descriptors and implementations if needed
1114
#[derive(Debug)]
1215
pub struct HIRGlobalScopeStorage {
1316
pub scope: TypedGlobalScope,
1417
pub descriptors: Vec<HIRFunction>,
15-
pub implementations: Vec<Box<HIRNode>>,
18+
pub implementations: Vec<HIRFunctionImpl>,
1619
}
1720

1821
impl HIRGlobalScopeStorage {
@@ -39,10 +42,11 @@ impl HIRGlobalScopeStorage {
3942
name: EntryKey,
4043
descriptor: HIRFunction,
4144
implementation: Box<HIRNode>,
45+
brctx: HIRBranchedContext,
4246
origin: &K,
4347
) -> DiagnosticResult<usize> {
4448
self.descriptors.push(descriptor);
45-
self.implementations.push(implementation);
49+
self.implementations.push((brctx, implementation));
4650

4751
self.scope.append(
4852
name,
@@ -74,11 +78,12 @@ impl HIRGlobalScopeStorage {
7478
name: EntryKey,
7579
descriptor: HIRFunction,
7680
implementation: Box<HIRNode>,
81+
brctx: HIRBranchedContext,
7782
struct_type: RawType,
7883
origin: &K,
7984
) -> DiagnosticResult<usize> {
8085
self.descriptors.push(descriptor);
81-
self.implementations.push(implementation);
86+
self.implementations.push((brctx, implementation));
8287

8388
let ind = self.scope.value_to_ind[&TypedGlobalScopeEntry::Type(struct_type)];
8489

@@ -151,7 +156,7 @@ impl HIRGlobalScopeStorage {
151156
&self,
152157
name: EntryKey,
153158
origin: &K,
154-
) -> DiagnosticResult<Box<HIRNode>> {
159+
) -> DiagnosticResult<HIRFunctionImpl> {
155160
let ind = self.scope.get_function_impl(name, origin)?;
156161

157162
return Ok(self.implementations[ind].clone());
@@ -171,7 +176,7 @@ impl HIRGlobalScopeStorage {
171176
&self,
172177
name: EntryKey,
173178
origin: &K,
174-
) -> DiagnosticResult<(HIRFunction, Box<HIRNode>)> {
179+
) -> DiagnosticResult<(HIRFunction, HIRFunctionImpl)> {
175180
let inds = self.scope.get_exact_function(name, origin)?;
176181

177182
return Ok((
@@ -184,7 +189,7 @@ impl HIRGlobalScopeStorage {
184189
&self,
185190
name: EntryKey,
186191
origin: &K,
187-
) -> DiagnosticResult<(HIRFunction, Box<HIRNode>, RawType)> {
192+
) -> DiagnosticResult<(HIRFunction, HIRFunctionImpl, RawType)> {
188193
let res = self.scope.get_exact_struct_function(name, origin)?;
189194

190195
return Ok((

0 commit comments

Comments
 (0)