Skip to content

no_std for wtf8, sre_engine, compiler-core, literal#7051

Merged
youknowone merged 2 commits intoRustPython:mainfrom
youknowone:no_std
Feb 8, 2026
Merged

no_std for wtf8, sre_engine, compiler-core, literal#7051
youknowone merged 2 commits intoRustPython:mainfrom
youknowone:no_std

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Feb 8, 2026

Summary by CodeRabbit

  • New Features

    • Exposed new public modules and constants for search engine operations and literal handling.
  • Refactor

    • Updated formatter method signatures across multiple modules to ensure consistency with core formatting interfaces.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

Multiple crates migrate to no_std compilation by adding #![no_std] attributes, replacing std:: imports with core:: and alloc:: equivalents, and updating formatter trait parameters from std::fmt::Write to core::fmt::Write. Public module structures and re-exports are added where needed.

Changes

Cohort / File(s) Summary
compiler-core no_std imports
crates/compiler-core/src/bytecode.rs, crates/compiler-core/src/frozen.rs, crates/compiler-core/src/marshal.rs, crates/compiler-core/src/varint.rs
Added alloc:: imports (Vec, Box, String, ToOwned) to support heap allocation in no_std context.
compiler-core lib root
crates/compiler-core/src/lib.rs
Added #![no_std] attribute to enable no_std compilation for the crate.
literal no_std imports
crates/literal/src/complex.rs, crates/literal/src/float.rs
Added alloc:: and core:: imports (String, ToString, ToOwned, format, f64) to replace std equivalents.
literal public API formatter refactor
crates/literal/src/escape.rs
Updated public function signatures and trait implementations to use core::fmt::Write instead of std::fmt::Write across Escape, StrRepr, UnicodeEscape, AsciiEscape, and BytesRepr. Added alloc::string::String import.
literal lib root
crates/literal/src/lib.rs
Added #![no_std] attribute and declared new public modules pub mod float; and pub mod format;.
sre_engine no_std imports
crates/sre_engine/src/engine.rs
Added alloc::{vec, vec::Vec} import to support Vec in no_std context.
sre_engine lib root
crates/sre_engine/src/lib.rs
Added #![no_std] and extern crate alloc;, declared public modules and constants, added platform-specific MAXREPEAT and MAXGROUPS constants via cfg attributes.
wtf8 no_std migration
crates/wtf8/src/lib.rs
Added #![no_std] and extern crate alloc;, replaced std imports with core/alloc equivalents (Borrow, Cow, String, Vec, from_utf8, mem::take, iter::once), updated Write trait usage to core::fmt::Write.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • no_std clippy #7043: Performs the same no_std/alloc migration pattern (switching std → core/alloc imports and adding #![no_std] across crates).
  • finish no_std clippy #6587: Contains related no_std migration-style changes (replacing std imports with core/alloc equivalents across multiple modules).

Suggested reviewers

  • ShaharNaveh
  • coolreader18
  • fanninpm

Poem

