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

Implement lazy_static support #93

Merged
merged 2 commits into from
Jan 25, 2023
Merged

Conversation

jamesbornholt
Copy link
Member

This change adds support for the lazy_static crate. It's mostly built around a Once cell for each static plus some global storage.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This change adds support for the `lazy_static` crate. It's mostly built
around a `Once` cell for each static plus some global storage.
Copy link
Member

@jorajeev jorajeev left a comment

Choose a reason for hiding this comment

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

Looks good. One issue is that lazy_static does not run Drop methods on the type. However, this version will run the destructors.

We can either (1) alert users to this difference, or (2) do std::mem::forget on the value when we finish an execution?

@@ -414,3 +415,64 @@ macro_rules! __thread_local_inner {
};
}
}

/// Declare a new [lazy static value](crate::lazy_static::Lazy), like the `lazy_static` crate.
Copy link
Member

Choose a reason for hiding this comment

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

How about also adding lazy_static::initialize ? (Not that I've seen anyone ever using it...)

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually used this the other day, so added :-)

}

#[test]
fn mutex_dfs() {
Copy link
Member

Choose a reason for hiding this comment

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

Could you improve the test name, and add a comment -- this test checks that DFS will explore the N! interleavings during initialization?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, and ended up refactoring a little to share the two tests.

tests/basic/lazy_static.rs Outdated Show resolved Hide resolved
tests/basic/lazy_static.rs Show resolved Hide resolved
@jorajeev jorajeev merged commit 97e0396 into awslabs:main Jan 25, 2023
jorajeev pushed a commit that referenced this pull request Feb 29, 2024
* Implement `lazy_static` support

This change adds support for the `lazy_static` crate. It's mostly built
around a `Once` cell for each static plus some global storage.

* Generalize warnings and now warn on lazy_static drops
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