You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jonahgao (via GitHub)" <gi...@apache.org> on 2024/12/04 08:50:23 UTC

[PR] refactor: replace `OnceLock` with `LazyLock` [datafusion]

jonahgao opened a new pull request, #13641:
URL: https://github.com/apache/datafusion/pull/13641

   ## Which issue does this PR close?
   
   Clear the TODOs after updating MSRV to 1.80.
   
   
   ## Rationale for this change
   `LazyLock` has been [stable](https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html#lazycell-and-lazylock) since Rust version 1.80.0, and it provides a simpler and more suitable way to define static variables.
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   Yes. By existing tests.
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   No
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: replace `OnceLock` with `LazyLock` [datafusion]

Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao commented on code in PR #13641:
URL: https://github.com/apache/datafusion/pull/13641#discussion_r1869009027


##########
datafusion/common/src/types/builtin.rs:
##########
@@ -16,17 +16,17 @@
 // under the License.
 
 use crate::types::{LogicalTypeRef, NativeType};
-use std::sync::{Arc, OnceLock};
+use std::sync::{Arc, LazyLock};
 
 macro_rules! singleton {
     ($name:ident, $getter:ident, $ty:ident) => {
-        // TODO: Use LazyLock instead of getter function when MSRV gets bumped
-        static $name: OnceLock<LogicalTypeRef> = OnceLock::new();
+        static $name: LazyLock<LogicalTypeRef> =
+            LazyLock::new(|| Arc::new(NativeType::$ty));
 
         #[doc = "Getter for singleton instance of a logical type representing"]
         #[doc = concat!("[`NativeType::", stringify!($ty), "`].")]
         pub fn $getter() -> LogicalTypeRef {

Review Comment:
   Not sure how to evolve this getter function because it hasn't been used anywhere yet.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: replace `OnceLock` with `LazyLock` [datafusion]

Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao commented on PR #13641:
URL: https://github.com/apache/datafusion/pull/13641#issuecomment-2518924963

   Thanks @alamb @comphead . I plan to handle the remaining `OnceLock`s.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: replace `OnceLock` with `LazyLock` [datafusion]

Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao commented on code in PR #13641:
URL: https://github.com/apache/datafusion/pull/13641#discussion_r1869009027


##########
datafusion/common/src/types/builtin.rs:
##########
@@ -16,17 +16,17 @@
 // under the License.
 
 use crate::types::{LogicalTypeRef, NativeType};
-use std::sync::{Arc, OnceLock};
+use std::sync::{Arc, LazyLock};
 
 macro_rules! singleton {
     ($name:ident, $getter:ident, $ty:ident) => {
-        // TODO: Use LazyLock instead of getter function when MSRV gets bumped
-        static $name: OnceLock<LogicalTypeRef> = OnceLock::new();
+        static $name: LazyLock<LogicalTypeRef> =
+            LazyLock::new(|| Arc::new(NativeType::$ty));
 
         #[doc = "Getter for singleton instance of a logical type representing"]
         #[doc = concat!("[`NativeType::", stringify!($ty), "`].")]
         pub fn $getter() -> LogicalTypeRef {

Review Comment:
   Not sure how to evolve this getter function because it hasn't been used anywhere yet.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: replace `OnceLock` with `LazyLock` [datafusion]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead merged PR #13641:
URL: https://github.com/apache/datafusion/pull/13641


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: replace `OnceLock` with `LazyLock` [datafusion]

Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao commented on code in PR #13641:
URL: https://github.com/apache/datafusion/pull/13641#discussion_r1869044427


##########
datafusion/common/src/types/builtin.rs:
##########
@@ -16,17 +16,17 @@
 // under the License.
 
 use crate::types::{LogicalTypeRef, NativeType};
-use std::sync::{Arc, OnceLock};
+use std::sync::{Arc, LazyLock};
 
 macro_rules! singleton {
     ($name:ident, $getter:ident, $ty:ident) => {
-        // TODO: Use LazyLock instead of getter function when MSRV gets bumped
-        static $name: OnceLock<LogicalTypeRef> = OnceLock::new();
+        static $name: LazyLock<LogicalTypeRef> =
+            LazyLock::new(|| Arc::new(NativeType::$ty));
 
         #[doc = "Getter for singleton instance of a logical type representing"]
         #[doc = concat!("[`NativeType::", stringify!($ty), "`].")]
         pub fn $getter() -> LogicalTypeRef {

Review Comment:
   Current callers require a `LogicalTypeRef`, so this getter still seems to be needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] refactor: replace `OnceLock` with `LazyLock` [datafusion]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #13641:
URL: https://github.com/apache/datafusion/pull/13641#issuecomment-2518016884

   Thats good point, wondering we probably want to use LazyLock in documentation generation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org