Skip to content

Commit 7f6fa3a

Browse files
committed
Tweak more comments
1 parent ae0b428 commit 7f6fa3a

File tree

5 files changed

+29
-34
lines changed

5 files changed

+29
-34
lines changed

crates/ark/src/interface.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ pub struct RMain {
309309
/// consoles to get R to shut down
310310
read_console_shutdown: Cell<bool>,
311311

312-
/// Current topmost environment on the stack while waiting for input in ReadConsole
312+
/// Current topmost environment on the stack while waiting for input in ReadConsole.
313+
/// This is a RefCell since we require `get()` for this field and `RObject` isn't `Copy`.
313314
pub(crate) read_console_frame: RefCell<RObject>,
314315
}
315316

@@ -344,7 +345,6 @@ impl PendingInputs {
344345
let status = match harp::parse_status(&input) {
345346
Err(err) => {
346347
// Failed to even attempt to parse the input, something is seriously wrong
347-
// FIXME: There are some valid syntax errors going through here, e.g. `identity |> _(1)`.
348348
return Ok(ParseResult::SyntaxError(format!("{err}")));
349349
},
350350
Ok(status) => status,
@@ -353,7 +353,7 @@ impl PendingInputs {
353353
// - Incomplete inputs put R into a state where it expects more input that will never come, so we
354354
// immediately reject them. Positron should never send us these, but Jupyter Notebooks may.
355355
// - Complete statements are obviously fine.
356-
// - Syntax errors will cause R to throw an error, which is expected.
356+
// - Syntax errors will get bubbled up as R errors via an `ConsoleResult::Error`.
357357
let exprs = match status {
358358
harp::ParseResult::Complete(exprs) => exprs,
359359
harp::ParseResult::Incomplete => {
@@ -793,6 +793,7 @@ impl RMain {
793793
read_console_nested_return: Cell::new(false),
794794
read_console_threw_error: Cell::new(false),
795795
read_console_nested_return_next_input: Cell::new(None),
796+
// Can't use `R_ENVS.global` here as it isn't initialised yet
796797
read_console_frame: RefCell::new(RObject::new(unsafe { libr::R_GlobalEnv })),
797798
read_console_shutdown: Cell::new(false),
798799
}
@@ -956,16 +957,17 @@ impl RMain {
956957
// Clear any pending inputs, if any
957958
self.pending_inputs = None;
958959

959-
// Reply to active request with error
960+
// Reply to active request with error, then fall through to event loop
960961
self.handle_active_request(&info, ConsoleValue::Error(exception));
961962
} else if matches!(info.kind, PromptKind::InputRequest) {
962-
// Request input reply to the frontend and return it to R
963+
// Request input from the frontend and return it to R
963964
return self.handle_input_request(&info, buf, buflen);
964965
} else if let Some(input) = self.pop_pending() {
965966
// Evaluate pending expression if there is any remaining
966967
return self.handle_pending_input(input, buf, buflen);
967968
} else {
968-
// Otherwise reply to active request with accumulated result
969+
// Otherwise reply to active request with accumulated result, then
970+
// fall through to event loop
969971
let result = self.take_result();
970972
self.handle_active_request(&info, ConsoleValue::Success(result));
971973
}
@@ -1029,12 +1031,12 @@ impl RMain {
10291031
let tasks_interrupt_index = select.recv(&tasks_interrupt_rx);
10301032
let polled_events_index = select.recv(&polled_events_rx);
10311033

1032-
// Don't process idle tasks unless at top level. We currently don't want
1033-
// idle tasks (e.g. for srcref generation) to run when the call stack is
1034-
// not empty. We could make this configurable though if needed, i.e. some
1035-
// idle tasks would be able to run in the browser. Those should be sent
1036-
// to a dedicated channel that would always be included in the set of
1037-
// recv channels.
1034+
// Only process idle at top level. We currently don't want idle tasks
1035+
// (e.g. for srcref generation) to run when the call stack is not empty.
1036+
// We could make this configurable though if needed, i.e. some idle
1037+
// tasks would be able to run in the browser. Those should be sent to a
1038+
// dedicated channel that would always be included in the set of recv
1039+
// channels.
10381040
let tasks_idle_index = if matches!(info.kind, PromptKind::TopLevel) {
10391041
Some(select.recv(&tasks_idle_rx))
10401042
} else {
@@ -1175,8 +1177,7 @@ impl RMain {
11751177

11761178
if autoprint.ends_with('\n') {
11771179
// Remove the trailing newlines that R adds to outputs but that
1178-
// Jupyter frontends are not expecting. Is it worth taking a
1179-
// mutable self ref across calling methods to avoid the clone?
1180+
// Jupyter frontends are not expecting
11801181
autoprint.pop();
11811182
}
11821183
if autoprint.len() != 0 {
@@ -1249,9 +1250,6 @@ impl RMain {
12491250
Some(exception)
12501251
}
12511252

1252-
/// Returns:
1253-
/// - `None` if we should fall through to the event loop to wait for more user input
1254-
/// - `Some(ConsoleResult)` if we should immediately exit `read_console()`
12551253
fn handle_active_request(&mut self, info: &PromptInfo, value: ConsoleValue) {
12561254
// If we get here we finished evaluating all pending inputs. Check if we
12571255
// have an active request from a previous `read_console()` iteration. If
@@ -2423,7 +2421,8 @@ pub extern "C-unwind" fn r_read_console(
24232421
}
24242422

24252423
// We've finished evaluating a dummy value to reset state in R's REPL,
2426-
// and are now ready to evaluate the actual input
2424+
// and are now ready to evaluate the actual input, which is typically
2425+
// just `.ark_last_value`.
24272426
if let Some(next_input) = main.read_console_nested_return_next_input.take() {
24282427
RMain::on_console_input(buf, buflen, next_input).unwrap();
24292428
return 1;

crates/ark/src/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ fn main() -> anyhow::Result<()> {
8383
let mut capture_streams = true;
8484
let mut default_repos = DefaultRepos::Auto;
8585

86-
// We don't support the asking the user whether to save the workspace data
87-
// on exit because calling readline during shutdown puts in a precarious
88-
// position. So effectively we're implementing "no-save" by default.
89-
// Process remaining arguments. TODO: Need an argument that can passthrough args to R
9086
while let Some(arg) = argv.next() {
9187
match arg.as_str() {
9288
"--connection_file" => {

crates/ark/src/sys/unix/interface.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ pub fn setup_r(args: &Vec<String>) {
7373
libr::set(ptr_R_Busy, Some(r_busy));
7474
libr::set(ptr_R_Suicide, Some(r_suicide));
7575

76+
// Install a CleanUp hook for integration tests that test the shutdown process.
77+
// We confirm that shutdown occurs by waiting in the test until `CLEANUP_SIGNAL`'s
78+
// condition variable sends a notification, which occurs in this cleanup method
79+
// that is called during R's shutdown process.
7680
if stdext::IS_TESTING {
77-
use libr::ptr_R_CleanUp;
78-
79-
use crate::interface::r_cleanup_for_tests;
80-
81-
libr::set(ptr_R_CleanUp, Some(r_cleanup_for_tests));
81+
libr::set(
82+
libr::ptr_R_CleanUp,
83+
Some(crate::interface::r_cleanup_for_tests),
84+
);
8285
}
8386

8487
// In tests R may be run from various threads. This confuses R's stack

crates/ark/tests/kernel.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ use amalthea::wire::kernel_info_request::KernelInfoRequest;
55
use ark::fixtures::DummyArkFrontend;
66
use stdext::assert_match;
77

8-
// Avoids our global calling handler from rlangifying errors.
9-
// This causes some test instability across configs.
10-
118
#[test]
129
fn test_kernel_info() {
1310
let frontend = DummyArkFrontend::lock();
@@ -424,8 +421,8 @@ fn test_execute_request_error() {
424421

425422
#[test]
426423
fn test_execute_request_error_with_accumulated_output() {
427-
// Test that when the very last input output and then throws an error,
428-
// the accumulated output is flushed before the error is reported.
424+
// Test that when the very last input throws an error after producing
425+
// output, the accumulated output is flushed before the error is reported.
429426
// This tests the autoprint buffer flush logic in error handling.
430427
let frontend = DummyArkFrontend::lock();
431428

crates/harp/src/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ mod tests {
220220
Ok(ParseResult::Incomplete)
221221
);
222222

223-
// Error
223+
// Syntax error (error longjump thrown by parser)
224224
assert_match!(
225225
parse_status(&ParseInput::Text("42 + _")),
226226
Ok(ParseResult::SyntaxError { message }) => {
227227
assert!(message.contains("invalid use of pipe placeholder"));
228228
}
229229
);
230230

231-
// "normal" syntax error
231+
// Syntax error (error code returned by parser)
232232
assert_match!(
233233
parse_status(&ParseInput::Text("1+1\n*42")),
234234
Ok(ParseResult::SyntaxError { message }) => {

0 commit comments

Comments
 (0)