Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
no_std for sre_engine, compiler-core, literal
  • Loading branch information
youknowone committed Feb 8, 2026
commit 2c5ece945b463b2725296fc078e935875e18568e
3 changes: 2 additions & 1 deletion crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
varint::{read_varint, read_varint_with_start, write_varint, write_varint_with_start},
{OneIndexed, SourceLocation},
};
use alloc::{collections::BTreeSet, fmt, vec::Vec};
use alloc::{borrow::ToOwned, boxed::Box, collections::BTreeSet, fmt, string::String, vec::Vec};
use bitflags::bitflags;
use core::{hash, mem, ops::Deref};
use itertools::Itertools;
Expand Down Expand Up @@ -804,6 +804,7 @@ impl<C: Constant> fmt::Debug for CodeObject<C> {
#[cfg(test)]
mod tests {
use super::*;
use alloc::{vec, vec::Vec};

#[test]
fn test_exception_table_encode_decode() {
Expand Down
1 change: 1 addition & 0 deletions crates/compiler-core/src/frozen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::bytecode::*;
use crate::marshal::{self, Read, ReadBorrowed, Write};
use alloc::vec::Vec;

/// A frozen module. Holds a frozen code object and whether it is part of a package
#[derive(Copy, Clone)]
Expand Down
1 change: 1 addition & 0 deletions crates/compiler-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![no_std]
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
#![doc(html_root_url = "https://docs.rs/rustpython-compiler-core/")]

Expand Down
1 change: 1 addition & 0 deletions crates/compiler-core/src/marshal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{OneIndexed, SourceLocation, bytecode::*};
use alloc::{boxed::Box, vec::Vec};
use core::convert::Infallible;
use malachite_bigint::{BigInt, Sign};
use num_complex::Complex64;
Expand Down
2 changes: 2 additions & 0 deletions crates/compiler-core/src/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! Uses 6-bit chunks with a continuation bit (0x40) to encode integers.
//! Used for exception tables and line number tables.

use alloc::vec::Vec;

/// Write a variable-length unsigned integer using 6-bit chunks.
/// Returns the number of bytes written.
#[inline]
Expand Down
2 changes: 2 additions & 0 deletions crates/literal/src/complex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::float;
use alloc::borrow::ToOwned;
use alloc::string::{String, ToString};

/// Convert a complex number to a string.
pub fn to_string(re: f64, im: f64) -> String {
Expand Down
31 changes: 18 additions & 13 deletions crates/literal/src/escape.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::string::String;
use rustpython_wtf8::{CodePoint, Wtf8};

#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, is_macro::Is)]
Expand Down Expand Up @@ -55,9 +56,9 @@ pub unsafe trait Escape {
/// # Safety
///
/// This string must only contain printable characters.
unsafe fn write_source(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result;
fn write_body_slow(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result;
fn write_body(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result {
unsafe fn write_source(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result;
fn write_body_slow(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result;
fn write_body(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result {
if self.changed() {
self.write_body_slow(formatter)
} else {
Expand Down Expand Up @@ -117,7 +118,7 @@ impl<'a> UnicodeEscape<'a> {
pub struct StrRepr<'r, 'a>(&'r UnicodeEscape<'a>);

impl StrRepr<'_, '_> {
pub fn write(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result {
pub fn write(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result {
let quote = self.0.layout().quote.to_char();
formatter.write_char(quote)?;
self.0.write_body(formatter)?;
Expand Down Expand Up @@ -216,7 +217,7 @@ impl UnicodeEscape<'_> {
fn write_char(
ch: CodePoint,
quote: Quote,
formatter: &mut impl std::fmt::Write,
formatter: &mut impl core::fmt::Write,
) -> core::fmt::Result {
let Some(ch) = ch.to_char() else {
return write!(formatter, "\\u{:04x}", ch.to_u32());
Expand Down Expand Up @@ -260,15 +261,15 @@ unsafe impl Escape for UnicodeEscape<'_> {
&self.layout
}

unsafe fn write_source(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result {
unsafe fn write_source(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result {
formatter.write_str(unsafe {
// SAFETY: this function must be called only when source is printable characters (i.e. no surrogates)
std::str::from_utf8_unchecked(self.source.as_bytes())
core::str::from_utf8_unchecked(self.source.as_bytes())
})
}

#[cold]
fn write_body_slow(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result {
fn write_body_slow(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result {
for ch in self.source.code_points() {
Self::write_char(ch, self.layout().quote, formatter)?;
}
Expand Down Expand Up @@ -378,7 +379,11 @@ impl AsciiEscape<'_> {
}
}

fn write_char(ch: u8, quote: Quote, formatter: &mut impl std::fmt::Write) -> core::fmt::Result {
fn write_char(
ch: u8,
quote: Quote,
formatter: &mut impl core::fmt::Write,
) -> core::fmt::Result {
match ch {
b'\t' => formatter.write_str("\\t"),
b'\n' => formatter.write_str("\\n"),
Expand All @@ -404,15 +409,15 @@ unsafe impl Escape for AsciiEscape<'_> {
&self.layout
}

unsafe fn write_source(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result {
unsafe fn write_source(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result {
formatter.write_str(unsafe {
// SAFETY: this function must be called only when source is printable ascii characters
std::str::from_utf8_unchecked(self.source)
core::str::from_utf8_unchecked(self.source)
})
}

#[cold]
fn write_body_slow(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result {
fn write_body_slow(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result {
for ch in self.source {
Self::write_char(*ch, self.layout().quote, formatter)?;
}
Expand All @@ -423,7 +428,7 @@ unsafe impl Escape for AsciiEscape<'_> {
pub struct BytesRepr<'r, 'a>(&'r AsciiEscape<'a>);

impl BytesRepr<'_, '_> {
pub fn write(&self, formatter: &mut impl std::fmt::Write) -> core::fmt::Result {
pub fn write(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result {
let quote = self.0.layout().quote.to_char();
formatter.write_char('b')?;
formatter.write_char(quote)?;
Expand Down
5 changes: 4 additions & 1 deletion crates/literal/src/float.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::format::Case;
use alloc::borrow::ToOwned;
use alloc::format;
use alloc::string::{String, ToString};
use core::f64;
use num_traits::{Float, Zero};
use std::f64;

pub fn parse_str(literal: &str) -> Option<f64> {
parse_inner(literal.trim().as_bytes())
Expand Down
4 changes: 4 additions & 0 deletions crates/literal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![no_std]

extern crate alloc;

pub mod char;
pub mod complex;
pub mod escape;
Expand Down
1 change: 1 addition & 0 deletions crates/sre_engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::string::{
};

use super::{MAXREPEAT, SreAtCode, SreCatCode, SreInfo, SreOpcode, StrDrive, StringCursor};
use alloc::{vec, vec::Vec};
use core::{convert::TryFrom, ptr::null};
use optional::Optioned;

Expand Down
4 changes: 4 additions & 0 deletions crates/sre_engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![no_std]

extern crate alloc;

pub mod constants;
pub mod engine;
pub mod string;
Expand Down
Loading