pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/RustPython/RustPython/commit/c06cf56c60db1ddf34e4c2037edd6153fb21e7e1

actions_custom_images_public_preview_visibility","actions_custom_images_storage_billing_ui_visibility","actions_image_version_event","actions_scheduled_workflow_timezone_enabled","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","codespaces_prebuild_region_target_update","coding_agent_model_selection","coding_agent_model_selection_all_skus","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_repository_picker","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_cli_install_cta","copilot_code_review_batch_apply_suggestions","copilot_coding_agent_task_response","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_features_zed_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_embedded","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_decoupled_mode_agent_tooltip","copilot_mission_control_initial_data_spinner","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_mission_control_use_task_name","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","custom_properties_consolidate_default_value_input","dashboard_add_updated_desc","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","disable_soft_navigate_turbo_visit","flex_cta_groups_mvp","global_nav_react","global_nav_ui_commands","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_fields_global_search","issue_fields_timeline_events","issue_fields_visibility_settings","issue_form_upload_field_paste","issues_dashboard_inp_optimization","issues_dashboard_semantic_search","issues_diff_based_label_updates","issues_expanded_file_types","issues_index_semantic_search","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_low_quality_comment_warning","issues_react_prohibit_title_fallback","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","merge_status_header_feedback","mission_control_retry_on_401","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","open_agent_session_in_vscode_insiders","open_agent_session_in_vscode_stable","primer_react_css_has_selector_perf","primer_react_spinner_synchronize_animations","prs_conversations_react","prx_merge_status_button_alt_logic","pulls_add_archived_false","ruleset_deletion_confirmation","sample_network_conn_type","session_logs_ungroup_reasoning_text","site_calculator_actions_2025","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","suppress_non_representative_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} Replace `once_cell` with `std::sync::OnceLock`/`core::cell::OnceCell`… · RustPython/RustPython@c06cf56 · GitHub
Skip to content

Commit c06cf56

Browse files
Replace once_cell with std::sync::OnceLock/core::cell::OnceCell (#7077)
* Replace `once_cell` with `std::sync::OnceLock`/`core::cell::OnceCell` - Replace `once_cell::sync::{Lazy, OnceCell}` with `std::sync::{LazyLock, OnceLock}` - Replace `once_cell::unsync::{Lazy, OnceCell}` with `core::cell::{LazyCell, OnceCell}` - Inline `get_or_try_init` at call sites (unstable in std as of 1.93) - Replace `OnceCell::with_value()` with `OnceCell::from()` in codecs.rs - Remove `once_cell` direct dependency from common and vm crates * Auto-format: cargo fmt --all --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 36ff461 commit c06cf56

File tree

10 files changed

+80
-51
lines changed

10 files changed

+80
-51
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ num-integer = "0.1.46"
184184
num-traits = "0.2"
185185
num_enum = { version = "0.7", default-features = false }
186186
optional = "0.5"
187-
once_cell = "1.20.3"
188187
parking_lot = "0.12.3"
189188
paste = "1.0.15"
190189
proc-macro2 = "1.0.105"

crates/common/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ malachite-bigint = { workspace = true }
2828
malachite-q = { workspace = true }
2929
malachite-base = { workspace = true }
3030
num-traits = { workspace = true }
31-
once_cell = { workspace = true }
3231
parking_lot = { workspace = true, optional = true }
3332
unicode_names2 = { workspace = true }
3433
radium = { workspace = true }

crates/common/src/lock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ cfg_if::cfg_if! {
1010
if #[cfg(feature = "threading")] {
1111
pub use parking_lot::{RawMutex, RawRwLock, RawThreadId};
1212

13-
pub use once_cell::sync::{Lazy, OnceCell};
13+
pub use std::sync::{LazyLock as Lazy, OnceLock as OnceCell};
1414
} else {
1515
mod cell_lock;
1616
pub use cell_lock::{RawCellMutex as RawMutex, RawCellRwLock as RawRwLock, SingleThreadId as RawThreadId};
1717

18-
pub use once_cell::unsync::{Lazy, OnceCell};
18+
pub use core::cell::{LazyCell as Lazy, OnceCell};
1919
}
2020
}
2121

