Skip to content

Commit

Permalink
chore: Update rust-simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
uncomputable committed Aug 31, 2024
1 parent da8eba9 commit 9374196
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
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
17 changes: 7 additions & 10 deletions src/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +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(StructuralValue::from)
.map(Arc::<simplicity::Value>::from);
.map(simplicity::Value::from);
Ok(maybe_value)
}

Expand All @@ -137,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 @@ -228,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 @@ -282,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 @@ -586,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
33 changes: 18 additions & 15 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::Arc;

use either::Either;
use miniscript::iter::{Tree, TreeLike};
use simplicity::types::Final as SimType;
use simplicity::Value as SimValue;

use crate::array::{BTreeSlice, Partition};
Expand Down Expand Up @@ -708,26 +709,28 @@ impl Value {
/// Structure of a Simfony value.
/// 1:1 isomorphism to Simplicity.
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct StructuralValue(Arc<SimValue>);
pub struct StructuralValue(SimValue);

impl AsRef<SimValue> for StructuralValue {
fn as_ref(&self) -> &SimValue {
&self.0
}
}

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

impl TreeLike for StructuralValue {
fn as_node(&self) -> Tree<Self> {
match self.as_ref() {
SimValue::Unit => Tree::Nullary,
SimValue::Left(l) | SimValue::Right(l) => Tree::Unary(Self(l.clone())),
SimValue::Product(l, r) => Tree::Binary(Self(l.clone()), Self(r.clone())),
use simplicity::dag::{Dag, DagLike};

match (&self.0).as_dag_node() {
Dag::Nullary => Tree::Nullary,
Dag::Unary(l) => Tree::Unary(Self(l.shallow_clone())),
Dag::Binary(l, r) => Tree::Binary(Self(l.shallow_clone()), Self(r.shallow_clone())),
}
}
}
Expand Down Expand Up @@ -757,20 +760,20 @@ impl ValueConstructible for StructuralValue {
Self(SimValue::product(left.0, right.0))
}

fn left(left: Self, _right: Self::Type) -> Self {
Self(SimValue::left(left.0))
fn left(left: Self, right: Self::Type) -> Self {
Self(SimValue::left(left.0, right.into()))
}

fn right(_left: Self::Type, right: Self) -> Self {
Self(SimValue::right(right.0))
fn right(left: Self::Type, right: Self) -> Self {
Self(SimValue::right(left.into(), right.0))
}

fn none(_inner: Self::Type) -> Self {
Self(SimValue::left(SimValue::unit()))
fn none(inner: Self::Type) -> Self {
Self(SimValue::none(inner.into()))
}

fn some(inner: Self) -> Self {
Self(SimValue::right(inner.0))
Self(SimValue::some(inner.0))
}

fn tuple<I: IntoIterator<Item = Self>>(elements: I) -> Self {
Expand Down Expand Up @@ -819,8 +822,8 @@ impl ValueConstructible for StructuralValue {
impl From<bool> for StructuralValue {
fn from(value: bool) -> Self {
match value {
false => Self(SimValue::left(SimValue::unit())),
true => Self(SimValue::right(SimValue::unit())),
false => Self(SimValue::left(SimValue::unit(), SimType::unit())),
true => Self(SimValue::right(SimType::unit(), SimValue::unit())),
}
}
}
Expand Down

0 comments on commit 9374196

Please sign in to comment.