Skip to content

Commit

Permalink
fix: it is not strong one ref now
Browse files Browse the repository at this point in the history
  • Loading branch information
RanolP committed Nov 14, 2023
1 parent 8a72dfb commit b599e95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions crates/psl/src/codegen/context.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use std::hash::Hash;
use std::{
cell::{Ref, RefCell},
hash::Hash,
rc::Rc,
};

use super::{construct::Scope, pass::NamesResolved};

pub struct CodegenContext {
name_resolution: NamesResolved,
name_resolution: Rc<RefCell<NamesResolved>>,
}

impl CodegenContext {
pub fn new(resolution: NamesResolved) -> CodegenContext {
pub fn new(resolution: Rc<RefCell<NamesResolved>>) -> CodegenContext {

Check warning on line 14 in crates/psl/src/codegen/context.rs

View check run for this annotation

Codecov / codecov/patch

crates/psl/src/codegen/context.rs#L14

Added line #L14 was not covered by tests
CodegenContext {
name_resolution: resolution,

Check warning on line 16 in crates/psl/src/codegen/context.rs

View check run for this annotation

Codecov / codecov/patch

crates/psl/src/codegen/context.rs#L16

Added line #L16 was not covered by tests
}
}

pub fn scope<T: Hash + 'static>(&self, node: &T) -> &Scope {
self.name_resolution.get(node).unwrap()
pub fn scope<T: Hash + 'static>(&self, node: &T) -> Ref<Scope> {
Ref::map(self.name_resolution.borrow(), |root| {
root.get(node).unwrap()
})

Check warning on line 23 in crates/psl/src/codegen/context.rs

View check run for this annotation

Codecov / codecov/patch

crates/psl/src/codegen/context.rs#L20-L23

Added lines #L20 - L23 were not covered by tests
}
}
4 changes: 2 additions & 2 deletions crates/psl/src/codegen/pass/name_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ impl NameResolutionContext {
})
}

Check warning on line 100 in crates/psl/src/codegen/pass/name_resolution.rs

View check run for this annotation

Codecov / codecov/patch

crates/psl/src/codegen/pass/name_resolution.rs#L96-L100

Added lines #L96 - L100 were not covered by tests

pub fn finish(self) -> NamesResolved {
Rc::into_inner(self.root).unwrap().into_inner()
pub fn finish(self) -> Rc<RefCell<NamesResolved>> {
self.root
}

Check warning on line 104 in crates/psl/src/codegen/pass/name_resolution.rs

View check run for this annotation

Codecov / codecov/patch

crates/psl/src/codegen/pass/name_resolution.rs#L102-L104

Added lines #L102 - L104 were not covered by tests
}

Expand Down

0 comments on commit b599e95

Please sign in to comment.