diff --git a/crates/fayalite/src/expr.rs b/crates/fayalite/src/expr.rs index 016ec8e..f0008f4 100644 --- a/crates/fayalite/src/expr.rs +++ b/crates/fayalite/src/expr.rs @@ -16,7 +16,6 @@ use crate::{ transform::visit::{Fold, Folder, Visit, Visitor}, Instance, ModuleIO, }, - phantom_const::PhantomConst, reg::Reg, reset::{AsyncReset, Reset, ResetType, ResetTypeDispatch, SyncReset}, ty::{CanonicalType, StaticType, Type, TypeWithDeref}, @@ -110,7 +109,6 @@ expr_enum! { UIntLiteral(Interned), SIntLiteral(Interned), BoolLiteral(bool), - PhantomConst(PhantomConst), BundleLiteral(ops::BundleLiteral), ArrayLiteral(ops::ArrayLiteral), EnumLiteral(ops::EnumLiteral), @@ -757,27 +755,3 @@ pub fn repeat( ) .to_expr() } - -impl ToExpr for PhantomConst { - type Type = Self; - - fn to_expr(&self) -> Expr { - Expr { - __enum: ExprEnum::PhantomConst(self.canonical_phantom_const()).intern_sized(), - __ty: *self, - __flow: Flow::Source, - } - } -} - -impl GetTarget for PhantomConst { - fn target(&self) -> Option> { - None - } -} - -impl ToLiteralBits for PhantomConst { - fn to_literal_bits(&self) -> Result, NotALiteralExpr> { - Ok(Interned::default()) - } -} diff --git a/crates/fayalite/src/expr/ops.rs b/crates/fayalite/src/expr/ops.rs index e794a68..c502fd5 100644 --- a/crates/fayalite/src/expr/ops.rs +++ b/crates/fayalite/src/expr/ops.rs @@ -11,15 +11,14 @@ use crate::{ GetTarget, Target, TargetPathArrayElement, TargetPathBundleField, TargetPathDynArrayElement, TargetPathElement, }, - CastBitsTo as _, CastTo, CastToBits as _, Expr, ExprEnum, Flow, HdlPartialEq, - HdlPartialOrd, NotALiteralExpr, ReduceBits, ToExpr, ToLiteralBits, + CastTo, Expr, ExprEnum, Flow, HdlPartialEq, HdlPartialOrd, NotALiteralExpr, ReduceBits, + ToExpr, ToLiteralBits, }, int::{ Bool, BoolOrIntType, DynSize, IntType, KnownSize, SInt, SIntType, SIntValue, Size, UInt, UIntType, UIntValue, }, intern::{Intern, Interned}, - phantom_const::{PhantomConst, PhantomConstValue}, reset::{ AsyncReset, Reset, ResetType, ResetTypeDispatch, SyncReset, ToAsyncReset, ToReset, ToSyncReset, @@ -1893,26 +1892,6 @@ impl ExprCastTo for Clock { } } -impl ExprCastTo<()> for PhantomConst { - fn cast_to(src: Expr, to_type: ()) -> Expr<()> { - src.cast_to_bits().cast_bits_to(to_type) - } -} - -impl ExprCastTo> for () { - fn cast_to(src: Expr, to_type: PhantomConst) -> Expr> { - src.cast_to_bits().cast_bits_to(to_type) - } -} - -impl ExprCastTo> - for PhantomConst -{ - fn cast_to(src: Expr, to_type: PhantomConst) -> Expr> { - src.cast_to_bits().cast_bits_to(to_type) - } -} - #[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct FieldAccess { base: Expr, diff --git a/crates/fayalite/src/firrtl.rs b/crates/fayalite/src/firrtl.rs index dd5fc2e..ea76cf8 100644 --- a/crates/fayalite/src/firrtl.rs +++ b/crates/fayalite/src/firrtl.rs @@ -15,7 +15,7 @@ use crate::{ target::{ Target, TargetBase, TargetPathArrayElement, TargetPathBundleField, TargetPathElement, }, - CastBitsTo, Expr, ExprEnum, + Expr, ExprEnum, }, formal::FormalKind, int::{Bool, DynSize, IntType, SIntValue, UInt, UIntValue}, @@ -447,7 +447,6 @@ impl TypeState { CanonicalType::AsyncReset(AsyncReset {}) => "AsyncReset".into(), CanonicalType::SyncReset(SyncReset {}) => "UInt<1>".into(), CanonicalType::Reset(Reset {}) => "Reset".into(), - CanonicalType::PhantomConst(_) => "{}".into(), } } } @@ -1153,7 +1152,6 @@ impl<'a> Exporter<'a> { | CanonicalType::Clock(_) | CanonicalType::AsyncReset(_) | CanonicalType::Reset(_) => format!("asUInt({value_str})"), - CanonicalType::PhantomConst(_) => "UInt<0>(0)".into(), } } fn expr_cast_bits_to_bundle( @@ -1359,12 +1357,6 @@ impl<'a> Exporter<'a> { CanonicalType::AsyncReset(_) => format!("asAsyncReset({value_str})"), CanonicalType::SyncReset(_) => value_str, CanonicalType::Reset(_) => unreachable!("Reset is not bit castable to"), - CanonicalType::PhantomConst(_) => { - let retval = self.module.ns.make_new("_cast_bits_to_phantom_const_expr"); - definitions.add_definition_line(format_args!("{extra_indent}wire {retval}: {{}}")); - definitions.add_definition_line(format_args!("{extra_indent}invalidate {retval}")); - return retval.to_string(); - } } } fn expr_unary( @@ -1403,11 +1395,6 @@ impl<'a> Exporter<'a> { ExprEnum::UIntLiteral(literal) => self.uint_literal(&literal), ExprEnum::SIntLiteral(literal) => self.sint_literal(&literal), ExprEnum::BoolLiteral(literal) => self.bool_literal(literal), - ExprEnum::PhantomConst(ty) => self.expr( - UInt[0].zero().cast_bits_to(ty.canonical()), - definitions, - const_ty, - ), ExprEnum::ArrayLiteral(array_literal) => { self.array_literal_expr(array_literal, definitions, const_ty) } diff --git a/crates/fayalite/src/lib.rs b/crates/fayalite/src/lib.rs index 512572d..88fe169 100644 --- a/crates/fayalite/src/lib.rs +++ b/crates/fayalite/src/lib.rs @@ -96,7 +96,6 @@ pub mod int; pub mod intern; pub mod memory; pub mod module; -pub mod phantom_const; pub mod prelude; pub mod reg; pub mod reset; diff --git a/crates/fayalite/src/memory.rs b/crates/fayalite/src/memory.rs index 1101157..2f0ec47 100644 --- a/crates/fayalite/src/memory.rs +++ b/crates/fayalite/src/memory.rs @@ -1082,7 +1082,6 @@ pub fn splat_mask(ty: T, value: Expr) -> Expr> { ) .to_expr(), )), - CanonicalType::PhantomConst(_) => Expr::from_canonical(Expr::canonical(().to_expr())), } } diff --git a/crates/fayalite/src/module.rs b/crates/fayalite/src/module.rs index 446746a..5a18ac9 100644 --- a/crates/fayalite/src/module.rs +++ b/crates/fayalite/src/module.rs @@ -1490,9 +1490,6 @@ impl TargetState { }) .collect(), }, - CanonicalType::PhantomConst(_) => TargetStateInner::Decomposed { - subtargets: HashMap::new(), - }, CanonicalType::Array(ty) => TargetStateInner::Decomposed { subtargets: (0..ty.len()) .map(|index| { diff --git a/crates/fayalite/src/module/transform/deduce_resets.rs b/crates/fayalite/src/module/transform/deduce_resets.rs index a70dc33..fe518a5 100644 --- a/crates/fayalite/src/module/transform/deduce_resets.rs +++ b/crates/fayalite/src/module/transform/deduce_resets.rs @@ -155,7 +155,6 @@ impl ResetsLayout { CanonicalType::SyncReset(_) => ResetsLayout::SyncReset, CanonicalType::Reset(_) => ResetsLayout::Reset, CanonicalType::Clock(_) => ResetsLayout::NoResets, - CanonicalType::PhantomConst(_) => ResetsLayout::NoResets, } } } @@ -408,8 +407,7 @@ impl Resets { | CanonicalType::Bool(_) | CanonicalType::AsyncReset(_) | CanonicalType::SyncReset(_) - | CanonicalType::Clock(_) - | CanonicalType::PhantomConst(_) => Ok(self.ty), + | CanonicalType::Clock(_) => Ok(self.ty), CanonicalType::Array(ty) => Ok(CanonicalType::Array(Array::new_dyn( self.array_elements().substituted_type( reset_graph, @@ -1000,8 +998,7 @@ fn cast_bit_op( CanonicalType::Array(_) | CanonicalType::Enum(_) | CanonicalType::Bundle(_) - | CanonicalType::Reset(_) - | CanonicalType::PhantomConst(_) => unreachable!(), + | CanonicalType::Reset(_) => unreachable!(), $(CanonicalType::$Variant(ty) => Expr::expr_enum($arg.cast_to(ty)),)* } }; @@ -1013,7 +1010,6 @@ fn cast_bit_op( | CanonicalType::Enum(_) | CanonicalType::Bundle(_) | CanonicalType::Reset(_) => unreachable!(), - CanonicalType::PhantomConst(_) => Expr::expr_enum(arg), $(CanonicalType::$Variant(_) => { let arg = Expr::<$Variant>::from_canonical(arg); match_expr_ty!(arg, UInt, SInt, Bool, AsyncReset, SyncReset, Clock) @@ -1044,7 +1040,6 @@ impl RunPass