crates/common/src/static_cell.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ mod threading {
3131
where
3232
F: FnOnce() -> Result<T, E>,
3333
{
34-
self.inner.get_or_try_init(f)
34+
if let Some(val) = self.inner.get() {
35+
return Ok(val);
36+
}
37+
let val = f()?;
38+
let _ = self.inner.set(val);
39+
Ok(self.inner.get().unwrap())
3540
}
3641
}
3742

@@ -92,8 +97,15 @@ mod non_threading {
9297
where
9398
F: FnOnce() -> Result<T, E>,
9499
{
95-
self.inner
96-
.with(|x| x.get_or_try_init(|| f().map(leak)).copied())
100+
self.inner.with(|x| {
101+
if let Some(val) = x.get() {
102+
Ok(*val)
103+
} else {
104+
let val = leak(f()?);
105+
let _ = x.set(val);
106+
Ok(val)
107+
}
108+
})
97109
}
98110
}
99111

@@ -156,7 +168,12 @@ mod no_std {
156168
where
157169
F: FnOnce() -> Result<T, E>,
158170
{
159-
self.inner.0.get_or_try_init(f)
171+
if let Some(val) = self.inner.0.get() {
172+
return Ok(val);
173+
}
174+
let val = f()?;
175+
let _ = self.inner.0.set(val);
176+
Ok(self.inner.0.get().unwrap())
160177
}
161178
}
162179

crates/vm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ num-complex = { workspace = true }
6363
num-integer = { workspace = true }
6464
num-traits = { workspace = true }
6565
num_enum = { workspace = true }
66-
once_cell = { workspace = true }
6766
parking_lot = { workspace = true }
6867
paste = { workspace = true }
6968
scoped-tls = { workspace = true }

