From e8848779ecc3b18d3104bf26f9c2f8329580e555 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sun, 3 Nov 2024 12:03:05 +0100 Subject: [PATCH] rune: Use a single RTTI --- crates/rune/src/compile/context.rs | 8 +-- crates/rune/src/compile/error.rs | 4 +- crates/rune/src/compile/unit_builder.rs | 48 +++++++---------- crates/rune/src/runtime/function.rs | 16 +++--- crates/rune/src/runtime/mod.rs | 2 +- crates/rune/src/runtime/type_info.rs | 21 ++------ crates/rune/src/runtime/unit.rs | 13 +---- crates/rune/src/runtime/value.rs | 16 +++--- crates/rune/src/runtime/value/rtti.rs | 72 ++++--------------------- crates/rune/src/runtime/variant.rs | 24 ++++----- crates/rune/src/runtime/vm.rs | 22 ++++---- crates/rune/src/runtime/vm_error.rs | 7 --- 12 files changed, 81 insertions(+), 172 deletions(-) diff --git a/crates/rune/src/compile/context.rs b/crates/rune/src/compile/context.rs index c3427606c..bd6fa40d7 100644 --- a/crates/rune/src/compile/context.rs +++ b/crates/rune/src/compile/context.rs @@ -21,7 +21,7 @@ use crate::module::{ }; use crate::runtime::{ AnyTypeInfo, ConstConstruct, ConstContext, ConstValue, FunctionHandler, InstAddress, Memory, - Output, Protocol, RuntimeContext, TypeCheck, TypeInfo, VariantRtti, VmResult, + Output, Protocol, Rtti, RuntimeContext, TypeCheck, TypeInfo, VmResult, }; use crate::{Hash, Item, ItemBuf}; @@ -771,9 +771,9 @@ impl Context { item: item.try_clone()?, hash, type_check: None, - type_info: TypeInfo::variant(Arc::new(VariantRtti { - enum_hash: ty.hash, - hash, + type_info: TypeInfo::typed(Arc::new(Rtti { + hash: ty.hash, + variant_hash: hash, item: item.try_clone()?, fields: fields.to_fields()?, })), diff --git a/crates/rune/src/compile/error.rs b/crates/rune/src/compile/error.rs index a4164ff1c..b6690f894 100644 --- a/crates/rune/src/compile/error.rs +++ b/crates/rune/src/compile/error.rs @@ -545,7 +545,7 @@ pub(crate) enum ErrorKind { path: Vec, }, LastUseComponent, - VariantRttiConflict { + RttiConflict { hash: Hash, }, TypeRttiConflict { @@ -1113,7 +1113,7 @@ impl fmt::Display for ErrorKind { ErrorKind::LastUseComponent => { write!(f, "Missing last use component")?; } - ErrorKind::VariantRttiConflict { hash } => { + ErrorKind::RttiConflict { hash } => { write!(f,"Tried to insert variant runtime type information, but conflicted with hash `{hash}`")?; } ErrorKind::TypeRttiConflict { hash } => { diff --git a/crates/rune/src/compile/unit_builder.rs b/crates/rune/src/compile/unit_builder.rs index 0fd58c64d..6dc0381a0 100644 --- a/crates/rune/src/compile/unit_builder.rs +++ b/crates/rune/src/compile/unit_builder.rs @@ -18,8 +18,7 @@ use crate::query::QueryInner; use crate::runtime::debug::{DebugArgs, DebugSignature}; use crate::runtime::unit::UnitEncoder; use crate::runtime::{ - Call, ConstValue, DebugInfo, DebugInst, Inst, Label, Protocol, Rtti, StaticString, Unit, - UnitFn, VariantRtti, + Call, ConstValue, DebugInfo, DebugInst, Inst, Label, Protocol, Rtti, StaticString, Unit, UnitFn, }; use crate::{Context, Diagnostics, Hash, Item, SourceId}; @@ -74,8 +73,6 @@ pub(crate) struct UnitBuilder { static_object_keys_rev: HashMap, /// Runtime type information for types. rtti: hash::Map>, - /// Runtime type information for variants. - variant_rtti: hash::Map>, /// The current label count. label_count: usize, /// A collection of required function hashes. @@ -153,7 +150,6 @@ impl UnitBuilder { self.static_bytes, self.static_object_keys, self.rtti, - self.variant_rtti, self.debug, self.constants, )) @@ -317,6 +313,7 @@ impl UnitBuilder { let rtti = Arc::new(Rtti { hash, + variant_hash: Hash::EMPTY, item: pool.item(meta.item_meta.item).try_to_owned()?, fields: HashMap::new(), }); @@ -348,6 +345,7 @@ impl UnitBuilder { let rtti = Arc::new(Rtti { hash: meta.hash, + variant_hash: Hash::EMPTY, item: pool.item(meta.item_meta.item).try_to_owned()?, fields: HashMap::new(), }); @@ -405,6 +403,7 @@ impl UnitBuilder { let rtti = Arc::new(Rtti { hash: meta.hash, + variant_hash: Hash::EMPTY, item: pool.item(meta.item_meta.item).try_to_owned()?, fields: HashMap::new(), }); @@ -454,6 +453,7 @@ impl UnitBuilder { let rtti = Arc::new(Rtti { hash, + variant_hash: Hash::EMPTY, item: pool.item(meta.item_meta.item).try_to_owned()?, fields: named.to_fields()?, }); @@ -477,22 +477,22 @@ impl UnitBuilder { fields: meta::Fields::Empty, .. } => { - let rtti = Arc::new(VariantRtti { - enum_hash, - hash: meta.hash, + let rtti = Arc::new(Rtti { + hash: enum_hash, + variant_hash: meta.hash, item: pool.item(meta.item_meta.item).try_to_owned()?, fields: HashMap::new(), }); if self - .variant_rtti + .rtti .try_insert(meta.hash, rtti) .with_span(span)? .is_some() { return Err(compile::Error::new( span, - ErrorKind::VariantRttiConflict { hash: meta.hash }, + ErrorKind::RttiConflict { hash: meta.hash }, )); } @@ -526,22 +526,22 @@ impl UnitBuilder { fields: meta::Fields::Unnamed(args), .. } => { - let rtti = Arc::new(VariantRtti { - enum_hash, - hash: meta.hash, + let rtti = Arc::new(Rtti { + hash: enum_hash, + variant_hash: meta.hash, item: pool.item(meta.item_meta.item).try_to_owned()?, fields: HashMap::new(), }); if self - .variant_rtti + .rtti .try_insert(meta.hash, rtti) .with_span(span)? .is_some() { return Err(compile::Error::new( span, - ErrorKind::VariantRttiConflict { hash: meta.hash }, + ErrorKind::RttiConflict { hash: meta.hash }, )); } @@ -580,23 +580,15 @@ impl UnitBuilder { } => { let hash = pool.item_type_hash(meta.item_meta.item); - let rtti = Arc::new(VariantRtti { - enum_hash, - hash, + let rtti = Arc::new(Rtti { + hash: enum_hash, + variant_hash: hash, item: pool.item(meta.item_meta.item).try_to_owned()?, fields: named.to_fields()?, }); - if self - .variant_rtti - .try_insert(hash, rtti) - .with_span(span)? - .is_some() - { - return Err(compile::Error::new( - span, - ErrorKind::VariantRttiConflict { hash }, - )); + if self.rtti.try_insert(hash, rtti).with_span(span)?.is_some() { + return Err(compile::Error::new(span, ErrorKind::RttiConflict { hash })); } } meta::Kind::Enum { .. } => { diff --git a/crates/rune/src/runtime/function.rs b/crates/rune/src/runtime/function.rs index ded84a248..6fdcb1796 100644 --- a/crates/rune/src/runtime/function.rs +++ b/crates/rune/src/runtime/function.rs @@ -16,8 +16,8 @@ use crate::Hash; use super::{ Args, Call, ConstValue, Formatter, FromValue, FunctionHandler, GuardedArgs, InstAddress, - Output, OwnedTuple, Rtti, RuntimeContext, RuntimeError, Stack, Unit, Value, VariantRtti, Vm, - VmCall, VmErrorKind, VmHalt, VmResult, + Output, OwnedTuple, Rtti, RuntimeContext, RuntimeError, Stack, Unit, Value, Vm, VmCall, + VmErrorKind, VmHalt, VmResult, }; /// The type of a function in Rune. @@ -256,12 +256,12 @@ impl Function { } /// Create a function pointer that constructs a empty variant. - pub(crate) fn from_unit_variant(rtti: Arc) -> Self { + pub(crate) fn from_unit_variant(rtti: Arc) -> Self { Self(FunctionImpl::from_unit_variant(rtti)) } /// Create a function pointer that constructs a tuple variant. - pub(crate) fn from_tuple_variant(rtti: Arc, args: usize) -> Self { + pub(crate) fn from_tuple_variant(rtti: Arc, args: usize) -> Self { Self(FunctionImpl::from_tuple_variant(rtti, args)) } @@ -766,14 +766,14 @@ where } /// Create a function pointer that constructs a empty variant. - pub(crate) fn from_unit_variant(rtti: Arc) -> Self { + pub(crate) fn from_unit_variant(rtti: Arc) -> Self { Self { inner: Inner::FnUnitVariant(FnUnitVariant { rtti }), } } /// Create a function pointer that constructs a tuple variant. - pub(crate) fn from_tuple_variant(rtti: Arc, args: usize) -> Self { + pub(crate) fn from_tuple_variant(rtti: Arc, args: usize) -> Self { Self { inner: Inner::FnTupleVariant(FnTupleVariant { rtti, args }), } @@ -1032,13 +1032,13 @@ struct FnTupleStruct { #[derive(Debug, Clone, TryClone)] struct FnUnitVariant { /// Runtime information fo variant. - rtti: Arc, + rtti: Arc, } #[derive(Debug, Clone, TryClone)] struct FnTupleVariant { /// Runtime information fo variant. - rtti: Arc, + rtti: Arc, /// The number of arguments the tuple takes. args: usize, } diff --git a/crates/rune/src/runtime/mod.rs b/crates/rune/src/runtime/mod.rs index bf8c8d6a9..e8e50155e 100644 --- a/crates/rune/src/runtime/mod.rs +++ b/crates/rune/src/runtime/mod.rs @@ -163,7 +163,7 @@ pub use self::unit::{Unit, UnitStorage}; mod value; pub use self::value::{ Accessor, EmptyStruct, Inline, RawValueGuard, Rtti, Struct, TupleStruct, TypeValue, Value, - ValueMutGuard, ValueRefGuard, VariantRtti, + ValueMutGuard, ValueRefGuard, }; pub(crate) use self::value::{Mutable, ReprMut, ReprOwned, ReprRef}; diff --git a/crates/rune/src/runtime/type_info.rs b/crates/rune/src/runtime/type_info.rs index 1ff64cdc2..ae32a2cbe 100644 --- a/crates/rune/src/runtime/type_info.rs +++ b/crates/rune/src/runtime/type_info.rs @@ -9,16 +9,14 @@ use crate::{Any, TypeHash}; use ::rust_alloc::sync::Arc; -use super::{Rtti, VariantRtti}; +use super::Rtti; #[derive(Debug, TryClone, PartialEq, Eq)] enum TypeInfoKind { /// Reference to an external type. Any(AnyTypeInfo), /// A named type. - Typed(Arc), - /// A variant. - Variant(Arc), + Runtime(Arc), } /// Diagnostical type information for a given type. @@ -67,20 +65,14 @@ impl TypeInfo { #[inline] pub(crate) const fn typed(rtti: Arc) -> Self { - Self::new(TypeInfoKind::Typed(rtti)) - } - - #[inline] - pub(crate) const fn variant(rtti: Arc) -> Self { - Self::new(TypeInfoKind::Variant(rtti)) + Self::new(TypeInfoKind::Runtime(rtti)) } #[cfg(feature = "emit")] pub(crate) fn type_hash(&self) -> Hash { match &self.kind { - TypeInfoKind::Typed(ty) => ty.hash, - TypeInfoKind::Variant(ty) => ty.hash, TypeInfoKind::Any(ty) => ty.hash, + TypeInfoKind::Runtime(ty) => ty.hash, } } } @@ -95,10 +87,7 @@ impl fmt::Debug for TypeInfo { impl fmt::Display for TypeInfo { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.kind { - TypeInfoKind::Typed(rtti) => { - write!(f, "{}", rtti.item)?; - } - TypeInfoKind::Variant(rtti) => { + TypeInfoKind::Runtime(rtti) => { write!(f, "{}", rtti.item)?; } TypeInfoKind::Any(info) => { diff --git a/crates/rune/src/runtime/unit.rs b/crates/rune/src/runtime/unit.rs index 4cddf814f..2f46400d6 100644 --- a/crates/rune/src/runtime/unit.rs +++ b/crates/rune/src/runtime/unit.rs @@ -18,9 +18,7 @@ use crate as rune; use crate::alloc::prelude::*; use crate::alloc::{self, Box, String, Vec}; use crate::hash; -use crate::runtime::{ - Call, ConstValue, DebugInfo, Inst, Rtti, StaticString, VariantRtti, VmError, VmErrorKind, -}; +use crate::runtime::{Call, ConstValue, DebugInfo, Inst, Rtti, StaticString, VmError, VmErrorKind}; use crate::Hash; pub use self::storage::{ArrayUnit, EncodeError, UnitEncoder, UnitStorage}; @@ -72,8 +70,6 @@ pub struct Logic { static_object_keys: Vec>, /// Runtime information for types. rtti: hash::Map>, - /// Runtime information for variants. - variant_rtti: hash::Map>, /// Named constants constants: hash::Map, } @@ -96,7 +92,6 @@ impl Unit { static_bytes: Vec>, static_object_keys: Vec>, rtti: hash::Map>, - variant_rtti: hash::Map>, debug: Option>, constants: hash::Map, ) -> Self { @@ -108,7 +103,6 @@ impl Unit { static_bytes, static_object_keys, rtti, - variant_rtti, constants, }, debug, @@ -194,11 +188,6 @@ impl Unit { self.logic.rtti.get(&hash) } - /// Lookup variant run-time information for the given variant hash. - pub(crate) fn lookup_variant_rtti(&self, hash: Hash) -> Option<&Arc> { - self.logic.variant_rtti.get(&hash) - } - /// Lookup a function in the unit. pub(crate) fn function(&self, hash: Hash) -> Option { self.logic.functions.get(&hash).copied() diff --git a/crates/rune/src/runtime/value.rs b/crates/rune/src/runtime/value.rs index 8b9cf78d6..7b459fee5 100644 --- a/crates/rune/src/runtime/value.rs +++ b/crates/rune/src/runtime/value.rs @@ -7,7 +7,7 @@ pub use self::inline::Inline; mod serde; mod rtti; -pub use self::rtti::{Accessor, Rtti, VariantRtti}; +pub use self::rtti::{Accessor, Rtti}; mod data; pub use self::data::{EmptyStruct, Struct, TupleStruct}; @@ -592,12 +592,12 @@ impl Value { } /// Construct an empty variant. - pub fn unit_variant(rtti: Arc) -> VmResult { + pub fn unit_variant(rtti: Arc) -> VmResult { VmResult::Ok(vm_try!(Value::try_from(Variant::unit(rtti)))) } /// Construct a tuple variant. - pub fn tuple_variant(rtti: Arc, vec: alloc::Vec) -> VmResult { + pub fn tuple_variant(rtti: Arc, vec: alloc::Vec) -> VmResult { let data = vm_try!(OwnedTuple::try_from(vec)); VmResult::Ok(vm_try!(Value::try_from(Variant::tuple(rtti, data)))) @@ -1206,7 +1206,7 @@ impl Value { } } (Mutable::Variant(a), Mutable::Variant(b)) => { - if a.rtti().enum_hash == b.rtti().enum_hash { + if a.rtti().hash == b.rtti().hash { return Variant::partial_eq_with(a, b, caller); } } @@ -1368,7 +1368,7 @@ impl Value { } } (Mutable::Variant(a), Mutable::Variant(b)) => { - if a.rtti().enum_hash == b.rtti().enum_hash { + if a.rtti().hash == b.rtti().hash { return Variant::eq_with(a, b, caller); } } @@ -1453,7 +1453,7 @@ impl Value { } } (Mutable::Variant(a), Mutable::Variant(b)) => { - if a.rtti().enum_hash == b.rtti().enum_hash { + if a.rtti().hash == b.rtti().hash { return Variant::partial_cmp_with(a, b, caller); } } @@ -1529,7 +1529,7 @@ impl Value { } } (Mutable::Variant(a), Mutable::Variant(b)) => { - if a.rtti().enum_hash == b.rtti().enum_hash { + if a.rtti().hash == b.rtti().hash { return Variant::cmp_with(a, b, caller); } } @@ -2032,7 +2032,7 @@ impl Mutable { Mutable::EmptyStruct(empty) => empty.rtti.hash, Mutable::TupleStruct(tuple) => tuple.rtti.hash, Mutable::Struct(object) => object.rtti.hash, - Mutable::Variant(variant) => variant.rtti().enum_hash, + Mutable::Variant(variant) => variant.rtti().hash, } } } diff --git a/crates/rune/src/runtime/value/rtti.rs b/crates/rune/src/runtime/value/rtti.rs index 85bf2fb5b..55f09bb67 100644 --- a/crates/rune/src/runtime/value/rtti.rs +++ b/crates/rune/src/runtime/value/rtti.rs @@ -9,66 +9,6 @@ use crate::alloc::HashMap; use crate::runtime::Value; use crate::{Hash, ItemBuf}; -/// Runtime information on variant. -#[derive(Debug, Serialize, Deserialize)] -#[non_exhaustive] -pub struct VariantRtti { - /// The type hash of the enum. - pub enum_hash: Hash, - /// The type variant hash. - pub hash: Hash, - /// The name of the variant. - pub item: ItemBuf, - /// Fields associated with the variant. - pub fields: HashMap, usize>, -} - -impl VariantRtti { - /// Access a named field mutably from the given data. - pub fn get_field<'a, Q>(&self, data: &'a [Value], key: &Q) -> Option<&'a Value> - where - Box: Borrow, - Q: hash::Hash + Eq + ?Sized, - { - data.get(*self.fields.get(key)?) - } - - /// Access a named field immutably from the given data. - pub fn get_field_mut<'a, Q>(&self, data: &'a mut [Value], key: &Q) -> Option<&'a mut Value> - where - Box: Borrow, - Q: hash::Hash + Eq + ?Sized, - { - data.get_mut(*self.fields.get(key)?) - } -} - -impl PartialEq for VariantRtti { - fn eq(&self, other: &Self) -> bool { - self.hash == other.hash - } -} - -impl Eq for VariantRtti {} - -impl hash::Hash for VariantRtti { - fn hash(&self, state: &mut H) { - self.hash.hash(state) - } -} - -impl PartialOrd for VariantRtti { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for VariantRtti { - fn cmp(&self, other: &Self) -> Ordering { - self.hash.cmp(&other.hash) - } -} - /// Field accessor for a variant struct. #[doc(hidden)] pub struct Accessor<'a> { @@ -94,6 +34,8 @@ impl<'a> Accessor<'a> { pub struct Rtti { /// The type hash of the type. pub hash: Hash, + /// If this type is a variant, designates the hash of the variant. + pub variant_hash: Hash, /// The item of the type. pub item: ItemBuf, /// Mapping from field names to their corresponding indexes. @@ -122,7 +64,7 @@ impl Rtti { impl PartialEq for Rtti { fn eq(&self, other: &Self) -> bool { - self.hash == other.hash + self.hash == other.hash && self.variant_hash == other.variant_hash } } @@ -130,7 +72,8 @@ impl Eq for Rtti {} impl hash::Hash for Rtti { fn hash(&self, state: &mut H) { - self.hash.hash(state) + self.hash.hash(state); + self.variant_hash.hash(state); } } @@ -141,7 +84,10 @@ impl PartialOrd for Rtti { } impl Ord for Rtti { + #[inline] fn cmp(&self, other: &Self) -> Ordering { - self.hash.cmp(&other.hash) + self.hash + .cmp(&other.hash) + .then_with(|| self.variant_hash.cmp(&other.variant_hash)) } } diff --git a/crates/rune/src/runtime/variant.rs b/crates/rune/src/runtime/variant.rs index e079d577a..87c5696e1 100644 --- a/crates/rune/src/runtime/variant.rs +++ b/crates/rune/src/runtime/variant.rs @@ -8,14 +8,14 @@ use crate::alloc::clone::TryClone; use crate::alloc::Box; use super::{ - Accessor, FromValue, Mutable, OwnedTuple, ProtocolCaller, ReprOwned, RuntimeError, Tuple, - TypeInfo, Value, VariantRtti, Vec, VmResult, + Accessor, FromValue, Mutable, OwnedTuple, ProtocolCaller, ReprOwned, Rtti, RuntimeError, Tuple, + TypeInfo, Value, Vec, VmResult, }; /// The variant of a type. #[derive(TryClone)] pub struct Variant { - pub(crate) rtti: Arc, + pub(crate) rtti: Arc, pub(crate) data: VariantData, } @@ -38,7 +38,7 @@ impl Variant { } /// Construct a unit variant. - pub(crate) fn unit(rtti: Arc) -> Self { + pub(crate) fn unit(rtti: Arc) -> Self { Self { rtti, data: VariantData::Empty, @@ -46,7 +46,7 @@ impl Variant { } /// Construct a tuple variant. - pub(crate) fn tuple(rtti: Arc, tuple: OwnedTuple) -> Self { + pub(crate) fn tuple(rtti: Arc, tuple: OwnedTuple) -> Self { Self { rtti, data: VariantData::Tuple(tuple), @@ -54,7 +54,7 @@ impl Variant { } /// Construct a struct variant. - pub(crate) fn struct_(rtti: Arc, data: Box<[Value]>) -> Self { + pub(crate) fn struct_(rtti: Arc, data: Box<[Value]>) -> Self { Self { rtti, data: VariantData::Struct(data), @@ -62,7 +62,7 @@ impl Variant { } /// Access the rtti of the variant. - pub fn rtti(&self) -> &VariantRtti { + pub fn rtti(&self) -> &Rtti { &self.rtti } @@ -78,7 +78,7 @@ impl Variant { /// Get type info for the variant. pub(crate) fn type_info(&self) -> TypeInfo { - TypeInfo::variant(self.rtti.clone()) + TypeInfo::typed(self.rtti.clone()) } pub(crate) fn partial_eq_with( @@ -87,7 +87,7 @@ impl Variant { caller: &mut dyn ProtocolCaller, ) -> VmResult { debug_assert_eq!( - a.rtti.enum_hash, b.rtti.enum_hash, + a.rtti.hash, b.rtti.hash, "comparison only makes sense if enum hashes match" ); @@ -109,7 +109,7 @@ impl Variant { pub(crate) fn eq_with(a: &Self, b: &Self, caller: &mut dyn ProtocolCaller) -> VmResult { debug_assert_eq!( - a.rtti.enum_hash, b.rtti.enum_hash, + a.rtti.hash, b.rtti.hash, "comparison only makes sense if enum hashes match" ); @@ -135,7 +135,7 @@ impl Variant { caller: &mut dyn ProtocolCaller, ) -> VmResult> { debug_assert_eq!( - a.rtti.enum_hash, b.rtti.enum_hash, + a.rtti.hash, b.rtti.hash, "comparison only makes sense if enum hashes match" ); @@ -158,7 +158,7 @@ impl Variant { caller: &mut dyn ProtocolCaller, ) -> VmResult { debug_assert_eq!( - a.rtti.enum_hash, b.rtti.enum_hash, + a.rtti.hash, b.rtti.hash, "comparison only makes sense if enum hashes match" ); diff --git a/crates/rune/src/runtime/vm.rs b/crates/rune/src/runtime/vm.rs index 34c96c61a..dba24fee5 100644 --- a/crates/rune/src/runtime/vm.rs +++ b/crates/rune/src/runtime/vm.rs @@ -2717,16 +2717,16 @@ impl Vm { UnitFn::UnitVariant { hash } => { let rtti = self .unit - .lookup_variant_rtti(hash) - .ok_or(VmErrorKind::MissingVariantRtti { hash })?; + .lookup_rtti(hash) + .ok_or(VmErrorKind::MissingRtti { hash })?; Function::from_unit_variant(rtti.clone()) } UnitFn::TupleVariant { hash, args } => { let rtti = self .unit - .lookup_variant_rtti(hash) - .ok_or(VmErrorKind::MissingVariantRtti { hash })?; + .lookup_rtti(hash) + .ok_or(VmErrorKind::MissingRtti { hash })?; Function::from_tuple_variant(rtti.clone(), args) } @@ -3058,8 +3058,8 @@ impl Vm { fn op_struct_variant(&mut self, addr: InstAddress, hash: Hash, out: Output) -> VmResult<()> { let rtti = vm_try!(self .unit - .lookup_variant_rtti(hash) - .ok_or(VmErrorKind::MissingVariantRtti { hash })); + .lookup_rtti(hash) + .ok_or(VmErrorKind::MissingRtti { hash })); let mut data = vm_try!(alloc::Vec::try_with_capacity(rtti.fields.len())); let values = vm_try!(self.stack.slice_at_mut(addr, rtti.fields.len())); @@ -3313,7 +3313,7 @@ impl Vm { ReprRef::Mutable(value) => match &*vm_try!(value.borrow_ref()) { Mutable::Variant(variant) => { let rtti = variant.rtti(); - break 'out rtti.enum_hash == enum_hash && rtti.hash == variant_hash; + break 'out rtti.hash == enum_hash && rtti.hash == variant_hash; } _ => { break 'out false; @@ -3578,8 +3578,8 @@ impl Vm { let rtti = vm_try!(self .unit - .lookup_variant_rtti(hash) - .ok_or(VmErrorKind::MissingVariantRtti { hash })); + .lookup_rtti(hash) + .ok_or(VmErrorKind::MissingRtti { hash })); let tuple = vm_try!(self.stack.slice_at_mut(addr, args)); let tuple = vm_try!(tuple.iter_mut().map(take).try_collect()); @@ -3594,8 +3594,8 @@ impl Vm { let rtti = vm_try!(self .unit - .lookup_variant_rtti(hash) - .ok_or(VmErrorKind::MissingVariantRtti { hash })); + .lookup_rtti(hash) + .ok_or(VmErrorKind::MissingRtti { hash })); vm_try!(out.store(&mut self.stack, || Value::unit_variant(rtti.clone()))); } diff --git a/crates/rune/src/runtime/vm_error.rs b/crates/rune/src/runtime/vm_error.rs index 464acf74c..da6283590 100644 --- a/crates/rune/src/runtime/vm_error.rs +++ b/crates/rune/src/runtime/vm_error.rs @@ -692,9 +692,6 @@ pub(crate) enum VmErrorKind { MissingStaticObjectKeys { slot: usize, }, - MissingVariantRtti { - hash: Hash, - }, MissingRtti { hash: Hash, }, @@ -911,10 +908,6 @@ impl fmt::Display for VmErrorKind { VmErrorKind::MissingStaticObjectKeys { slot } => { write!(f, "Static object keys slot `{slot}` does not exist") } - VmErrorKind::MissingVariantRtti { hash } => write!( - f, - "Missing runtime information for variant with hash `{hash}`", - ), VmErrorKind::MissingRtti { hash } => { write!(f, "Missing runtime information for type with hash `{hash}`") }