for ExprEnum { ExprEnum::UIntLiteral(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)), ExprEnum::SIntLiteral(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)), ExprEnum::BoolLiteral(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)), - ExprEnum::PhantomConst(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)), ExprEnum::BundleLiteral(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)), ExprEnum::ArrayLiteral(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)), ExprEnum::EnumLiteral(expr) => Ok(expr.run_pass(pass_args)?.map(ExprEnum::from)), @@ -1675,8 +1670,7 @@ impl RunPassDispatch for AnyReg { | CanonicalType::Enum(_) | CanonicalType::Bundle(_) | CanonicalType::Reset(_) - | CanonicalType::Clock(_) - | CanonicalType::PhantomConst(_) => unreachable!(), + | CanonicalType::Clock(_) => unreachable!(), } }) } @@ -1775,7 +1769,6 @@ impl_run_pass_copy!([] SVAttributeAnnotation); impl_run_pass_copy!([] UInt); impl_run_pass_copy!([] usize); impl_run_pass_copy!([] FormalKind); -impl_run_pass_copy!([] PhantomConst); macro_rules! impl_run_pass_for_struct { ( diff --git a/crates/fayalite/src/module/transform/simplify_enums.rs b/crates/fayalite/src/module/transform/simplify_enums.rs index e8b6168..4eb0d0c 100644 --- a/crates/fayalite/src/module/transform/simplify_enums.rs +++ b/crates/fayalite/src/module/transform/simplify_enums.rs @@ -69,8 +69,7 @@ fn contains_any_enum_types(ty: CanonicalType) -> bool { | CanonicalType::AsyncReset(_) | CanonicalType::SyncReset(_) | CanonicalType::Reset(_) - | CanonicalType::Clock(_) - | CanonicalType::PhantomConst(_) => false, + | CanonicalType::Clock(_) => false, } } } @@ -513,8 +512,7 @@ impl State { | CanonicalType::AsyncReset(_) | CanonicalType::SyncReset(_) | CanonicalType::Reset(_) - | CanonicalType::Clock(_) - | CanonicalType::PhantomConst(_) => unreachable!(), + | CanonicalType::Clock(_) => unreachable!(), } } } @@ -579,8 +577,7 @@ fn connect_port( | (CanonicalType::Clock(_), _) | (CanonicalType::AsyncReset(_), _) | (CanonicalType::SyncReset(_), _) - | (CanonicalType::Reset(_), _) - | (CanonicalType::PhantomConst(_), _) => unreachable!( + | (CanonicalType::Reset(_), _) => unreachable!( "trying to connect memory ports:\n{:?}\n{:?}", Expr::ty(lhs), Expr::ty(rhs), @@ -668,7 +665,6 @@ impl Folder for State { ExprEnum::UIntLiteral(_) | ExprEnum::SIntLiteral(_) | ExprEnum::BoolLiteral(_) - | ExprEnum::PhantomConst(_) | ExprEnum::BundleLiteral(_) | ExprEnum::ArrayLiteral(_) | ExprEnum::Uninit(_) @@ -927,8 +923,7 @@ impl Folder for State { | CanonicalType::Clock(_) | CanonicalType::AsyncReset(_) | CanonicalType::SyncReset(_) - | CanonicalType::Reset(_) - | CanonicalType::PhantomConst(_) => canonical_type.default_fold(self), + | CanonicalType::Reset(_) => canonical_type.default_fold(self), } } diff --git a/crates/fayalite/src/module/transform/simplify_memories.rs b/crates/fayalite/src/module/transform/simplify_memories.rs index 101385e..e8f9cbf 100644 --- a/crates/fayalite/src/module/transform/simplify_memories.rs +++ b/crates/fayalite/src/module/transform/simplify_memories.rs @@ -62,7 +62,6 @@ enum MemSplit { Bundle { fields: Rc<[MemSplit]>, }, - PhantomConst, Single { output_mem: Option, element_type: SingleType, @@ -77,7 +76,6 @@ impl MemSplit { fn mark_changed_element_type(self) -> Self { match self { MemSplit::Bundle { fields: _ } => self, - MemSplit::PhantomConst => self, MemSplit::Single { output_mem, element_type, @@ -99,7 +97,6 @@ impl MemSplit { .map(|field| Self::new(field.ty).mark_changed_element_type()) .collect(), }, - CanonicalType::PhantomConst(_) => MemSplit::PhantomConst, CanonicalType::Array(ty) => { let element = MemSplit::new(ty.element()); if let Self::Single { @@ -342,7 +339,6 @@ impl SplitMemState<'_, '_> { self.split_state_stack.pop(); } } - MemSplit::PhantomConst => {} MemSplit::Single { output_mem, element_type: single_type, @@ -542,12 +538,7 @@ impl ModuleState { }; loop { match input_element_type { - CanonicalType::Bundle(_) => { - unreachable!("bundle types are always split") - } - CanonicalType::PhantomConst(_) => { - unreachable!("PhantomConst are always removed") - } + CanonicalType::Bundle(_) => unreachable!("bundle types are always split"), CanonicalType::Enum(_) if input_array_types .first() @@ -752,8 +743,7 @@ impl ModuleState { .. } | MemSplit::Bundle { .. } - | MemSplit::Array { .. } - | MemSplit::PhantomConst => { + | MemSplit::Array { .. } => { let mut replacement_ports = Vec::with_capacity(input_mem.ports().len()); let mut wire_port_rdata = Vec::with_capacity(input_mem.ports().len()); let mut wire_port_wdata = Vec::with_capacity(input_mem.ports().len()); diff --git a/crates/fayalite/src/module/transform/visit.rs b/crates/fayalite/src/module/transform/visit.rs index 662a578..97de4fc 100644 --- a/crates/fayalite/src/module/transform/visit.rs +++ b/crates/fayalite/src/module/transform/visit.rs @@ -28,7 +28,6 @@ use crate::{ NormalModuleBody, ScopedNameId, Stmt, StmtConnect, StmtDeclaration, StmtFormal, StmtIf, StmtInstance, StmtMatch, StmtReg, StmtWire, }, - phantom_const::PhantomConst, reg::Reg, reset::{AsyncReset, Reset, ResetType, SyncReset}, source_location::SourceLocation, diff --git a/crates/fayalite/src/phantom_const.rs b/crates/fayalite/src/phantom_const.rs deleted file mode 100644 index 81f5d6f..0000000 --- a/crates/fayalite/src/phantom_const.rs +++ /dev/null @@ -1,273 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// See Notices.txt for copyright information - -use serde::{de::DeserializeOwned, Deserialize, Serialize}; - -use crate::{ - intern::{Intern, Interned, InternedCompare, LazyInterned, Memoize}, - source_location::SourceLocation, - ty::{impl_match_variant_as_self, CanonicalType, StaticType, Type, TypeProperties}, -}; -use std::{ - any::Any, - fmt, - hash::{Hash, Hasher}, - marker::PhantomData, -}; - -#[derive(Clone)] -pub struct PhantomConstCanonicalValue { - parsed: serde_json::Value, - serialized: Interned, -} - -impl PhantomConstCanonicalValue { - pub fn from_json_value(parsed: serde_json::Value) -> Self { - let serialized = Intern::intern_owned( - serde_json::to_string(&parsed) - .expect("conversion from json value to text shouldn't fail"), - ); - Self { parsed, serialized } - } - pub fn as_json_value(&self) -> &serde_json::Value { - &self.parsed - } - pub fn as_str(&self) -> Interned { - self.serialized - } -} - -impl fmt::Debug for PhantomConstCanonicalValue { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(&self.serialized) - } -} - -impl fmt::Display for PhantomConstCanonicalValue { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(&self.serialized) - } -} - -impl PartialEq for PhantomConstCanonicalValue { - fn eq(&self, other: &Self) -> bool { - self.serialized == other.serialized - } -} - -impl Eq for PhantomConstCanonicalValue {} - -impl Hash for PhantomConstCanonicalValue { - fn hash(&self, state: &mut H) { - self.serialized.hash(state); - } -} - -impl Serialize for PhantomConstCanonicalValue { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - self.parsed.serialize(serializer) - } -} - -impl<'de> Deserialize<'de> for PhantomConstCanonicalValue { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - Ok(Self::from_json_value(serde_json::Value::deserialize( - deserializer, - )?)) - } -} - -pub trait PhantomConstValue: Intern + InternedCompare + Serialize + fmt::Debug { - fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where - D: serde::Deserializer<'de>; -} - -impl PhantomConstValue for T -where - T: ?Sized + Intern + InternedCompare + Serialize + fmt::Debug, - Interned: DeserializeOwned, -{ - fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> - where - D: serde::Deserializer<'de>, - { - as Deserialize<'de>>::deserialize(deserializer) - } -} - -/// Wrapper type that allows any Rust value to be smuggled as a HDL [`Type`]. -/// This only works for values that can be [serialized][Serialize] to and [deserialized][Deserialize] from [JSON][serde_json]. -pub struct PhantomConst { - value: LazyInterned, -} - -impl fmt::Debug for PhantomConst { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_tuple("PhantomConst").field(&self.get()).finish() - } -} - -impl Clone for PhantomConst { - fn clone(&self) -> Self { - *self - } -} - -impl Copy for PhantomConst {} - -impl PartialEq for PhantomConst { - fn eq(&self, other: &Self) -> bool { - self.get() == other.get() - } -} - -impl Eq for PhantomConst {} - -impl Hash for PhantomConst { - fn hash(&self, state: &mut H) { - self.get().hash(state); - } -} - -struct PhantomConstCanonicalMemoize(PhantomData); - -impl Copy - for PhantomConstCanonicalMemoize -{ -} - -impl Clone - for PhantomConstCanonicalMemoize -{ - fn clone(&self) -> Self { - *self - } -} - -impl Eq - for PhantomConstCanonicalMemoize -{ -} - -impl PartialEq - for PhantomConstCanonicalMemoize -{ - fn eq(&self, _other: &Self) -> bool { - true - } -} - -impl Hash - for PhantomConstCanonicalMemoize -{ - fn hash(&self, _state: &mut H) {} -} - -impl Memoize for PhantomConstCanonicalMemoize { - type Input = Interned; - type InputOwned = Interned; - type Output = Interned; - - fn inner(self, input: &Self::Input) -> Self::Output { - Intern::intern_sized(PhantomConstCanonicalValue::from_json_value( - serde_json::to_value(input) - .expect("serialization failed when constructing a canonical PhantomConst"), - )) - } -} - -impl Memoize for PhantomConstCanonicalMemoize { - type Input = Interned; - type InputOwned = Interned; - type Output = Interned; - - fn inner(self, input: &Self::Input) -> Self::Output { - PhantomConstValue::deserialize(input.as_json_value()).expect("deserialization failed ") - } -} - -impl PhantomConst -where - Interned: Default, -{ - pub const fn default() -> Self { - PhantomConst { - value: LazyInterned::new_lazy(&Interned::::default), - } - } -} - -impl PhantomConst { - pub fn new(value: Interned) -> Self { - Self { - value: LazyInterned::Interned(value), - } - } - pub fn get(self) -> Interned { - self.value.interned() - } - pub fn type_properties(self) -> TypeProperties { - <()>::TYPE_PROPERTIES - } - pub fn can_connect(self, other: Self) -> bool { - self == other - } - pub fn canonical_phantom_const(self) -> PhantomConst { - if let Some(&retval) = ::downcast_ref::(&self) { - return retval; - } - ::new( - PhantomConstCanonicalMemoize::(PhantomData).get_owned(self.get()), - ) - } - pub fn from_canonical_phantom_const(canonical_type: PhantomConst) -> Self { - if let Some(&retval) = ::downcast_ref::(&canonical_type) { - return retval; - } - Self::new( - PhantomConstCanonicalMemoize::(PhantomData).get_owned(canonical_type.get()), - ) - } -} - -impl Type for PhantomConst { - type BaseType = PhantomConst; - type MaskType = (); - impl_match_variant_as_self!(); - - fn mask_type(&self) -> Self::MaskType { - () - } - - fn canonical(&self) -> CanonicalType { - CanonicalType::PhantomConst(self.canonical_phantom_const()) - } - - fn from_canonical(canonical_type: CanonicalType) -> Self { - let CanonicalType::PhantomConst(phantom_const) = canonical_type else { - panic!("expected PhantomConst"); - }; - Self::from_canonical_phantom_const(phantom_const) - } - - fn source_location() -> SourceLocation { - SourceLocation::builtin() - } -} - -impl StaticType for PhantomConst -where - Interned: Default, -{ - const TYPE: Self = Self::default(); - const MASK_TYPE: Self::MaskType = (); - const TYPE_PROPERTIES: TypeProperties = <()>::TYPE_PROPERTIES; - const MASK_TYPE_PROPERTIES: TypeProperties = <()>::TYPE_PROPERTIES; -} diff --git a/crates/fayalite/src/prelude.rs b/crates/fayalite/src/prelude.rs index 39fa143..9e7a85e 100644 --- a/crates/fayalite/src/prelude.rs +++ b/crates/fayalite/src/prelude.rs @@ -26,7 +26,6 @@ pub use crate::{ annotate, connect, connect_any, incomplete_wire, instance, memory, memory_array, memory_with_init, reg_builder, wire, Instance, Module, ModuleBuilder, }, - phantom_const::PhantomConst, reg::Reg, reset::{AsyncReset, Reset, SyncReset, ToAsyncReset, ToReset, ToSyncReset}, source_location::SourceLocation, diff --git a/crates/fayalite/src/sim.rs b/crates/fayalite/src/sim.rs index 96f6dd9..f630f5a 100644 --- a/crates/fayalite/src/sim.rs +++ b/crates/fayalite/src/sim.rs @@ -167,14 +167,6 @@ impl CompiledTypeLayout { body: CompiledTypeLayoutBody::Array { element }, } } - CanonicalType::PhantomConst(_) => { - let unit_layout = CompiledTypeLayout::get(()); - CompiledTypeLayout { - ty: *input, - layout: unit_layout.layout, - body: unit_layout.body, - } - } CanonicalType::Bundle(bundle) => { let mut layout = TypeLayout::empty(); let fields = bundle @@ -1800,7 +1792,7 @@ impl Compiler { } .into() } - CanonicalType::Bundle(_) | CanonicalType::PhantomConst(_) => unreachable!(), + CanonicalType::Bundle(_) => unreachable!(), CanonicalType::AsyncReset(_) => TraceAsyncReset { location: self.make_trace_scalar_helper( instantiated_module, @@ -2017,13 +2009,6 @@ impl Compiler { | CanonicalType::Clock(_) => { self.make_trace_scalar(instantiated_module, target, name, source_location) } - CanonicalType::PhantomConst(_) => TraceBundle { - name, - fields: Interned::default(), - ty: Bundle::new(Interned::default()), - flow: target.flow(), - } - .into(), } } fn make_trace_decl( @@ -2484,9 +2469,6 @@ impl Compiler { Expr::field(Expr::::from_canonical(expr.arg()), &field.name) }), ), - CanonicalType::PhantomConst(_) => { - self.compile_cast_aggregate_to_bits(instantiated_module, []) - } } } fn compile_cast_bits_to( @@ -2536,10 +2518,6 @@ impl Compiler { CanonicalType::SyncReset(ty) => Expr::canonical(expr.arg().cast_to(ty)), CanonicalType::Reset(_) => unreachable!(), CanonicalType::Clock(ty) => Expr::canonical(expr.arg().cast_to(ty)), - CanonicalType::PhantomConst(ty) => { - let _ = self.compile_expr(instantiated_module, Expr::canonical(expr.arg())); - Expr::canonical(ty.to_expr()) - } }; let retval = self.compile_expr(instantiated_module, Expr::canonical(retval)); self.compiled_expr_to_value(retval, instantiated_module.leaf_module().source_location()) @@ -2589,7 +2567,6 @@ impl Compiler { CanonicalType::SyncReset(_) => false, CanonicalType::Reset(_) => false, CanonicalType::Clock(_) => false, - CanonicalType::PhantomConst(_) => unreachable!(), }; let dest_signed = match Expr::ty(expr) { CanonicalType::UInt(_) => false, @@ -2602,7 +2579,6 @@ impl Compiler { CanonicalType::SyncReset(_) => false, CanonicalType::Reset(_) => false, CanonicalType::Clock(_) => false, - CanonicalType::PhantomConst(_) => unreachable!(), }; self.simple_nary_big_expr(instantiated_module, Expr::ty(expr), [arg], |dest, [src]| { match (src_signed, dest_signed) { @@ -2658,9 +2634,6 @@ impl Compiler { }] }) .into(), - ExprEnum::PhantomConst(_) => self - .compile_aggregate_literal(instantiated_module, Expr::ty(expr), Interned::default()) - .into(), ExprEnum::BundleLiteral(literal) => self .compile_aggregate_literal( instantiated_module, @@ -3564,7 +3537,6 @@ impl Compiler { CanonicalType::SyncReset(_) => unreachable!(), CanonicalType::Reset(_) => unreachable!(), CanonicalType::Clock(_) => unreachable!(), - CanonicalType::PhantomConst(_) => unreachable!("PhantomConst mismatch"), } } let Some(target) = lhs.target() else { @@ -3929,7 +3901,6 @@ impl Compiler { CanonicalType::SyncReset(_) => false, CanonicalType::Reset(_) => false, CanonicalType::Clock(_) => false, - CanonicalType::PhantomConst(_) => unreachable!(), }; let width = data_layout.ty.bit_width(); if let Some(MemoryPortReadInsns { @@ -5938,7 +5909,6 @@ impl SimValue { CanonicalType::Clock(ty) => { Expr::canonical(Bool::bits_to_expr(Cow::Borrowed(bits)).cast_to(ty)) } - CanonicalType::PhantomConst(ty) => Expr::canonical(ty.to_expr()), } } } @@ -6342,8 +6312,7 @@ impl ToSimValue for bool { | CanonicalType::SInt(_) | CanonicalType::Array(_) | CanonicalType::Enum(_) - | CanonicalType::Bundle(_) - | CanonicalType::PhantomConst(_) => { + | CanonicalType::Bundle(_) => { panic!("can't create SimValue from bool: expected value of type: {ty:?}"); } CanonicalType::Bool(_) @@ -7008,7 +6977,6 @@ impl SimulationImpl { CanonicalType::SyncReset(_) => false, CanonicalType::Reset(_) => false, CanonicalType::Clock(_) => false, - CanonicalType::PhantomConst(_) => unreachable!(), }; match compiled_value.range.len() { TypeLen::A_SMALL_SLOT => read_write_small_scalar( diff --git a/crates/fayalite/src/ty.rs b/crates/fayalite/src/ty.rs index 2786782..69080c9 100644 --- a/crates/fayalite/src/ty.rs +++ b/crates/fayalite/src/ty.rs @@ -9,10 +9,8 @@ use crate::{ expr::Expr, int::{Bool, SInt, UInt}, intern::{Intern, Interned}, - phantom_const::PhantomConst, reset::{AsyncReset, Reset, SyncReset}, source_location::SourceLocation, - util::ConstUsize, }; use std::{fmt, hash::Hash, iter::FusedIterator, ops::Index}; @@ -37,7 +35,6 @@ pub enum CanonicalType { SyncReset(SyncReset), Reset(Reset), Clock(Clock), - PhantomConst(PhantomConst), } impl fmt::Debug for CanonicalType { @@ -53,7 +50,6 @@ impl fmt::Debug for CanonicalType { Self::SyncReset(v) => v.fmt(f), Self::Reset(v) => v.fmt(f), Self::Clock(v) => v.fmt(f), - Self::PhantomConst(v) => v.fmt(f), } } } @@ -71,7 +67,6 @@ impl CanonicalType { CanonicalType::SyncReset(v) => v.type_properties(), CanonicalType::Reset(v) => v.type_properties(), CanonicalType::Clock(v) => v.type_properties(), - CanonicalType::PhantomConst(v) => v.type_properties(), } } pub fn is_passive(self) -> bool { @@ -148,12 +143,6 @@ impl CanonicalType { }; lhs.can_connect(rhs) } - CanonicalType::PhantomConst(lhs) => { - let CanonicalType::PhantomConst(rhs) = rhs else { - return false; - }; - lhs.can_connect(rhs) - } } } } @@ -177,7 +166,7 @@ impl MatchVariantAndInactiveScope for MatchVariantWith } pub trait FillInDefaultedGenerics { - type Type; + type Type: Type; fn fill_in_defaulted_generics(self) -> Self::Type; } @@ -189,22 +178,6 @@ impl FillInDefaultedGenerics for T { } } -impl FillInDefaultedGenerics for usize { - type Type = usize; - - fn fill_in_defaulted_generics(self) -> Self::Type { - self - } -} - -impl FillInDefaultedGenerics for ConstUsize { - type Type = ConstUsize; - - fn fill_in_defaulted_generics(self) -> Self::Type { - self - } -} - mod sealed { pub trait TypeOrDefaultSealed {} pub trait BaseTypeSealed {} @@ -232,7 +205,6 @@ impl_base_type!(AsyncReset); impl_base_type!(SyncReset); impl_base_type!(Reset); impl_base_type!(Clock); -impl_base_type!(PhantomConst); impl sealed::BaseTypeSealed for CanonicalType {} @@ -327,7 +299,6 @@ impl Type for CanonicalType { CanonicalType::SyncReset(v) => v.mask_type().canonical(), CanonicalType::Reset(v) => v.mask_type().canonical(), CanonicalType::Clock(v) => v.mask_type().canonical(), - CanonicalType::PhantomConst(v) => v.mask_type().canonical(), } } fn canonical(&self) -> CanonicalType { diff --git a/crates/fayalite/visit_types.json b/crates/fayalite/visit_types.json index b284372..3eff1f5 100644 --- a/crates/fayalite/visit_types.json +++ b/crates/fayalite/visit_types.json @@ -49,8 +49,7 @@ "AsyncReset": "Visible", "SyncReset": "Visible", "Reset": "Visible", - "Clock": "Visible", - "PhantomConst": "Visible" + "Clock": "Visible" } }, "Bundle": { @@ -1263,12 +1262,6 @@ "ArrayElement": "Visible", "DynArrayElement": "Visible" } - }, - "PhantomConst": { - "data": { - "$kind": "Opaque" - }, - "generics": "" } } } \ No newline at end of file