A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Partial support for no_std in cranelift_codegen (#12222)
SSD76911c2957bb
diff --git a/Cargo.lock b/Cargo.lockindex 7cbe26eabb..9bb699ba1b 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -766,6 +766,7 @@ dependencies = ["env_logger 0.11.5","gimli 0.32.3","hashbrown 0.15.2",+ "libm","log","postcard","proptest",@@ -2988,9 +2989,9 @@ dependencies = [[[package]]name = "regalloc2"-version = "0.13.3"+version = "0.13.4"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4e249c660440317032a71ddac302f25f1d5dff387667bcc3978d1f77aa31ac34"+checksum = "919cc500365f55230d2e2230cb813dd7c6fa5f907ad332d83ad3b862112cb69e"dependencies = ["allocator-api2","bumpalo",diff --git a/Cargo.toml b/Cargo.tomlindex c193538525..bfdf50d019 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -304,7 +304,7 @@ cranelift-jit = { path = "cranelift/jit", version = "0.129.0" }cranelift-fuzzgen = { path = "cranelift/fuzzgen" }cranelift-bforest = { path = "cranelift/bforest", version = "0.129.0" }cranelift-bitset = { path = "cranelift/bitset", version = "0.129.0" }-cranelift-control = { path = "cranelift/control", version = "0.129.0" }+cranelift-control = { path = "cranelift/control", version = "0.129.0", default-features = false }cranelift-srcgen = { path = "cranelift/srcgen", version = "0.129.0" }cranelift = { path = "cranelift/umbrella", version = "0.129.0" }@@ -322,7 +322,7 @@ component-async-tests = { path = "crates/misc/component-async-tests" }# Bytecode Alliance maintained dependencies:# ----------------------------regalloc2 = "0.13.3"+regalloc2 = "0.13.4"wasip1 = { version = "1.0.0", default-features = false }# cap-std family:@@ -414,7 +414,7 @@ tracing-subscriber = { version = "0.3.20", default-features = false, features =url = "2.5.7"postcard = { version = "1.1.3", default-features = false, features = ['alloc'] }criterion = { version = "0.7.0", default-features = false, features = ["html_reports", "rayon"] }-rustc-hash = "2.1.1"+rustc-hash = { version = "2.1.1", default-features = false }libtest-mimic = "0.8.1"semver = { version = "1.0.27", default-features = false }ittapi = "0.4.0"diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.tomlindex 2f84fac0cf..e8cbe564d0 100644--- a/cranelift/codegen/Cargo.toml+++ b/cranelift/codegen/Cargo.toml@@ -30,20 +30,21 @@ cranelift-entity = { workspace = true }cranelift-bforest = { workspace = true }cranelift-bitset = { workspace = true }cranelift-control = { workspace = true }-hashbrown = { workspace = true }+hashbrown = { workspace = true, features = ["default-hasher"] }target-lexicon = { workspace = true }log = { workspace = true }serde = { workspace = true, optional = true }serde_derive = { workspace = true, optional = true }pulley-interpreter = { workspace = true, optional = true }postcard = { workspace = true, optional = true }-gimli = { workspace = true, features = ["write", "std"], optional = true }+gimli = { workspace = true, features = ["write"], optional = true }smallvec = { workspace = true }regalloc2 = { workspace = true, features = ["checker"] }souper-ir = { version = "2.1.0", optional = true }sha2 = { version = "0.10.2", optional = true }rustc-hash = { workspace = true }wasmtime-math = { workspace = true }+libm = { workspace = true }# It is a goal of the cranelift-codegen crate to have minimal external dependencies.# Please don't add any unless they are essential to the task of creating binary# machine code. Integration tests that need external dependencies can be@@ -65,7 +66,7 @@ default = ["std", "unwind", "host-arch", "timing"]# The "std" feature enables use of libstd. The "core" feature enables use# of some minimal std-like replacement libraries. At least one of these two# features need to be enabled.-std = ["serde?/std"]+std = ["serde?/std", "rustc-hash/std", "gimli/std", "cranelift-control/fuzz"]# The "core" feature used to enable a hashmap workaround, but is now# deprecated (we (i) always use hashbrown, and (ii) don't support adiff --git a/cranelift/codegen/src/alias_analysis.rs b/cranelift/codegen/src/alias_analysis.rsindex 93adce052c..eecb38096d 100644--- a/cranelift/codegen/src/alias_analysis.rs+++ b/cranelift/codegen/src/alias_analysis.rs@@ -61,6 +61,7 @@//! must be correct likely reduce the potential benefit, we don't yet//! do this.+use crate::{FxHashMap, FxHashSet};use crate::{cursor::{Cursor, FuncCursor},dominator_tree::DominatorTree,@@ -71,7 +72,6 @@ use crate::{trace,};use cranelift_entity::{EntityRef, packed_option::PackedOption};-use rustc_hash::{FxHashMap, FxHashSet};/// For a given program point, the vector of last-store instruction/// indices for each disjoint category of abstract state.diff --git a/cranelift/codegen/src/egraph/elaborate.rs b/cranelift/codegen/src/egraph/elaborate.rsindex 9328354b2d..86443e5cb1 100644--- a/cranelift/codegen/src/egraph/elaborate.rs+++ b/cranelift/codegen/src/egraph/elaborate.rs@@ -11,10 +11,10 @@ use crate::ir::{Block, Function, Inst, Value, ValueDef};use crate::loop_analysis::{Loop, LoopAnalysis};use crate::scoped_hash_map::ScopedHashMap;use crate::trace;+use crate::{FxHashMap, FxHashSet};use alloc::vec::Vec;use cranelift_control::ControlPlane;use cranelift_entity::{EntitySet, SecondaryMap, packed_option::ReservedValue};-use rustc_hash::{FxHashMap, FxHashSet};use smallvec::{SmallVec, smallvec};pub(crate) struct Elaborator<'a> {diff --git a/cranelift/codegen/src/egraph.rs b/cranelift/codegen/src/egraph/mod.rssimilarity index 99%rename from cranelift/codegen/src/egraph.rsrename to cranelift/codegen/src/egraph/mod.rsindex 46fdaf3698..280109470d 100644--- a/cranelift/codegen/src/egraph.rs+++ b/cranelift/codegen/src/egraph/mod.rs@@ -1,5 +1,6 @@//! Support for egraphs represented in the DataFlowGraph.+use crate::FxHashSet;use crate::alias_analysis::{AliasAnalysis, LastStores};use crate::ctxhash::{CtxEq, CtxHash, NullCtx};use crate::cursor::{Cursor, CursorPosition, FuncCursor};@@ -24,7 +25,6 @@ use core::hash::Hasher;use cranelift_control::ControlPlane;use cranelift_entity::SecondaryMap;use cranelift_entity::packed_option::ReservedValue;-use rustc_hash::FxHashSet;use smallvec::SmallVec;mod cost;diff --git a/cranelift/codegen/src/ir/immediates.rs b/cranelift/codegen/src/ir/immediates.rsindex 79b9432960..6eb30974ed 100644--- a/cranelift/codegen/src/ir/immediates.rs+++ b/cranelift/codegen/src/ir/immediates.rs@@ -10,6 +10,7 @@ use core::fmt::{self, Display, Formatter};use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Sub};use core::str::FromStr;use core::{i32, u32};+use libm::Libm;#[cfg(feature = "enable-serde")]use serde_derive::{Deserialize, Serialize};@@ -682,27 +683,29 @@ macro_rules! ieee_float {$(/// Returns the square root of `self`.pub fn sqrt(self) -> Self {- Self::with_float(self.$as_float().sqrt())+ Self::with_float(Libm::<$float_ty>::sqrt(self.$as_float()))}/// Returns the smallest integer greater than or equal to `self`.pub fn ceil(self) -> Self {- Self::with_float(self.$as_float().ceil())+ Self::with_float(Libm::<$float_ty>::ceil(self.$as_float()))}/// Returns the largest integer less than or equal to `self`.pub fn floor(self) -> Self {- Self::with_float(self.$as_float().floor())+ Self::with_float(Libm::<$float_ty>::floor(self.$as_float()))}/// Returns the integer part of `self`. This means that non-integer numbers are always truncated towards zero.pub fn trunc(self) -> Self {- Self::with_float(self.$as_float().trunc())+ Self::with_float(Libm::<$float_ty>::trunc(self.$as_float()))}/// Returns the nearest integer to `self`. Rounds half-way cases to the number/// with an even least significant digit.pub fn round_ties_even(self) -> Self {+ // TODO: when libm v0.2.16 is published line below can be used instead+ // Self::with_float(Libm::<$float_ty>::roundeven(self.$as_float()))Self::with_float(self.$as_float().round_ties_even())})?diff --git a/cranelift/codegen/src/isa/unwind.rs b/cranelift/codegen/src/isa/unwind.rsindex ada37b03cc..c9ea050fb2 100644--- a/cranelift/codegen/src/isa/unwind.rs+++ b/cranelift/codegen/src/isa/unwind.rs@@ -14,6 +14,7 @@ pub mod winx64;#[cfg(feature = "unwind")]pub mod winarm64;+#[cfg(feature = "unwind")]/// CFA-based unwind information used on SystemV.pub type CfaUnwindInfo = systemv::UnwindInfo;diff --git a/cranelift/codegen/src/isa/x64/mod.rs b/cranelift/codegen/src/isa/x64/mod.rsindex 37a3865043..2559a97b68 100644--- a/cranelift/codegen/src/isa/x64/mod.rs+++ b/cranelift/codegen/src/isa/x64/mod.rs@@ -28,6 +28,7 @@ mod lower;mod pcc;pub mod settings;+#[cfg(feature = "unwind")]pub use inst::unwind::systemv::create_cie;/// An X64 backend.@@ -217,6 +218,7 @@ pub fn emit_unwind_info() -> CodegenResult<Option<crate::isa::unwind::UnwindInfo>> {use crate::isa::unwind::{UnwindInfo, UnwindInfoKind};Ok(match kind {+ #[cfg(feature = "unwind")]UnwindInfoKind::SystemV => {let mapper = self::inst::unwind::systemv::RegisterMapper;Some(UnwindInfo::SystemV(@@ -227,6 +229,7 @@ pub fn emit_unwind_info()?,))}+ #[cfg(feature = "unwind")]UnwindInfoKind::Windows => Some(UnwindInfo::WindowsX64(crate::isa::unwind::winx64::create_unwind_info_from_insts::<self::inst::unwind::winx64::RegisterMapper,diff --git a/cranelift/codegen/src/lib.rs b/cranelift/codegen/src/lib.rsindex 425edb25e1..1cfb95c1f2 100644--- a/cranelift/codegen/src/lib.rs+++ b/cranelift/codegen/src/lib.rs@@ -14,6 +14,7 @@allow(dead_code, reason = "see comment above"))]+#[cfg_attr(not(feature = "std"), macro_use)]extern crate alloc;#[cfg(feature = "std")]@@ -23,7 +24,12 @@ extern crate std;#[cfg(not(feature = "std"))]use hashbrown::{HashMap, HashSet, hash_map};#[cfg(feature = "std")]-use std::collections::{HashMap, hash_map};+use std::collections::{HashMap, HashSet, hash_map};++/// Type alias for a hash map that uses the Fx hashing algorithm.+pub type FxHashMap<K, V> = HashMap<K, V, rustc_hash::FxBuildHasher>;+/// Type alias for a hash set that uses the Fx hashing algorithm.+pub type FxHashSet<V> = HashSet<V, rustc_hash::FxBuildHasher>;pub use crate::context::Context;pub use crate::value_label::{LabelValueLoc, ValueLabelsRanges, ValueLocRange};diff --git a/cranelift/codegen/src/machinst/abi.rs b/cranelift/codegen/src/machinst/abi.rsindex 60ea23445e..08f275ccca 100644--- a/cranelift/codegen/src/machinst/abi.rs+++ b/cranelift/codegen/src/machinst/abi.rs@@ -99,6 +99,7 @@//! ABI. See each platform's `abi.rs` implementation for details.use crate::CodegenError;+use crate::FxHashMap;use crate::HashMap;use crate::entity::SecondaryMap;use crate::ir::{ArgumentExtension, ArgumentPurpose, ExceptionTag, Signature};@@ -110,7 +111,6 @@ use crate::{machinst::*, trace};use alloc::boxed::Box;use core::marker::PhantomData;use regalloc2::{MachineEnv, PReg, PRegSet};-use rustc_hash::FxHashMap;use smallvec::smallvec;/// A small vector of instructions (with some reasonable size); appropriate fordiff --git a/cranelift/codegen/src/machinst/blockorder.rs b/cranelift/codegen/src/machinst/blockorder.rsindex 9e48e2c4d6..671426e600 100644--- a/cranelift/codegen/src/machinst/blockorder.rs+++ b/cranelift/codegen/src/machinst/blockorder.rs@@ -64,8 +64,8 @@ use crate::dominator_tree::DominatorTree;use crate::entity::SecondaryMap;use crate::inst_predicates::visit_block_succs;use crate::ir::{Block, Function, Inst, Opcode};+use crate::{FxHashMap, FxHashSet};use crate::{machinst::*, trace};-use rustc_hash::{FxHashMap, FxHashSet};/// Mapping from CLIF BBs to VCode BBs.#[derive(Debug)]diff --git a/cranelift/codegen/src/machinst/compile.rs b/cranelift/codegen/src/machinst/compile.rsindex cd2e7e9d6a..84c68b3374 100644--- a/cranelift/codegen/src/machinst/compile.rs+++ b/cranelift/codegen/src/machinst/compile.rs@@ -82,7 +82,7 @@ pub fn compile<B: LowerBackend + TargetIsa>(// Run the regalloc checker, if requested.if b.flags().regalloc_checker() {let _tt = timing::regalloc_checker();- let mut checker = regalloc2::checker::Checker::new(&vcode, vcode.abi.machine_env());+ let mut checker = regalloc2::checker::Checker::new(&vcode, &vcode.abi.machine_env());checker.prepare(®alloc_result);checker.run()diff --git a/cranelift/codegen/src/machinst/lower.rs b/cranelift/codegen/src/machinst/lower.rsindex 4c55b018c8..c3ce9fa9c9 100644--- a/cranelift/codegen/src/machinst/lower.rs+++ b/cranelift/codegen/src/machinst/lower.rs@@ -22,10 +22,10 @@ use crate::machinst::{};use crate::settings::Flags;use crate::{CodegenError, CodegenResult, trace};+use crate::{FxHashMap, FxHashSet};use alloc::vec::Vec;use core::fmt::Debug;use cranelift_control::ControlPlane;-use rustc_hash::{FxHashMap, FxHashSet};use smallvec::{SmallVec, smallvec};use super::{VCodeBuildDirection, VRegAllocator};diff --git a/cranelift/codegen/src/machinst/vcode.rs b/cranelift/codegen/src/machinst/vcode.rsindex 596d720e4e..5a1aa71b97 100644--- a/cranelift/codegen/src/machinst/vcode.rs+++ b/cranelift/codegen/src/machinst/vcode.rs@@ -18,6 +18,7 @@//! backend pipeline.use crate::CodegenError;+use crate::FxHashMap;use crate::ir::pcc::*;use crate::ir::{self, Constant, ConstantData, ValueLabel, types};use crate::ranges::Ranges;@@ -29,7 +30,6 @@ use regalloc2::{Edit, Function as RegallocFunction, InstOrEdit, InstPosition, InstRange, Operand,OperandConstraint, OperandKind, PRegSet, ProgPoint, RegClass,};-use rustc_hash::FxHashMap;use crate::HashMap;use crate::hash_map::Entry;@@ -1274,15 +1274,21 @@ impl<I: VCodeInst> VCode<I> {let loc = if let Some(preg) = alloc.as_reg() {LabelValueLoc::Reg(Reg::from(preg))} else {- let slot = alloc.as_stack().unwrap();- let slot_offset = self.abi.get_spillslot_offset(slot);- let slot_base_to_caller_sp_offset = self.abi.slot_base_to_caller_sp_offset();- let caller_sp_to_cfa_offset =- crate::isa::unwind::systemv::caller_sp_to_cfa_offset();- // NOTE: this is a negative offset because it's relative to the caller's SP- let cfa_to_sp_offset =- -((slot_base_to_caller_sp_offset + caller_sp_to_cfa_offset) as i64);- LabelValueLoc::CFAOffset(cfa_to_sp_offset + slot_offset)+ #[cfg(not(feature = "unwind"))]+ continue;++ #[cfg(feature = "unwind")]+ {+ let slot = alloc.as_stack().unwrap();+ let slot_offset = self.abi.get_spillslot_offset(slot);+ let slot_base_to_caller_sp_offset = self.abi.slot_base_to_caller_sp_offset();+ let caller_sp_to_cfa_offset =+ crate::isa::unwind::systemv::caller_sp_to_cfa_offset();+ // NOTE: this is a negative offset because it's relative to the caller's SP+ let cfa_to_sp_offset =+ -((slot_base_to_caller_sp_offset + caller_sp_to_cfa_offset) as i64);+ LabelValueLoc::CFAOffset(cfa_to_sp_offset + slot_offset)+ }};// Coalesce adjacent ranges that for the same locationdiff --git a/cranelift/codegen/src/remove_constant_phis.rs b/cranelift/codegen/src/remove_constant_phis.rsindex ae9f3ad6ed..ab5def4f75 100644--- a/cranelift/codegen/src/remove_constant_phis.rs+++ b/cranelift/codegen/src/remove_constant_phis.rs@@ -5,9 +5,9 @@ use crate::ir;use crate::ir::Function;use crate::ir::{Block, BlockArg, BlockCall, Inst, Value};use crate::timing;+use crate::{FxHashMap, FxHashSet};use bumpalo::Bump;use cranelift_entity::SecondaryMap;-use rustc_hash::{FxHashMap, FxHashSet};use smallvec::SmallVec;// A note on notation. For the sake of clarity, this file uses the phrasediff --git a/supply-chain/imports.lock b/supply-chain/imports.lockindex 9f9ae55a03..e74bfb03fd 100644--- a/supply-chain/imports.lock+++ b/supply-chain/imports.lock@@ -1327,8 +1327,8 @@ user-login = "dtolnay"user-name = "David Tolnay"[[publisher.regalloc2]]-version = "0.13.3"-when = "2025-11-13"+version = "0.13.4"+when = "2026-01-06"user-id = 3726user-login = "cfallin"user-name = "Chris Fallin"