Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update simplicity #82

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pest = "2.1.3"
pest_derive = "2.7.1"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.105"
simplicity-lang = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "f6e7ecfc43852064780bba6f019b6532d572f166" }
simplicity-lang = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "794918783291465a109bdaf2ef694f86467c477e" }
miniscript = "11.0.0"
either = "1.12.0"
itertools = "0.13.0"
Expand Down
20 changes: 8 additions & 12 deletions src/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use simplicity::{types, CommitNode, FailEntropy};
use simplicity::{Cmr, WitnessNode};

use crate::str::WitnessName;
use crate::value::{StructuralValue, TypedValue};
use crate::value::StructuralValue;
use crate::witness::WitnessValues;

/// Marker for [`ConstructNode`].
Expand Down Expand Up @@ -112,13 +112,12 @@ pub fn to_witness_node(node: &ConstructNode, values: &WitnessValues) -> Arc<Witn
&mut self,
_: &PostOrderIterItem<&Node<Construct<J>>>,
witness: &WitnessName,
) -> Result<Option<Arc<simplicity::Value>>, Self::Error> {
) -> Result<Option<simplicity::Value>, Self::Error> {
let maybe_value = self
.values
.get(witness)
.map(TypedValue::value)
.map(StructuralValue::from)
.map(Arc::<simplicity::Value>::from);
.map(simplicity::Value::from);
Ok(maybe_value)
}

Expand All @@ -138,13 +137,13 @@ pub fn to_witness_node(node: &ConstructNode, values: &WitnessValues) -> Arc<Witn
&Arc<WitnessNode<J>>,
J,
&Option<Arc<WitnessNode<J>>>,
&Option<Arc<simplicity::Value>>,
&Option<simplicity::Value>,
>,
) -> Result<WitnessData<J>, Self::Error> {
let inner = inner
.map(Arc::as_ref)
.map(WitnessNode::<J>::cached_data)
.map_witness(Option::<Arc<simplicity::Value>>::clone);
.map_witness(Option::<simplicity::Value>::clone);
Ok(WitnessData::from_inner(&self.inference_context, inner).unwrap())
}
}
Expand Down Expand Up @@ -229,7 +228,7 @@ impl<J> CoreConstructible for ConstructData<J> {
Arrow::fail(inference_context, entropy).into()
}

fn const_word(inference_context: &types::Context, word: Arc<simplicity::Value>) -> Self {
fn const_word(inference_context: &types::Context, word: simplicity::Value) -> Self {
Arrow::const_word(inference_context, word).into()
}

Expand Down Expand Up @@ -283,7 +282,7 @@ pub trait CoreExt: CoreConstructible + Sized {
/// -------------------
/// comp unit (const v) : A → B
/// ```
fn unit_const_value(inference_context: &types::Context, value: Arc<simplicity::Value>) -> Self {
fn unit_const_value(inference_context: &types::Context, value: simplicity::Value) -> Self {
Self::comp(
&Self::unit(inference_context),
&Self::const_word(inference_context, value),
Expand Down Expand Up @@ -587,10 +586,7 @@ impl<P: CoreExt> PairBuilder<P> {
/// ---------------------------
/// comp unit (const v) : A → B
/// ```
pub fn unit_const_value(
inference_context: &types::Context,
value: Arc<simplicity::Value>,
) -> Self {
pub fn unit_const_value(inference_context: &types::Context, value: simplicity::Value) -> Self {
Self(P::unit_const_value(inference_context, value))
}
}
Expand Down
45 changes: 16 additions & 29 deletions src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,26 @@ impl fmt::Display for Pattern {
match data.node {
Pattern::Identifier(i) => write!(f, "{i}")?,
Pattern::Ignore => write!(f, "_")?,
Pattern::Tuple(elements) => match data.n_children_yielded {
0 => {
f.write_str("(")?;
if 0 == elements.len() {
f.write_str(")")?;
}
}
n if n == elements.len() => {
if n == 1 {
f.write_str(",")?;
}
f.write_str(")")?;
Pattern::Tuple(tuple) => {
if data.n_children_yielded == 0 {
write!(f, "(")?;
} else if !data.is_complete || tuple.len() == 1 {
write!(f, ", ")?;
}
n => {
debug_assert!(n < elements.len());
f.write_str(", ")?
if data.is_complete {
write!(f, ")")?;
}
},
Pattern::Array(elements) => match data.n_children_yielded {
0 => {
f.write_str("[")?;
if 0 == elements.len() {
f.write_str("]")?;
}
}
n if n == elements.len() => {
f.write_str("]")?;
}
Pattern::Array(..) => {
if data.n_children_yielded == 0 {
write!(f, "[")?;
} else if !data.is_complete {
write!(f, ", ")?;
}
n => {
debug_assert!(n < elements.len());
f.write_str(", ")?;
if data.is_complete {
write!(f, "]")?;
}
},
}
}
}

Expand Down
52 changes: 47 additions & 5 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<A> TypeInner<A> {
}

/// Unsigned integer type.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum UIntType {
/// 1-bit unsigned integer
Expand Down Expand Up @@ -164,6 +164,12 @@ impl UIntType {
}
}

impl fmt::Debug for UIntType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}

impl fmt::Display for UIntType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -277,7 +283,7 @@ pub trait TypeDeconstructible: Sized {
}

/// Simfony type without type aliases.
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
#[derive(PartialEq, Eq, Hash, Clone)]
pub struct ResolvedType(TypeInner<Arc<Self>>);

impl ResolvedType {
Expand Down Expand Up @@ -374,6 +380,12 @@ impl<'a> TreeLike for &'a ResolvedType {
}
}

impl fmt::Debug for ResolvedType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}

impl fmt::Display for ResolvedType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for data in self.verbose_pre_order_iter() {
Expand All @@ -390,7 +402,7 @@ impl From<UIntType> for ResolvedType {
}

/// Simfony type with type aliases.
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
#[derive(PartialEq, Eq, Hash, Clone)]
pub struct AliasedType(AliasedInner);

/// Type alias or primitive.
Expand All @@ -407,7 +419,7 @@ enum AliasedInner {
}

/// Type alias with predefined definition.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum BuiltinAlias {
Ctx8,
Expand Down Expand Up @@ -621,6 +633,12 @@ impl<'a> TreeLike for &'a AliasedType {
}
}

impl fmt::Debug for AliasedType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}

impl fmt::Display for AliasedType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for data in self.verbose_pre_order_iter() {
Expand Down Expand Up @@ -739,6 +757,12 @@ impl BuiltinAlias {
}
}

impl fmt::Debug for BuiltinAlias {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}

impl fmt::Display for BuiltinAlias {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -806,7 +830,7 @@ impl FromStr for BuiltinAlias {

/// Internal structure of a Simfony type.
/// 1:1 isomorphism to Simplicity.
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct StructuralType(Arc<Final>);

impl AsRef<Final> for StructuralType {
Expand All @@ -815,6 +839,12 @@ impl AsRef<Final> for StructuralType {
}
}

impl From<StructuralType> for Arc<Final> {
fn from(value: StructuralType) -> Self {
value.0
}
}

impl TreeLike for StructuralType {
fn as_node(&self) -> Tree<Self> {
match self.0.bound() {
Expand All @@ -826,6 +856,18 @@ impl TreeLike for StructuralType {
}
}

impl fmt::Debug for StructuralType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &self.0)
}
}

impl fmt::Display for StructuralType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &self.0)
}
}

impl From<UIntType> for StructuralType {
fn from(value: UIntType) -> Self {
let inner = match value {
Expand Down
Loading
Loading