Skip to content

Commit 38ecd04

Browse files
committed
refactor!(static memory allocation): Remove option to share allocs
Remove unused the option to share static memory allocated values. This option (read: abomination) was used neither in this repo, nor in the downstreams `tasm-lang` or `neptune-core`. So I think it's fine just to delete it.
1 parent 6464ac6 commit 38ecd04

File tree

1 file changed

+1
-30
lines changed

1 file changed

+1
-30
lines changed

tasm-lib/src/library.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ pub struct Library {
2929
/// Imported dependencies.
3030
seen_snippets: HashMap<String, Vec<LabelledInstruction>>,
3131

32-
/// Known, and thus shareable, (static) memory allocations. Includes both their address and
33-
/// their size.
34-
pub_allocations: HashMap<String, (BFieldElement, u32)>,
35-
3632
/// The number of statically allocated words
3733
num_allocated_words: u32,
3834
}
@@ -51,7 +47,6 @@ impl Library {
5147
pub fn new() -> Self {
5248
Self {
5349
seen_snippets: HashMap::default(),
54-
pub_allocations: HashMap::default(),
5550
num_allocated_words: 0,
5651
}
5752
}
@@ -130,6 +125,7 @@ impl Library {
130125
/// Statically allocate `num_words` words of memory. Panics if more static
131126
/// memory is required than what the capacity allows for.
132127
pub fn kmalloc(&mut self, num_words: u32) -> BFieldElement {
128+
assert!(num_words > 0, "must allocate a positive number of words");
133129
let address = STATIC_MEMORY_FIRST_ADDRESS
134130
- bfe!(self.num_allocated_words)
135131
- BFieldElement::new(num_words as u64 - 1);
@@ -140,24 +136,6 @@ impl Library {
140136

141137
address
142138
}
143-
144-
/// Statically allocate `num_words` words of memory and give it a name.
145-
/// Allows sharing the allocation with other snippets.
146-
pub fn pub_kmalloc(&mut self, num_words: u32, name: String) -> BFieldElement {
147-
let address = self.kmalloc(num_words);
148-
if let Some((addr, size)) = self
149-
.pub_allocations
150-
.insert(name.clone(), (address, num_words))
151-
{
152-
panic!("Public kmalloc for \"{name}\" overwrote previous allocation: ({addr}, {size})");
153-
};
154-
address
155-
}
156-
157-
/// Get the address and size of a public allocation.
158-
pub fn get_pub_allocation(&self, name: &str) -> (BFieldElement, u32) {
159-
self.pub_allocations[name]
160-
}
161139
}
162140

163141
#[derive(Debug)]
@@ -496,12 +474,5 @@ mod tests {
496474

497475
let third_free_address = lib.kmalloc(1000);
498476
assert_eq!(-BFieldElement::new(1009), third_free_address);
499-
500-
let fourth_free_address = lib.pub_kmalloc(10_000, "my_thing".to_string());
501-
assert_eq!(-BFieldElement::new(11_009), fourth_free_address);
502-
503-
let (address, size) = lib.get_pub_allocation("my_thing");
504-
assert_eq!(fourth_free_address, address);
505-
assert_eq!(10_000, size);
506477
}
507478
}

0 commit comments

Comments
 (0)