Apache DataFusion SQL Query Engine
refactor: replace `OnceLock` with `LazyLock` (#13641)
Jonah Gao9fbd87ff0353
diff --git a/datafusion/common/src/types/builtin.rs b/datafusion/common/src/types/builtin.rsindex c6105d37c3..ec69db7903 100644--- a/datafusion/common/src/types/builtin.rs+++ b/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 {- Arc::clone($name.get_or_init(|| Arc::new(NativeType::$ty)))+ Arc::clone(&$name)}};}diff --git a/datafusion/expr/src/logical_plan/statement.rs b/datafusion/expr/src/logical_plan/statement.rsindex a8b53e8a1f..93be04c275 100644--- a/datafusion/expr/src/logical_plan/statement.rs+++ b/datafusion/expr/src/logical_plan/statement.rs@@ -18,14 +18,10 @@use arrow::datatypes::DataType;use datafusion_common::{DFSchema, DFSchemaRef};use std::fmt::{self, Display};-use std::sync::{Arc, OnceLock};+use std::sync::{Arc, LazyLock};use crate::{expr_vec_fmt, Expr, LogicalPlan};-/// Statements have a unchanging empty schema.-/// TODO: Use `LazyLock` when MSRV is 1.80.0-static STATEMENT_EMPTY_SCHEMA: OnceLock<DFSchemaRef> = OnceLock::new();-/// Various types of Statements.////// # Transactions:@@ -54,7 +50,11 @@ pub enum Statement {impl Statement {/// Get a reference to the logical plan's schemapub fn schema(&self) -> &DFSchemaRef {- STATEMENT_EMPTY_SCHEMA.get_or_init(|| Arc::new(DFSchema::empty()))+ // Statements have an unchanging empty schema.+ static STATEMENT_EMPTY_SCHEMA: LazyLock<DFSchemaRef> =+ LazyLock::new(|| Arc::new(DFSchema::empty()));++ &STATEMENT_EMPTY_SCHEMA}/// Return a descriptive string describing the type of this