Skip to content
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into constify
  • Loading branch information
ShaharNaveh committed Jul 4, 2025
commit 593b9d267ada9c490c52a52964cdb6d3b09e9448
2 changes: 1 addition & 1 deletion common/src/cformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bitflags! {

impl CConversionFlags {
#[inline]
pub const fn sign_string(&self) -> &'static str {
pub fn sign_string(&self) -> &'static str {
if self.contains(Self::SIGN_CHAR) {
"+"
} else if self.contains(Self::BLANK_SIGN) {
Expand Down
6 changes: 1 addition & 5 deletions common/src/encodings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ struct DecodeError<'a> {

/// # Safety
/// `v[..valid_up_to]` must be valid utf8
const unsafe fn make_decode_err(
v: &[u8],
valid_up_to: usize,
err_len: Option<usize>,
) -> DecodeError<'_> {
unsafe fn make_decode_err(v: &[u8], valid_up_to: usize, err_len: Option<usize>) -> DecodeError<'_> {
let (valid_prefix, rest) = unsafe { v.split_at_unchecked(valid_up_to) };
let valid_prefix = unsafe { core::str::from_utf8_unchecked(valid_prefix) };
DecodeError {
Expand Down
4 changes: 2 additions & 2 deletions common/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn lcg_urandom(mut x: u32, buf: &mut [u8]) {
}

#[inline]
pub const fn hash_object_id_raw(p: usize) -> PyHash {
pub fn hash_object_id_raw(p: usize) -> PyHash {
// TODO: Use commented logic when below issue resolved.
// Ref: https://github.com/RustPython/RustPython/pull/3951#issuecomment-1193108966

Expand All @@ -175,7 +175,7 @@ pub const fn hash_object_id_raw(p: usize) -> PyHash {
}

#[inline]
pub const fn hash_object_id(p: usize) -> PyHash {
pub fn hash_object_id(p: usize) -> PyHash {
fix_sentinel(hash_object_id_raw(p))
}

Expand Down
16 changes: 8 additions & 8 deletions common/src/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<L: Link> LinkedList<L, L::Target> {
// }

/// Returns whether the linked list does not contain any node
pub const fn is_empty(&self) -> bool {
pub fn is_empty(&self) -> bool {
self.head.is_none()
// if self.head.is_some() {
// return false;
Expand Down Expand Up @@ -284,7 +284,7 @@ pub struct DrainFilter<'a, T: Link, F> {
}

impl<T: Link> LinkedList<T, T::Target> {
pub const fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F>
pub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F>
where
F: FnMut(&mut T::Target) -> bool,
{
Expand Down Expand Up @@ -323,8 +323,8 @@ where

impl<T> Pointers<T> {
/// Create a new set of empty pointers
pub const fn new() -> Pointers<T> {
Pointers {
pub fn new() -> Self {
Self {
inner: UnsafeCell::new(PointersInner {
prev: None,
next: None,
Expand All @@ -333,15 +333,15 @@ impl<T> Pointers<T> {
}
}

const fn get_prev(&self) -> Option<NonNull<T>> {
fn get_prev(&self) -> Option<NonNull<T>> {
// SAFETY: prev is the first field in PointersInner, which is #[repr(C)].
unsafe {
let inner = self.inner.get();
let prev = inner as *const Option<NonNull<T>>;
ptr::read(prev)
}
}
const fn get_next(&self) -> Option<NonNull<T>> {
fn get_next(&self) -> Option<NonNull<T>> {
// SAFETY: next is the second field in PointersInner, which is #[repr(C)].
unsafe {
let inner = self.inner.get();
Expand All @@ -351,15 +351,15 @@ impl<T> Pointers<T> {
}
}

const fn set_prev(&mut self, value: Option<NonNull<T>>) {
fn set_prev(&mut self, value: Option<NonNull<T>>) {
// SAFETY: prev is the first field in PointersInner, which is #[repr(C)].
unsafe {
let inner = self.inner.get();
let prev = inner as *mut Option<NonNull<T>>;
ptr::write(prev, value);
}
}
const fn set_next(&mut self, value: Option<NonNull<T>>) {
fn set_next(&mut self, value: Option<NonNull<T>>) {
// SAFETY: next is the second field in PointersInner, which is #[repr(C)].
unsafe {
let inner = self.inner.get();
Expand Down
4 changes: 2 additions & 2 deletions common/src/lock/thread_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ pub struct ThreadMutex<R: RawMutex, G: GetThreadId, T: ?Sized> {
}

impl<R: RawMutex, G: GetThreadId, T> ThreadMutex<R, G, T> {
pub const fn new(val: T) -> Self {
ThreadMutex {
pub fn new(val: T) -> Self {
Self {
raw: RawThreadMutex::INIT,
data: UnsafeCell::new(val),
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ impl Default for PatternContext {
}

impl PatternContext {
pub const fn new() -> Self {
PatternContext {
pub fn new() -> Self {
Self {
stores: Vec::new(),
allow_irrefutable: false,
fail_pop: Vec::new(),
Expand Down Expand Up @@ -4118,7 +4118,7 @@ impl Compiler<'_> {
code.current_block = block;
}

const fn set_source_range(&mut self, range: TextRange) {
fn set_source_range(&mut self, range: TextRange) {
self.current_source_range = range;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/codegen/src/string_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct StringParser {
}

impl StringParser {
const fn new(source: Box<str>, flags: AnyStringFlags) -> Self {
fn new(source: Box<str>, flags: AnyStringFlags) -> Self {
Self {
source,
cursor: 0,
Expand Down
6 changes: 3 additions & 3 deletions compiler/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ impl Symbol {
}
}

pub const fn is_global(&self) -> bool {
pub fn is_global(&self) -> bool {
matches!(
self.scope,
SymbolScope::GlobalExplicit | SymbolScope::GlobalImplicit
)
}

pub const fn is_local(&self) -> bool {
pub fn is_local(&self) -> bool {
matches!(self.scope, SymbolScope::Local | SymbolScope::Cell)
}

pub const fn is_bound(&self) -> bool {
pub fn is_bound(&self) -> bool {
self.flags.intersects(SymbolFlags::BOUND)
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/codegen/src/unparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Unparser<'a, 'b, 'c> {
source: &'c SourceCode<'c>,
}
impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
const fn new(f: &'b mut fmt::Formatter<'a>, source: &'c SourceCode<'c>) -> Self {
fn new(f: &'b mut fmt::Formatter<'a>, source: &'c SourceCode<'c>) -> Self {
Unparser { f, source }
}

Expand Down Expand Up @@ -602,7 +602,7 @@ pub struct UnparseExpr<'a> {
source: &'a SourceCode<'a>,
}

pub const fn unparse_expr<'a>(expr: &'a Expr, source: &'a SourceCode<'a>) -> UnparseExpr<'a> {
pub fn unparse_expr<'a>(expr: &'a Expr, source: &'a SourceCode<'a>) -> UnparseExpr<'a> {
UnparseExpr { expr, source }
}

Expand Down
14 changes: 7 additions & 7 deletions compiler/core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl OpArg {

/// Returns how many CodeUnits a instruction with this op_arg will be encoded as
#[inline]
pub const fn instr_size(self) -> usize {
pub fn instr_size(self) -> usize {
(self.0 > 0xff) as usize + (self.0 > 0xff_ff) as usize + (self.0 > 0xff_ff_ff) as usize + 1
}

Expand Down Expand Up @@ -214,7 +214,7 @@ impl OpArgState {
OpArg(self.state)
}
#[inline(always)]
pub const fn reset(&mut self) {
pub fn reset(&mut self) {
self.state = 0
}
}
Expand Down Expand Up @@ -280,8 +280,8 @@ pub struct Arg<T: OpArgType>(PhantomData<T>);

impl<T: OpArgType> Arg<T> {
#[inline]
pub const fn marker() -> Self {
Arg(PhantomData)
pub fn marker() -> Self {
Self(PhantomData)
}
#[inline]
pub fn new(arg: T) -> (Self, OpArg) {
Expand Down Expand Up @@ -660,7 +660,7 @@ pub struct CodeUnit {
const _: () = assert!(mem::size_of::<CodeUnit>() == 2);

impl CodeUnit {
pub const fn new(op: Instruction, arg: OpArgByte) -> Self {
pub fn new(op: Instruction, arg: OpArgByte) -> Self {
Self { op, arg }
}
}
Expand Down Expand Up @@ -1150,7 +1150,7 @@ impl<C: Constant> fmt::Display for CodeObject<C> {
impl Instruction {
/// Gets the label stored inside this instruction, if it exists
#[inline]
pub const fn label_arg(&self) -> Option<Arg<Label>> {
pub fn label_arg(&self) -> Option<Arg<Label>> {
match self {
Jump { target: l }
| JumpIfTrue { target: l }
Expand All @@ -1177,7 +1177,7 @@ impl Instruction {
/// let jump_inst = Instruction::Jump { target: Arg::marker() };
/// assert!(jump_inst.unconditional_branch())
/// ```
pub const fn unconditional_branch(&self) -> bool {
pub fn unconditional_branch(&self) -> bool {
matches!(
self,
Jump { .. }
Expand Down
6 changes: 3 additions & 3 deletions vm/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub(crate) struct FormatCode {
}

impl FormatCode {
pub const fn arg_count(&self) -> usize {
pub fn arg_count(&self) -> usize {
match self.code {
FormatType::Pad => 0,
FormatType::Str | FormatType::Pascal => 1,
Expand Down Expand Up @@ -286,7 +286,7 @@ impl FormatCode {
}
}

const fn compensate_alignment(offset: usize, align: usize) -> Option<usize> {
fn compensate_alignment(offset: usize, align: usize) -> Option<usize> {
if align != 0 && offset != 0 {
// a % b == a & (b-1) if b is a power of 2
(align - 1).checked_sub((offset - 1) & (align - 1))
Expand Down Expand Up @@ -444,7 +444,7 @@ impl FormatSpec {
}

#[inline]
pub const fn size(&self) -> usize {
pub fn size(&self) -> usize {
self.size
}
}
Expand Down
10 changes: 5 additions & 5 deletions vm/src/builtins/asyncgenerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl PyPayload for PyAsyncGen {

#[pyclass(with(PyRef, Unconstructible, Representable))]
impl PyAsyncGen {
pub const fn as_coro(&self) -> &Coro {
pub fn as_coro(&self) -> &Coro {
&self.inner
}

Expand Down Expand Up @@ -76,7 +76,7 @@ impl PyAsyncGen {
#[pyclass]
impl PyRef<PyAsyncGen> {
#[pymethod]
const fn __aiter__(self, _vm: &VirtualMachine) -> PyRef<PyAsyncGen> {
fn __aiter__(self, _vm: &VirtualMachine) -> Self {
self
}

Expand All @@ -86,7 +86,7 @@ impl PyRef<PyAsyncGen> {
}

#[pymethod]
const fn asend(self, value: PyObjectRef, _vm: &VirtualMachine) -> PyAsyncGenASend {
fn asend(self, value: PyObjectRef, _vm: &VirtualMachine) -> PyAsyncGenASend {
PyAsyncGenASend {
ag: self,
state: AtomicCell::new(AwaitableState::Init),
Expand Down Expand Up @@ -201,7 +201,7 @@ impl PyPayload for PyAsyncGenASend {
#[pyclass(with(IterNext, Iterable))]
impl PyAsyncGenASend {
#[pymethod(name = "__await__")]
const fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
zelf
}

Expand Down Expand Up @@ -295,7 +295,7 @@ impl PyPayload for PyAsyncGenAThrow {
#[pyclass(with(IterNext, Iterable))]
impl PyAsyncGenAThrow {
#[pymethod(name = "__await__")]
const fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
zelf
}

Expand Down
6 changes: 3 additions & 3 deletions vm/src/builtins/builtin_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl fmt::Debug for PyNativeFunction {
}

impl PyNativeFunction {
pub const fn with_module(mut self, module: &'static PyStrInterned) -> Self {
pub fn with_module(mut self, module: &'static PyStrInterned) -> Self {
self.module = Some(module);
self
}
Expand All @@ -50,7 +50,7 @@ impl PyNativeFunction {
}

// PyCFunction_GET_SELF
pub const fn get_self(&self) -> Option<&PyObjectRef> {
pub fn get_self(&self) -> Option<&PyObjectRef> {
if self.value.flags.contains(PyMethodFlags::STATIC) {
return None;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ impl PyNativeFunction {
}

#[pymethod]
const fn __reduce__(&self) -> &'static str {
fn __reduce__(&self) -> &'static str {
// TODO: return (getattr, (self.object, self.name)) if this is a method
self.value.name
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins/bytearray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl PyByteArray {
PyRef::new_ref(Self::from(data), ctx.types.bytearray_type.to_owned(), None)
}

const fn from_inner(inner: PyBytesInner) -> Self {
PyByteArray {
fn from_inner(inner: PyBytesInner) -> Self {
Self {
inner: PyRwLock::new(inner),
exports: AtomicUsize::new(0),
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ impl PyRef<PyBytes> {
impl PyBytes {
#[inline]
#[pymethod]
pub const fn __len__(&self) -> usize {
pub fn __len__(&self) -> usize {
self.inner.len()
}

#[inline]
pub const fn is_empty(&self) -> bool {
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.