🐰 Hopping through imports with glee,
From std:: to core so free,
No heap, no fuss—just alloc's call,
We've gone no_std, and that's all! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and clearly describes the main objective: converting four crates to no_std compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@youknowone youknowone marked this pull request as ready for review February 8, 2026 15:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/wtf8/src/lib.rs`:
- Around line 36-46: The workspace dependency for itertools must be configured
for no_std; update the Cargo.toml entry for itertools to disable default
features and enable its alloc support by setting itertools = { version =
"0.14.0", default-features = false, features = ["use_alloc"] } so the crate
using #![no_std] and alloc (see extern crate alloc and uses like
itertools::Either / itertools::Itertools) compiles without pulling in std.

Comment on lines +36 to +46
#![no_std]
#![allow(clippy::precedence, clippy::match_overlapping_arm)]

extern crate alloc;

use alloc::borrow::{Cow, ToOwned};
use alloc::boxed::Box;
use alloc::collections::TryReserveError;
use alloc::string::String;
use alloc::vec::Vec;
use core::borrow::Borrow;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

fd 'Cargo.toml' crates/wtf8 --exec cat {}

Repository: RustPython/RustPython

Length of output: 458


🏁 Script executed:

grep -A 50 '\[workspace\.dependencies\]' Cargo.toml | head -100

Repository: RustPython/RustPython

Length of output: 2625


🏁 Script executed:

# Check the actual lib.rs to see import usage and configuration
head -100 crates/wtf8/src/lib.rs

Repository: RustPython/RustPython

Length of output: 3814


🏁 Script executed:

# Check how itertools and bstr are used in the code
rg -n "itertools::" crates/wtf8/src/ -A 2

Repository: RustPython/RustPython

Length of output: 211


🏁 Script executed:

# Search for actual usage of Either, Itertools, ByteSlice, ByteVec
rg "Either|Itertools|ByteSlice|ByteVec" crates/wtf8/src/ --max-count=20

Repository: RustPython/RustPython

Length of output: 364


🏁 Script executed:

# Check for any cargo features or configuration related to no_std in wtf8
rg "feature\|no_std" crates/wtf8/ -B 2 -A 2

Repository: RustPython/RustPython

Length of output: 47


🏁 Script executed:

# Check if there are any tests or CI configuration that builds with no_std
fd 'Cargo.toml|\.rs' crates/wtf8 --exec grep -l "no_std\|no-std" {}

Repository: RustPython/RustPython

Length of output: 87


🏁 Script executed:

# Let's check if bstr crate documentation or source indicates no_std requirements
# First, let me see if there's a Cargo.lock or any evidence of successful builds
git log --oneline crates/wtf8/Cargo.toml | head -5

Repository: RustPython/RustPython

Length of output: 122


🏁 Script executed:

# Check the commit that added no_std support to see what pattern was used
git show 2c5ece945 --stat | head -30

Repository: RustPython/RustPython

Length of output: 1737


🏁 Script executed:

# Check if wtf8 was included in that commit and see what changes were made
git show 2c5ece945 -- crates/wtf8/ | head -200

Repository: RustPython/RustPython

Length of output: 6676


🏁 Script executed:

# Check if there's any .cargo/config.toml configuration related to building crates
cat .cargo/config.toml | head -50

Repository: RustPython/RustPython

Length of output: 343


🏁 Script executed:

# Check if there are any actual usages of ascii and memchr
rg "ascii::|memchr::" crates/wtf8/src/ -A 2

Repository: RustPython/RustPython

Length of output: 1327


🏁 Script executed:

# Check if any of the dependencies have been explicitly configured for no_std elsewhere
# Let's search for how other no_std crates in the workspace handle dependencies
rg "default-features.*false" Cargo.toml | head -20

Repository: RustPython/RustPython

Length of output: 576


🏁 Script executed:

# Check if there are any tests or build configurations that verify no_std compilation
rg "no.std|no-std" . --type toml | head -20

Repository: RustPython/RustPython

Length of output: 47


🏁 Script executed:

# Let me verify if these specific dependency versions support no_std out of the box
# by checking their documentation or configuration patterns used elsewhere in the repo
python3 << 'EOF'
# Check if other crates in the workspace use similar dependencies
import subprocess
import re

# Search for patterns of how dependencies are configured in Cargo.toml files
result = subprocess.run(['rg', 'ascii|bstr|itertools|memchr', '--type', 'toml', '-B2', '-A2'], 
                       capture_output=True, text=True)
print(result.stdout)
EOF

Repository: RustPython/RustPython

Length of output: 47


🌐 Web query:

itertools 0.14.0 no_std alloc feature requirements

💡 Result:

For itertools = 0.14.0, std is enabled by default (default = ["use_std"]). The crate’s features are: use_std (which implies use_alloc) and use_alloc alone. [1][2]

no_std + alloc (no std)

Use default-features = false and enable use_alloc:

[dependencies]
itertools = { version = "0.14.0", default-features = false, features = ["use_alloc"] }

This avoids use_std (and thus avoids enabling either/use_std) while allowing the parts of itertools that rely on alloc. [1][2]

no_std without alloc (core-only)

Disable default features and don’t enable use_alloc:

[dependencies]
itertools = { version = "0.14.0", default-features = false }

(You can only use the subset of itertools that doesn’t require allocation.) [1][2]

Note: In a #![no_std] binary, alloc-using code also requires that your target provides the alloc crate and that you have a global allocator available at link/runtime. [1]

Sources: [1] Cargo.toml for itertools 0.14.0 on docs.rs, [2] docs.rs feature flags page.


itertools requires explicit no_std configuration — add default-features = false, features = ["use_alloc"] to the workspace dependency.

The crate uses #![no_std] with itertools::Either and itertools::Itertools, but itertools 0.14.0 defaults to use_std. Update the workspace dependency in Cargo.toml:

itertools = { version = "0.14.0", default-features = false, features = ["use_alloc"] }

The other dependencies (ascii, bstr, memchr) support no_std with their default configurations.

🤖 Prompt for AI Agents
In `@crates/wtf8/src/lib.rs` around lines 36 - 46, The workspace dependency for
itertools must be configured for no_std; update the Cargo.toml entry for
itertools to disable default features and enable its alloc support by setting
itertools = { version = "0.14.0", default-features = false, features =
["use_alloc"] } so the crate using #![no_std] and alloc (see extern crate alloc
and uses like itertools::Either / itertools::Itertools) compiles without pulling
in std.

@youknowone youknowone merged commit cf83008 into RustPython:main Feb 8, 2026
12 of 13 checks passed
@youknowone youknowone deleted the no_std branch February 8, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant