Skip to content

Commit 1e04e8c

Browse files
JakobDegenmeta-codesync[bot]
authored andcommitted
lifetimes: Reuse Heap for some modules in a test
Summary: This is representative of the issue - this test allocates a starlark value using one heap and then references that starlark value from other heaps. When we started branding the modules (future diff) that stopped compiling. Fix this by using the same heap for all three modules Reviewed By: ship-it-ship-it Differential Revision: D90475056 fbshipit-source-id: 27db72115f95b662d4c0f41cf5cf59b46ca1698b
1 parent e20bcdd commit 1e04e8c

File tree

1 file changed

+36
-35
lines changed
  • starlark/src/eval/runtime/profile

1 file changed

+36
-35
lines changed

starlark/src/eval/runtime/profile/heap.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ mod tests {
269269
use crate::eval::runtime::profile::mode::ProfileMode;
270270
use crate::syntax::AstModule;
271271
use crate::syntax::Dialect;
272+
use crate::values::Heap;
272273
use crate::values::Value;
273274

274275
#[test]
@@ -286,41 +287,41 @@ f
286287
&Dialect::AllOptionsInternal,
287288
)?;
288289
let globals = Globals::standard();
289-
Module::with_temp_heap(|module| {
290-
Module::with_temp_heap(|module2| {
291-
Module::with_temp_heap(|module3| {
292-
let mut eval = Evaluator::new(&module);
293-
eval.enable_profile(&ProfileMode::HeapSummaryAllocated)
294-
.unwrap();
295-
let f = eval.eval_module(ast, &globals)?;
296-
297-
// first check module profiling works
298-
HeapProfile::write_summarized_heap_profile(module.heap());
299-
HeapProfile::write_flame_heap_profile(module.heap());
300-
301-
// second check function profiling works
302-
let mut eval = Evaluator::new(&module2);
303-
eval.enable_profile(&ProfileMode::HeapSummaryAllocated)
304-
.unwrap();
305-
eval.eval_function(f, &[Value::testing_new_int(100)], &[])?;
306-
307-
HeapProfile::write_summarized_heap_profile(module2.heap());
308-
HeapProfile::write_flame_heap_profile(module2.heap());
309-
310-
// finally, check a user can add values into the heap before/after
311-
let mut eval = Evaluator::new(&module3);
312-
module3.heap().alloc("Thing that goes before");
313-
eval.enable_profile(&ProfileMode::HeapSummaryAllocated)
314-
.unwrap();
315-
eval.eval_function(f, &[Value::testing_new_int(100)], &[])?;
316-
317-
module3.heap().alloc("Thing that goes after");
318-
HeapProfile::write_summarized_heap_profile(module3.heap());
319-
HeapProfile::write_flame_heap_profile(module3.heap());
320-
321-
Ok(())
322-
})
323-
})
290+
Heap::temp(|heap| {
291+
let module = Module::with_heap(heap);
292+
let module2 = Module::with_heap(heap);
293+
let module3 = Module::with_heap(heap);
294+
295+
let mut eval = Evaluator::new(&module);
296+
eval.enable_profile(&ProfileMode::HeapSummaryAllocated)
297+
.unwrap();
298+
let f = eval.eval_module(ast, &globals)?;
299+
300+
// first check module profiling works
301+
HeapProfile::write_summarized_heap_profile(module.heap());
302+
HeapProfile::write_flame_heap_profile(module.heap());
303+
304+
// second check function profiling works
305+
let mut eval = Evaluator::new(&module2);
306+
eval.enable_profile(&ProfileMode::HeapSummaryAllocated)
307+
.unwrap();
308+
eval.eval_function(f, &[Value::testing_new_int(100)], &[])?;
309+
310+
HeapProfile::write_summarized_heap_profile(module2.heap());
311+
HeapProfile::write_flame_heap_profile(module2.heap());
312+
313+
// finally, check a user can add values into the heap before/after
314+
let mut eval = Evaluator::new(&module3);
315+
module3.heap().alloc("Thing that goes before");
316+
eval.enable_profile(&ProfileMode::HeapSummaryAllocated)
317+
.unwrap();
318+
eval.eval_function(f, &[Value::testing_new_int(100)], &[])?;
319+
320+
module3.heap().alloc("Thing that goes after");
321+
HeapProfile::write_summarized_heap_profile(module3.heap());
322+
HeapProfile::write_flame_heap_profile(module3.heap());
323+
324+
Ok(())
324325
})
325326
}
326327
}

0 commit comments

Comments
 (0)