Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove lazy static instances #250

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

leon-xd
Copy link

@leon-xd leon-xd commented Dec 4, 2024

Replaced lazy static instances with std::sync::LazyLock in following locations:

  • crates/wdk-build/src/lib.rs
  • crates/wdk-sys/build.rs
  • tests/wdk-macros-tests/src/lib.rs

Replaced lazy static instances with custom FunctionTable struct in generated code in crates/wdk-sys/build.rs

@wmmc88 wmmc88 requested review from Copilot, NateD-MSFT and wmmc88 and removed request for NateD-MSFT December 5, 2024 00:58

Choose a reason for hiding this comment

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

Copilot reviewed 15 out of 17 changed files in this pull request and generated no suggestions.

Files not reviewed (2)
  • crates/wdk-sys/Cargo.toml: Evaluated as low risk
  • crates/wdk-build/Cargo.toml: Evaluated as low risk
crates/wdk-sys/build.rs Outdated Show resolved Hide resolved
crates/wdk-sys/build.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@wmmc88 wmmc88 changed the title chore: Remove lazy static instances refactor: Remove lazy static instances Dec 6, 2024
crates/wdk-build/src/lib.rs Show resolved Hide resolved
@@ -74,4 +74,4 @@ redundant_explicit_links = "warn"
unescaped_backticks = "warn"

[package.metadata.cargo-machete]
ignored = ["lazy_static"] # lazy_static is used in code generated by build.rs
Copy link
Collaborator

Choose a reason for hiding this comment

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

keep the comment

Copy link
Author

Choose a reason for hiding this comment

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

this entire line is gone -- there's no reference to lazy_static. why do we need to keep the comment?

Copy link
Collaborator

Choose a reason for hiding this comment

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

there is still a machete entry for once_cell. I want a comment documenting why machete needs to ignore once_cell (presumably because its only used in generated code that machete doesn't scan , resulting in a false positive).

Copy link
Collaborator

Choose a reason for hiding this comment

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

without the comment, machete fails, right?

Cargo.toml Outdated
@@ -45,7 +45,9 @@ cfg-if = "1.0.0"
clap = "4.5.9"
clap-cargo = "0.14.1"
itertools = "0.13.0"
lazy_static = "1.5.0"
once_cell = { version = "1.20.2", default-features = false, features = [
"alloc",
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm is alloc required here? this forces there to be an allocator pulled in always. packages without them would fail to compile

Copy link
Collaborator

Choose a reason for hiding this comment

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

To be addressed in separate issue: we should add some samples to the top level test that explicitly test this no alloc available case. The current examples all pull in wdk-alloc but samples should work without it still

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think as it stands, this pr breaks the pure no-std case

Copy link
Collaborator

Choose a reason for hiding this comment

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

@leon-xd this was marked as resolved, but i believe its still the case?

crates/wdk-sys/build.rs Outdated Show resolved Hide resolved
crates/wdk-sys/build.rs Outdated Show resolved Hide resolved
@wmmc88 wmmc88 requested a review from Copilot December 27, 2024 18:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 29 out of 44 changed files in this pull request and generated 1 comment.

Files not reviewed (15)
  • tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs: Evaluated as low risk
  • tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs: Evaluated as low risk
  • crates/wdk-sys/src/lib.rs: Evaluated as low risk
  • crates/wdk-build/Cargo.toml: Evaluated as low risk
  • Cargo.toml: Evaluated as low risk
  • crates/wdk-build/src/lib.rs: Evaluated as low risk
  • tests/wdk-macros-tests/Cargo.toml: Evaluated as low risk
  • crates/wdk-sys/src/wdf.rs: Evaluated as low risk
  • tests/wdk-macros-tests/src/lib.rs: Evaluated as low risk
  • crates/wdk-sys/Cargo.toml: Evaluated as low risk
  • crates/wdk-sys/build.rs: Evaluated as low risk
  • tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs: Evaluated as low risk
  • tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs: Evaluated as low risk
  • tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs: Evaluated as low risk
  • tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs: Evaluated as low risk
Comments suppressed due to low confidence (1)

tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs:30

  • [nitpick] The error message is too verbose. Consider simplifying it to: 'assertion failed: invalid function count size'.
::core::panicking::panic("assertion failed: isize::try_from(wdf_function_count *\n            core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()")

@@ -47,8 +47,26 @@ pub extern "system" fn driver_entry(
driver__: *mut WDFDRIVER,
) -> NTSTATUS {
let wdf_function: wdk_sys::PFN_WDFDRIVERCREATE = Some(unsafe {
let wdf_function_table = wdk_sys::WdfFunctions;
let wdf_function_count = wdk_sys::wdf::get_wdf_function_count();
if true {
Copy link
Preview

Copilot AI Dec 27, 2024

Choose a reason for hiding this comment

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

Redundant if true condition. This block can be simplified.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants