Skip to content

Commit

Permalink
Use interior mutability in translaion contexts instead of passing mut…
Browse files Browse the repository at this point in the history
…able borrows everywhere.
  • Loading branch information
jhjourdan committed Feb 12, 2025
1 parent dde8c4c commit 63533f6
Show file tree
Hide file tree
Showing 30 changed files with 415 additions and 407 deletions.
74 changes: 74 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions creusot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tempdir = "0.3"
serde_json = "1.0"
lazy_static = "1.5"
pathdiff = "0.2"
once_map = "0.4"

[dev-dependencies]
clap = { version = "4.5", features = ["derive", "env"] }
Expand Down
9 changes: 5 additions & 4 deletions creusot/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
util::path_of_span,
};
use std::{
cell::RefCell,
ops::{Deref, DerefMut},
path::PathBuf,
};
Expand All @@ -33,9 +34,9 @@ pub(crate) mod ty_inv;
pub(crate) mod wto;

pub struct Why3Generator<'tcx> {
ctx: TranslationCtx<'tcx>,
pub ctx: TranslationCtx<'tcx>,
functions: Vec<TranslatedItem>,
pub(crate) span_map: SpanMap,
pub(crate) span_map: RefCell<SpanMap>,
}

impl<'tcx> Deref for Why3Generator<'tcx> {
Expand Down Expand Up @@ -96,10 +97,10 @@ impl<'tcx> Why3Generator<'tcx> {
matches!(self.item_type(item), ItemType::Logic { .. } | ItemType::Predicate { .. })
}

pub(crate) fn span_attr(&mut self, span: Span) -> Option<why3::declaration::Attribute> {
pub(crate) fn span_attr(&self, span: Span) -> Option<why3::declaration::Attribute> {
let path = path_of_span(self.tcx, span, &self.opts.span_mode)?;

if let Some(span) = self.span_map.encode_span(&self.ctx.opts, span) {
if let Some(span) = self.span_map.borrow_mut().encode_span(&self.ctx.opts, span) {
return Some(span);
};

Expand Down
Loading

0 comments on commit 63533f6

Please sign in to comment.