A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Use `core::convert::Infallible` instead of our own `Uninhabited` type (#12115)
Nick Fitzgerald1d7389751e04
diff --git a/crates/wasmtime/src/runtime.rs b/crates/wasmtime/src/runtime.rsindex a0ff5e0ec6..e9417931a2 100644--- a/crates/wasmtime/src/runtime.rs+++ b/crates/wasmtime/src/runtime.rs@@ -53,7 +53,6 @@ pub(crate) mod trampoline;pub(crate) mod trap;pub(crate) mod type_registry;pub(crate) mod types;-pub(crate) mod uninhabited;pub(crate) mod v128;pub(crate) mod values;pub(crate) mod vm;@@ -100,8 +99,6 @@ pub use types::*;pub use v128::V128;pub use values::*;-pub(crate) use uninhabited::*;-#[cfg(feature = "pooling-allocator")]pub use vm::{PoolConcurrencyLimitError, PoolingAllocatorMetrics};diff --git a/crates/wasmtime/src/runtime/component/concurrent_disabled.rs b/crates/wasmtime/src/runtime/component/concurrent_disabled.rsindex 5fb313801f..e0dc802548 100644--- a/crates/wasmtime/src/runtime/component/concurrent_disabled.rs+++ b/crates/wasmtime/src/runtime/component/concurrent_disabled.rs@@ -1,8 +1,8 @@-use crate::Uninhabited;use crate::component::Val;use crate::component::func::{ComponentType, LiftContext, LowerContext};use crate::runtime::vm::VMStore;use anyhow::{Result, anyhow};+use core::convert::Infallible;use core::future::Future;use core::marker::PhantomData;use core::pin::pin;@@ -56,7 +56,7 @@ pub(crate) fn lower_error_context_to_index<U>(should_have_failed_validation("use of `error-context`")}-pub struct ErrorContext(Uninhabited);+pub struct ErrorContext(Infallible);impl ErrorContext {pub(crate) fn into_val(self) -> Val {@@ -81,7 +81,7 @@ impl ErrorContext {}pub struct StreamReader<P> {- uninhabited: Uninhabited,+ uninhabited: Infallible,_phantom: PhantomData<P>,}@@ -108,7 +108,7 @@ impl<P> StreamReader<P> {}pub struct FutureReader<P> {- uninhabited: Uninhabited,+ uninhabited: Infallible,_phantom: PhantomData<P>,}diff --git a/crates/wasmtime/src/runtime/func.rs b/crates/wasmtime/src/runtime/func.rsindex 7de4f2229b..5dc48488be 100644--- a/crates/wasmtime/src/runtime/func.rs+++ b/crates/wasmtime/src/runtime/func.rs@@ -1,5 +1,4 @@use crate::prelude::*;-use crate::runtime::Uninhabited;use crate::runtime::vm::{self, InterpreterRef, SendSyncPtr, StoreBox, VMArrayCallHostFuncContext,VMCommonStackInformation, VMContext, VMFuncRef, VMFunctionImport, VMOpaqueContext,@@ -12,6 +11,7 @@ use crate::{StoreContext, StoreContextMut, Val, ValRaw, ValType,};use alloc::sync::Arc;+use core::convert::Infallible;use core::ffi::c_void;#[cfg(feature = "async")]use core::future::Future;@@ -77,7 +77,7 @@ use wasmtime_environ::VMSharedTypeIndex;/// ```#[derive(Copy, Clone, Debug, PartialEq, Eq)]pub struct NoFunc {- _inner: Uninhabited,+ _inner: Infallible,}impl NoFunc {diff --git a/crates/wasmtime/src/runtime/gc/disabled/rooting.rs b/crates/wasmtime/src/runtime/gc/disabled/rooting.rsindex fcbe9e0fb0..543063f138 100644--- a/crates/wasmtime/src/runtime/gc/disabled/rooting.rs+++ b/crates/wasmtime/src/runtime/gc/disabled/rooting.rs@@ -1,9 +1,9 @@use crate::runtime::vm::{GcStore, VMGcRef};use crate::{AsContext, AsContextMut, GcRef, Result, RootedGcRef,- runtime::Uninhabited,store::{AutoAssertNoGc, StoreOpaque},};+use core::convert::Infallible;use core::fmt::{self, Debug};use core::hash::{Hash, Hasher};use core::marker;@@ -48,7 +48,7 @@ impl RootSet {/// This type is disabled because the `gc` cargo feature was not enabled at/// compile time.pub struct Rooted<T: GcRef> {- pub(crate) inner: Uninhabited,+ pub(crate) inner: Infallible,_phantom: marker::PhantomData<T>,}@@ -122,7 +122,7 @@ pub struct RootScope<C>whereC: AsContextMut,{- inner: Uninhabited,+ inner: Infallible,_phantom: marker::PhantomData<C>,}@@ -161,7 +161,7 @@ pub struct OwnedRooted<T>whereT: GcRef,{- pub(crate) inner: Uninhabited,+ pub(crate) inner: Infallible,_phantom: marker::PhantomData<T>,}diff --git a/crates/wasmtime/src/runtime/gc/noextern.rs b/crates/wasmtime/src/runtime/gc/noextern.rsindex e022fb2ca3..7cf59f1dfc 100644--- a/crates/wasmtime/src/runtime/gc/noextern.rs+++ b/crates/wasmtime/src/runtime/gc/noextern.rs@@ -1,7 +1,8 @@use crate::{- HeapType, Ref, RefType, Result, Uninhabited, Val, ValRaw, ValType, WasmTy,+ HeapType, Ref, RefType, Result, Val, ValRaw, ValType, WasmTy,store::{AutoAssertNoGc, StoreOpaque},};+use core::convert::Infallible;use core::mem::MaybeUninit;/// A reference to the abstract `noextern` heap value.@@ -64,7 +65,7 @@ use core::mem::MaybeUninit;/// ```#[derive(Copy, Clone, Debug, PartialEq, Eq)]pub struct NoExtern {- _inner: Uninhabited,+ _inner: Infallible,}impl NoExtern {diff --git a/crates/wasmtime/src/runtime/gc/none_ref.rs b/crates/wasmtime/src/runtime/gc/none_ref.rsindex f4c98856ed..47638b2b07 100644--- a/crates/wasmtime/src/runtime/gc/none_ref.rs+++ b/crates/wasmtime/src/runtime/gc/none_ref.rs@@ -1,7 +1,8 @@use crate::{- HeapType, Ref, RefType, Result, Uninhabited, Val, ValRaw, ValType, WasmTy,+ HeapType, Ref, RefType, Result, Val, ValRaw, ValType, WasmTy,store::{AutoAssertNoGc, StoreOpaque},};+use core::convert::Infallible;use core::mem::MaybeUninit;/// A reference to the abstract `none` heap value.@@ -64,7 +65,7 @@ use core::mem::MaybeUninit;/// ```#[derive(Copy, Clone, Debug, PartialEq, Eq)]pub struct NoneRef {- _inner: Uninhabited,+ _inner: Infallible,}impl NoneRef {diff --git a/crates/wasmtime/src/runtime/store.rs b/crates/wasmtime/src/runtime/store.rsindex f2f00b7fd2..19d9edc401 100644--- a/crates/wasmtime/src/runtime/store.rs+++ b/crates/wasmtime/src/runtime/store.rs@@ -106,8 +106,9 @@ use crate::trampoline::VMHostGlobalContext;use crate::{Engine, Module, Val, ValRaw, module::ModuleRegistry};#[cfg(feature = "gc")]use crate::{ExnRef, Rooted};-use crate::{Global, Instance, Table, Uninhabited};+use crate::{Global, Instance, Table};use alloc::sync::Arc;+use core::convert::Infallible;use core::fmt;use core::marker;use core::mem::{self, ManuallyDrop, MaybeUninit};@@ -384,7 +385,7 @@ enum CallHookInner<T: 'static> {reason = "forcing, regardless of cfg, the type param to be used")]ForceTypeParameterToBeUsed {- uninhabited: Uninhabited,+ uninhabited: Infallible,_marker: marker::PhantomData<T>,},}diff --git a/crates/wasmtime/src/runtime/uninhabited.rs b/crates/wasmtime/src/runtime/uninhabited.rsdeleted file mode 100644index 6b368c35ce..0000000000--- a/crates/wasmtime/src/runtime/uninhabited.rs+++ /dev/null@@ -1,5 +0,0 @@-/// An uninhabited type.-///-/// Useful for modeling Wasm's bottom types or `cfg`'d off features.-#[derive(Copy, Clone, Debug, PartialEq, Eq)]-pub(crate) enum Uninhabited {}diff --git a/crates/wasmtime/src/runtime/vm.rs b/crates/wasmtime/src/runtime/vm.rsindex a7c597affe..2eb24859f7 100644--- a/crates/wasmtime/src/runtime/vm.rs+++ b/crates/wasmtime/src/runtime/vm.rs@@ -23,15 +23,15 @@ pub(crate) type f64x2 = core::arch::x86_64::__m128d;#[cfg(not(all(target_arch = "x86_64", target_feature = "sse")))]#[expect(non_camel_case_types, reason = "matching wasm conventions")]#[derive(Copy, Clone)]-pub(crate) struct i8x16(crate::uninhabited::Uninhabited);+pub(crate) struct i8x16(core::convert::Infallible);#[cfg(not(all(target_arch = "x86_64", target_feature = "sse")))]#[expect(non_camel_case_types, reason = "matching wasm conventions")]#[derive(Copy, Clone)]-pub(crate) struct f32x4(crate::uninhabited::Uninhabited);+pub(crate) struct f32x4(core::convert::Infallible);#[cfg(not(all(target_arch = "x86_64", target_feature = "sse")))]#[expect(non_camel_case_types, reason = "matching wasm conventions")]#[derive(Copy, Clone)]-pub(crate) struct f64x2(crate::uninhabited::Uninhabited);+pub(crate) struct f64x2(core::convert::Infallible);use crate::StoreContextMut;use crate::prelude::*;diff --git a/crates/wasmtime/src/runtime/vm/interpreter_disabled.rs b/crates/wasmtime/src/runtime/vm/interpreter_disabled.rsindex be7311c158..fd8a0829ab 100644--- a/crates/wasmtime/src/runtime/vm/interpreter_disabled.rs+++ b/crates/wasmtime/src/runtime/vm/interpreter_disabled.rs@@ -4,16 +4,16 @@//! `Option<Thing>` is also zero-sized so there should be no runtime cost for//! having these structures plumbed around.-use crate::runtime::Uninhabited;use crate::runtime::vm::{VMContext, VMOpaqueContext};use crate::{Engine, ValRaw};+use core::convert::Infallible;use core::marker;use core::mem;use core::ptr::NonNull;use wasmtime_unwinder::Unwind;pub struct Interpreter {- empty: Uninhabited,+ empty: Infallible,}const _: () = assert!(mem::size_of::<Interpreter>() == 0);@@ -34,7 +34,7 @@ impl Interpreter {}pub struct InterpreterRef<'a> {- empty: Uninhabited,+ empty: Infallible,_marker: marker::PhantomData<&'a mut Interpreter>,}diff --git a/pulley/src/decode.rs b/pulley/src/decode.rsindex 6e1d2b0b77..6c567a71dd 100644--- a/pulley/src/decode.rs+++ b/pulley/src/decode.rs@@ -1,14 +1,13 @@//! Decoding support for pulley bytecode.-use core::ptr::NonNull;--use alloc::vec::Vec;-use cranelift_bitset::ScalarBitSet;-use cranelift_bitset::scalar::ScalarBitSetStorage;-use crate::imms::*;use crate::opcode::*;use crate::regs::*;+use alloc::vec::Vec;+use core::convert::Infallible;+use core::ptr::NonNull;+use cranelift_bitset::ScalarBitSet;+use cranelift_bitset::scalar::ScalarBitSetStorage;/// Either an `Ok(T)` or an `Err(DecodingError)`.pub type Result<T, E = DecodingError> = core::result::Result<T, E>;@@ -188,10 +187,6 @@ impl BytecodeStream for SafeBytecodeStream<'_> {}}-/// An uninhabited type that cannot be constructed at runtime.-#[derive(Debug)]-pub enum Uninhabited {}-/// An unsafe bytecode stream.////// This is a wrapper over a raw pointer to bytecode somewhere in memory.@@ -239,7 +234,7 @@ impl BytecodeStream for UnsafeBytecodeStream {Ok(bytes)}- type Error = Uninhabited;+ type Error = Infallible;fn unexpected_eof(&self) -> Self::Error {unsafe { crate::unreachable_unchecked() }