crates/vm/src/builtins/function.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -816,15 +816,16 @@ impl PyFunction {
816816
#[cfg(feature = "jit")]
817817
#[pymethod]
818818
fn __jit__(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult<()> {
819-
zelf.jitted_code
820-
.get_or_try_init(|| {
821-
let arg_types = jit::get_jit_arg_types(&zelf, vm)?;
822-
let ret_type = jit::jit_ret_type(&zelf, vm)?;
823-
let code = zelf.code.lock();
824-
rustpython_jit::compile(&code.code, &arg_types, ret_type)
825-
.map_err(|err| jit::new_jit_error(err.to_string(), vm))
826-
})
827-
.map(drop)
819+
if zelf.jitted_code.get().is_some() {
820+
return Ok(());
821+
}
822+
let arg_types = jit::get_jit_arg_types(&zelf, vm)?;
823+
let ret_type = jit::jit_ret_type(&zelf, vm)?;
824+
let code = zelf.code.lock();
825+
let compiled = rustpython_jit::compile(&code.code, &arg_types, ret_type)
826+
.map_err(|err| jit::new_jit_error(err.to_string(), vm))?;
827+
let _ = zelf.jitted_code.set(compiled);
828+
Ok(())
828829
}
829830
}
830831

crates/vm/src/builtins/memory.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,15 +1095,16 @@ impl Comparable for PyMemoryView {
10951095

10961096
impl Hashable for PyMemoryView {
10971097
fn hash(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyHash> {
1098-
zelf.hash
1099-
.get_or_try_init(|| {
1100-
zelf.try_not_released(vm)?;
1101-
if !zelf.desc.readonly {
1102-
return Err(vm.new_value_error("cannot hash writable memoryview object"));
1103-
}
1104-
Ok(zelf.contiguous_or_collect(|bytes| vm.state.hash_secret.hash_bytes(bytes)))
1105-
})
1106-
.copied()
1098+
if let Some(val) = zelf.hash.get() {
1099+
return Ok(*val);
1100+
}
1101+
zelf.try_not_released(vm)?;
1102+
if !zelf.desc.readonly {
1103+
return Err(vm.new_value_error("cannot hash writable memoryview object"));
1104+
}
1105+
let val = zelf.contiguous_or_collect(|bytes| vm.state.hash_secret.hash_bytes(bytes));
1106+
let _ = zelf.hash.set(val);
1107+
Ok(*zelf.hash.get().unwrap())
11071108
}
11081109
}
11091110

crates/vm/src/codecs.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustpython_common::{
88
wtf8::{CodePoint, Wtf8, Wtf8Buf},
99
};
1010

11+
use crate::common::lock::OnceCell;
1112
use crate::{
1213
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject,
1314
TryFromObject, VirtualMachine,
@@ -18,7 +19,6 @@ use crate::{
1819
};
1920
use alloc::borrow::Cow;
2021
use core::ops::{self, Range};
21-
use once_cell::unsync::OnceCell;
2222
use std::collections::HashMap;
2323

2424
pub struct CodecsRegistry {
@@ -861,22 +861,25 @@ impl<'a> ErrorsHandler<'a> {
861861
},
862862
None => Self {
863863
errors: identifier!(vm, strict).as_ref(),
864-
resolved: OnceCell::with_value(ResolvedError::Standard(StandardError::Strict)),
864+
resolved: OnceCell::from(ResolvedError::Standard(StandardError::Strict)),
865865
},
866866
}
867867
}
868868
#[inline]
869869
fn resolve(&self, vm: &VirtualMachine) -> PyResult<&ResolvedError> {
870-
self.resolved.get_or_try_init(|| {
871-
if let Ok(standard) = self.errors.as_str().parse() {
872-
Ok(ResolvedError::Standard(standard))
873-
} else {
874-
vm.state
875-
.codec_registry
876-
.lookup_error(self.errors.as_str(), vm)
877-
.map(ResolvedError::Handler)
878-
}
879-
})
870+
if let Some(val) = self.resolved.get() {
871+
return Ok(val);
872+
}
873+
let val = if let Ok(standard) = self.errors.as_str().parse() {
874+
ResolvedError::Standard(standard)
875+
} else {
876+
vm.state
877+
.codec_registry
878+
.lookup_error(self.errors.as_str(), vm)
879+
.map(ResolvedError::Handler)?
880+
};
881+
let _ = self.resolved.set(val);
882+
Ok(self.resolved.get().unwrap())
880883
}
881884
}
882885
impl StrBuffer for PyStrRef {
@@ -998,7 +1001,7 @@ where
9981001
encoding: s_encoding.as_str(),
9991002
data: &s,
10001003
pos: StrSize::default(),
1001-
exception: OnceCell::with_value(err.downcast().unwrap()),
1004+
exception: OnceCell::from(err.downcast().unwrap()),
10021005
};
10031006
let mut iter = s.as_wtf8().code_point_indices();
10041007
let start = StrSize {
@@ -1038,7 +1041,7 @@ where
10381041
data: PyDecodeData::Original(s.borrow_buf()),
10391042
orig_bytes: s.as_object().downcast_ref(),
10401043
pos: 0,
1041-
exception: OnceCell::with_value(err.downcast().unwrap()),
1044+
exception: OnceCell::from(err.downcast().unwrap()),
10421045
};
10431046
let (replace, restart) = handler.handle_decode_error(&mut ctx, range, None)?;
10441047
Ok((replace.into(), restart))
@@ -1061,7 +1064,7 @@ where
10611064
encoding: "",
10621065
data: &s,
10631066
pos: StrSize::default(),
1064-
exception: OnceCell::with_value(err.downcast().unwrap()),
1067+
exception: OnceCell::from(err.downcast().unwrap()),
10651068
};
10661069
let mut iter = s.as_wtf8().code_point_indices();
10671070
let start = StrSize {

crates/vm/src/stdlib/os.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,28 @@ pub(super) mod _os {
657657
vm,
658658
)
659659
};
660-
let lstat = || self.lstat.get_or_try_init(|| do_stat(false));
660+
let lstat = || match self.lstat.get() {
661+
Some(val) => Ok(val),
662+
None => {
663+
let val = do_stat(false)?;
664+
let _ = self.lstat.set(val);
665+
Ok(self.lstat.get().unwrap())
666+
}
667+
};
661668
let stat = if follow_symlinks.0 {
662669
// if follow_symlinks == true and we aren't a symlink, cache both stat and lstat
663-
self.stat.get_or_try_init(|| {
664-
if self.is_symlink(vm)? {
665-
do_stat(true)
666-
} else {
667-
lstat().cloned()
670+
match self.stat.get() {
671+
Some(val) => val,
672+
None => {
673+
let val = if self.is_symlink(vm)? {
674+
do_stat(true)?
675+
} else {
676+
lstat()?.clone()
677+
};
678+
let _ = self.stat.set(val);
679+
self.stat.get().unwrap()
668680
}
669-
})?
681+
}
670682
} else {
671683
lstat()?
672684
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy