Skip to content

Misc cleanup: pub(crate) mock fields, log_println allow, current_processor_number, stdin guard#755

Open
wdcui wants to merge 1 commit intomainfrom
wdcui/pr3e-misc-cleanup
Open

Misc cleanup: pub(crate) mock fields, log_println allow, current_processor_number, stdin guard#755
wdcui wants to merge 1 commit intomainfrom
wdcui/pr3e-misc-cleanup

Conversation

@wdcui
Copy link
Copy Markdown
Member

@wdcui wdcui commented Apr 7, 2026

Summary

  • Make MockPlatform fields pub(crate) instead of fully public, since the mock is only used within the crate's test infrastructure.
  • Add #[allow(unused_imports)] for log_println! macro import (used conditionally).
  • Add current_processor_number() to SystemInfoProvider with a default returning 0, for getcpu-family syscall emulation.
  • Add a Drop guard to MockPlatform::read_stdin() to clear the stdin buffer on return.

Split from #743.

…essor_number, stdin guard

Small independent cleanups:

- Make MockInstant::time and MockSystemTime::time pub(crate) so tests
  in other modules can construct instances with specific values.
- Add #[allow(unused_imports)] to log_println! macro use-statements to
  suppress warnings when the macro is invoked in contexts where the
  import is redundant.
- Add SystemInfoProvider::current_processor_number() default method
  returning 0, for platforms that don't expose processor topology.
- Add empty-buffer early return in MockPlatform::read_from_stdin() to
  avoid unnecessarily consuming queued input on zero-length reads.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

@jaybosamiya-ms jaybosamiya-ms added the expmt:shadow-kiln Tag to quickly find the different PRs as part of the "shadow kiln" experiment. label Apr 11, 2026
Comment on lines 213 to +233
@@ -230,7 +230,7 @@ impl Instant for MockInstant {
}

pub(crate) struct MockSystemTime {
time: u64,
pub(crate) time: u64,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually making them from private into crate-public, which contradicts the claim in the PR description. I don't understand why this change is done/needed.

Comment on lines +26 to +32
#[allow(unused_imports)]
use $crate::platform::DebugLogProvider as _;
$platform.debug_log_print($s);
}};
($platform:expr, $($tt:tt)*) => {{
use core::fmt::Write as _;
#[allow(unused_imports)]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why these unused_imports are being marked as allow here. Is there a use case that actually breaks if you don't put the allow?

This part of the change is fine to keep btw, no issue specifically due to the exact scenario it is in (i.e., a macro in a logging utility), but more broadly, introducing allows is a code smell.

Comment on lines +671 to +680

/// Returns the current processor number, used to emulate `getcpu`-family
/// syscalls and related VDSO interfaces.
///
/// Platforms that do not expose a stable processor identifier, or that
/// virtualize CPU topology, may return `0`. Callers arrive in subsequent
/// stacked PRs.
fn current_processor_number(&self) -> u32 {
0
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are allowing platforms to just give 0, are there scenarios where it matters that we are accurate? Why can't the shim just assume 0 always? Otherwise, this will lead to making the interface wider unnecessarily.

Also, same comment as in other PRs, doc strings should not mention "subsequent stacked PRs" and such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

expmt:shadow-kiln Tag to quickly find the different PRs as part of the "shadow kiln" experiment.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants