Skip to content

Commit 694f1a7

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Return Result from Evaluator::enable_profile
Summary: Following diff D38527560 starts validating arguments/state. Reviewed By: bobyangyf Differential Revision: D38523949 fbshipit-source-id: 237d964d3db0f24da243129d89c9755e4dde9fcf
1 parent 7c2ffc9 commit 694f1a7

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed

starlark/src/environment/modules.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ mod tests {
506506
fn test_gen_heap_summary_profile() {
507507
let module = Module::new();
508508
let mut eval = Evaluator::new(&module);
509-
eval.enable_profile(&ProfileMode::HeapSummaryRetained);
509+
eval.enable_profile(&ProfileMode::HeapSummaryRetained)
510+
.unwrap();
510511
eval.eval_module(
511512
AstModule::parse(
512513
"x.star",

starlark/src/eval/runtime/evaluator.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<'v, 'a> Evaluator<'v, 'a> {
211211
/// Enable profiling, allowing [`Evaluator::write_profile`] to be used.
212212
/// Profilers add overhead, and while some profilers can be used together,
213213
/// it's better to run at most one profiler at a time.
214-
pub fn enable_profile(&mut self, mode: &ProfileMode) {
214+
pub fn enable_profile(&mut self, mode: &ProfileMode) -> anyhow::Result<()> {
215215
match mode {
216216
ProfileMode::HeapSummary
217217
| ProfileMode::HeapFlame
@@ -247,13 +247,14 @@ impl<'v, 'a> Evaluator<'v, 'a> {
247247
self.typecheck_profile.enabled = true;
248248
}
249249
}
250+
Ok(())
250251
}
251252

252253
/// Enable instrumentation in module which is loaded by a module to be profiled.
253254
///
254255
/// This function need to be called when evaluating a dependency of a module, if a module
255256
/// does profiling in the given mode.
256-
pub fn enable_profile_instrumentation(&mut self, mode: &ProfileMode) {
257+
pub fn enable_profile_instrumentation(&mut self, mode: &ProfileMode) -> anyhow::Result<()> {
257258
match mode {
258259
ProfileMode::Bytecode | ProfileMode::BytecodePairs => {
259260
self.bc_profile.enable_1();
@@ -270,6 +271,7 @@ impl<'v, 'a> Evaluator<'v, 'a> {
270271
}
271272
ProfileMode::Typecheck => {}
272273
}
274+
Ok(())
273275
}
274276

275277
/// Write a profile to a file.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ mod tests {
203203
let module = Module::new();
204204
let globals = Globals::standard();
205205
let mut eval = Evaluator::new(&module);
206-
eval.enable_profile(&ProfileMode::Bytecode);
206+
eval.enable_profile(&ProfileMode::Bytecode).unwrap();
207207
eval.eval_module(
208208
AstModule::parse("bc.star", "repr([1, 2])".to_owned(), &Dialect::Standard).unwrap(),
209209
&globals,
@@ -222,7 +222,7 @@ mod tests {
222222
let module = Module::new();
223223
let globals = Globals::standard();
224224
let mut eval = Evaluator::new(&module);
225-
eval.enable_profile(&ProfileMode::BytecodePairs);
225+
eval.enable_profile(&ProfileMode::BytecodePairs).unwrap();
226226
eval.eval_module(
227227
AstModule::parse("bc.star", "repr([1, 2])".to_owned(), &Dialect::Standard).unwrap(),
228228
&globals,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ f
113113
let globals = Globals::standard();
114114
let module = Module::new();
115115
let mut eval = Evaluator::new(&module);
116-
eval.enable_profile(&ProfileMode::HeapSummary);
116+
eval.enable_profile(&ProfileMode::HeapSummary).unwrap();
117117
let f = eval.eval_module(ast, &globals)?;
118118
// first check module profiling works
119119
HeapProfile::write_summarized_heap_profile(module.heap());
@@ -122,7 +122,7 @@ f
122122
// second check function profiling works
123123
let module = Module::new();
124124
let mut eval = Evaluator::new(&module);
125-
eval.enable_profile(&ProfileMode::HeapSummary);
125+
eval.enable_profile(&ProfileMode::HeapSummary).unwrap();
126126
eval.eval_function(f, &[Value::new_int(100)], &[])?;
127127
HeapProfile::write_summarized_heap_profile(module.heap());
128128
HeapProfile::write_flame_heap_profile(module.heap());
@@ -131,7 +131,7 @@ f
131131
let module = Module::new();
132132
let mut eval = Evaluator::new(&module);
133133
module.heap().alloc("Thing that goes before");
134-
eval.enable_profile(&ProfileMode::HeapSummary);
134+
eval.enable_profile(&ProfileMode::HeapSummary).unwrap();
135135
eval.eval_function(f, &[Value::new_int(100)], &[])?;
136136
module.heap().alloc("Thing that goes after");
137137
HeapProfile::write_summarized_heap_profile(module.heap());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ xx(*[2])
224224
&Dialect::Extended,
225225
)
226226
.unwrap();
227-
eval.enable_profile(&ProfileMode::Statement);
227+
eval.enable_profile(&ProfileMode::Statement).unwrap();
228228
let mut globals = GlobalsBuilder::standard();
229229
test_functions(&mut globals);
230230
eval.eval_module(module, &globals.build()).unwrap();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def g():
9292
g()
9393
"#;
9494
let program = AstModule::parse("test.star", program.to_owned(), &Dialect::Extended)?;
95-
eval.enable_profile(&ProfileMode::Typecheck);
95+
eval.enable_profile(&ProfileMode::Typecheck)?;
9696
eval.eval_module(program, &Globals::extended())?;
9797

9898
let csv = eval.typecheck_profile.gen_csv();

starlark/src/values/layout/heap/profile/summary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ _ignore = str([1]) # allocate a string in non_drop
200200
let globals = Globals::standard();
201201
let module = Module::new();
202202
let mut eval = Evaluator::new(&module);
203-
eval.enable_profile(&ProfileMode::HeapSummary);
203+
eval.enable_profile(&ProfileMode::HeapSummary).unwrap();
204204

205205
eval.eval_module(ast, &globals).unwrap();
206206

0 commit comments

Comments
 (0)