Skip to content

Commit

Permalink
Try to fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanuppal committed Dec 2, 2024
1 parent 154da35 commit c9591a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 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 calyx-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ string-interner.workspace = true
itertools.workspace = true
petgraph.workspace = true
symbol_table = { version = "0.3", features = ["global"] }
lazy_static.workspace = true
43 changes: 25 additions & 18 deletions calyx-utils/src/position.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
//! Definitions for tracking source position information of Calyx programs
use itertools::Itertools;
use std::{cmp, fmt::Write, mem, sync};
use lazy_static::lazy_static;
use std::{
cmp,
fmt::Write,
sync::{RwLock, RwLockWriteGuard},
};

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
/// Handle to a position in a [PositionTable]
Expand Down Expand Up @@ -99,28 +104,30 @@ impl PositionTable {
/// The global position table
pub struct GlobalPositionTable;

lazy_static! {
static ref GPOS_TABLE: RwLock<PositionTable> =
RwLock::new(PositionTable::default());
}

impl GlobalPositionTable {
/// Return reference to a global [PositionTable]
pub fn as_mut() -> &'static mut PositionTable {
static mut SINGLETON: mem::MaybeUninit<PositionTable> =
mem::MaybeUninit::uninit();
static ONCE: sync::Once = sync::Once::new();

// SAFETY:
// - writing to the singleton is OK because we only do it one time
// - the ONCE guarantees that SINGLETON is init'ed before assume_init_ref
unsafe {
ONCE.call_once(|| {
SINGLETON.write(PositionTable::new());
assert!(PositionTable::UNKNOWN == GPosIdx::UNKNOWN.0)
});
SINGLETON.assume_init_mut()
}
/// Return reference to a global [PositionTable].
///
/// # Safety
///
/// You may not call this function after any call to [`Self::as_ref`].
pub fn as_mut() -> RwLockWriteGuard<'static, PositionTable> {
GPOS_TABLE
.write()
.expect("failed to get write lock for global position table")
}

/// Return an immutable reference to the global position table
pub fn as_ref() -> &'static PositionTable {
Self::as_mut()
&*Box::leak(Box::new(
GPOS_TABLE
.read()
.expect("failed to get read lock for global position table"),
))
}
}

Expand Down

0 comments on commit c9591a1

Please sign in to comment.