Skip to content

Conversation

@leon-xd
Copy link
Contributor

@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

Breaking Changes

  • Removes wdf_function_table.rs from generated code of WDK_BUILD. Users should access the function table instead via pointer at wdk_sys::WdfFunctions, and checking bounds via wdk_sys::wdf::get_wdf_function_count() which is generated in wdf_function_count.rs
  • lazy-static is no longer dependency in the workspace and is replaced with sync::LazyLock as introduced in Rust 1.83

closes #192

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

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 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

@wmmc88 wmmc88 changed the title chore: Remove lazy static instances refactor: Remove lazy static instances Dec 6, 2024
@wmmc88 wmmc88 requested a review from Copilot December 27, 2024 18:25
Copy link
Contributor

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()")

@wmmc88 wmmc88 self-assigned this Jan 10, 2025
Copy link
Collaborator

@wmmc88 wmmc88 left a comment

Choose a reason for hiding this comment

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

I really dislike adding a public api for the function count, since no such public api exists in the WDK, and i'd like for the sys crate to be purely the wdk apis. Ideally, the proc_macro should generate code that either dereferences the symbol OR uses the enum by conditionally compiling for the relevant cases. This essentially means turning the is_wdf_function_count_generated expression into a CFG.

This is currently not possible since:

  1. we do not expose WDF version number in EXPORTED_CFG_SETTINGS in emit_cfg_settings
  2. it would be very tedious and manual to cfg over all the supported values, since there is no rust cfg equivalent to UMDF_VERSION_MINOR > 1234. We would need to figure out a way to write a cfg in this fashion (is this even possible?)

I think those things are out of the scope of this PR, and the best we can do right now is hide the get_wdf_function_count api from the user and make it clear that it is subject to future removal once we've figured out the above.

@wmmc88
Copy link
Collaborator

wmmc88 commented Jan 15, 2025

I really dislike adding a public api for the function count, since no such public api exists in the WDK, and i'd like for the sys crate to be purely the wdk apis. Ideally, the proc_macro should generate code that either dereferences the symbol OR uses the enum by conditionally compiling for the relevant cases. This essentially means turning the is_wdf_function_count_generated expression into a CFG.

This is currently not possible since:

  1. we do not expose WDF version number in EXPORTED_CFG_SETTINGS in emit_cfg_settings
  2. it would be very tedious and manual to cfg over all the supported values, since there is no rust cfg equivalent to UMDF_VERSION_MINOR > 1234. We would need to figure out a way to write a cfg in this fashion (is this even possible?)

I think those things are out of the scope of this PR, and the best we can do right now is hide the get_wdf_function_count api from the user and make it clear that it is subject to future removal once we've figured out the above.

For more on #2, see https://users.rust-lang.org/t/cfg-w-arbitrary-expressions/109371

I think it may be possible to write a new attribute macro that expands into a cfg

@wmmc88 wmmc88 requested review from a team January 15, 2025 20:58
@leon-xd leon-xd changed the title refactor: Remove lazy static instances refactor!: Remove lazy static instances Jan 15, 2025
@leon-xd leon-xd requested a review from wmmc88 January 22, 2025 19:50
wmmc88
wmmc88 previously approved these changes Jan 22, 2025
hamzamust
hamzamust previously approved these changes Jan 30, 2025
@wmmc88 wmmc88 dismissed stale reviews from hamzamust and themself via c97de12 January 31, 2025 00:58
hamzamust
hamzamust previously approved these changes Jan 31, 2025
@wmmc88 wmmc88 enabled auto-merge January 31, 2025 01:03
@wmmc88 wmmc88 force-pushed the remove-lazy-static-instances branch from c97de12 to 4d4c2bf Compare January 31, 2025 01:19
wmmc88
wmmc88 previously approved these changes Jan 31, 2025
@wmmc88 wmmc88 dismissed stale reviews from hamzamust and themself via c4bda63 January 31, 2025 01:29
@wmmc88 wmmc88 force-pushed the remove-lazy-static-instances branch from 4d4c2bf to c4bda63 Compare January 31, 2025 01:29
wmmc88
wmmc88 previously approved these changes Jan 31, 2025
@wmmc88 wmmc88 force-pushed the remove-lazy-static-instances branch from c4bda63 to 2680313 Compare January 31, 2025 02:13
@wmmc88 wmmc88 added this pull request to the merge queue Jan 31, 2025
Merged via the queue into microsoft:main with commit 74e1087 Jan 31, 2025
62 checks passed
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.

Remove all lazy_static instances

3 participants