Skip to content

Commit 2500390

Browse files
committed
chore: Update rust-simplicity
1 parent c8e2565 commit 2500390

File tree

5 files changed

+33
-31
lines changed

5 files changed

+33
-31
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pest = "2.1.3"
2727
pest_derive = "2.7.1"
2828
serde = { version = "1.0.188", features = ["derive"], optional = true }
2929
serde_json = { version = "1.0.105", optional = true }
30-
simplicity-lang = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "ca0c0ebee295937ab021ad018acc44a5aaa12649" }
30+
simplicity-lang = { git = "https://github.com/uncomputable/rust-simplicity", branch = "2025-03-fix-value" }
3131
miniscript = "12.2.0"
3232
either = "1.12.0"
3333
itertools = "0.13.0"

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ mod tests {
392392
}
393393

394394
fn run(self) -> Result<(), simplicity::bit_machine::ExecutionError> {
395-
let mut mac = BitMachine::for_program(self.program.redeem());
395+
let mut mac = BitMachine::for_program(self.program.redeem())
396+
.expect("program should be within reasonable bounds");
396397
let env = dummy_env::dummy_with(self.lock_time, self.sequence, self.include_fee_output);
397398
mac.exec(self.program.redeem(), &env).map(|_| ())
398399
}

src/named.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use std::sync::Arc;
33
use simplicity::dag::{InternalSharing, PostOrderIterItem};
44
use simplicity::jet::{Elements, Jet};
55
use simplicity::node::{
6-
self, CommitData, Constructible, Converter, CoreConstructible, Inner, JetConstructible,
7-
NoDisconnect, NoWitness, Node, WitnessConstructible, WitnessData,
6+
self, CommitData, ConstructData as WitnessData, Constructible, Converter, CoreConstructible,
7+
Inner, JetConstructible, NoDisconnect, NoWitness, Node, WitnessConstructible,
88
};
99
use simplicity::types::arrow::Arrow;
1010
use simplicity::{types, CommitNode, FailEntropy};
11-
use simplicity::{Cmr, WitnessNode};
11+
use simplicity::{Cmr, ConstructNode as WitnessNode};
1212

1313
use crate::str::WitnessName;
1414
use crate::value::StructuralValue;
@@ -105,7 +105,7 @@ pub fn to_witness_node(node: &ConstructNode, values: WitnessValues) -> Arc<Witne
105105
inference_context: types::Context,
106106
}
107107

108-
impl<J: Jet> Converter<Construct<J>, node::Witness<J>> for Populator {
108+
impl<J: Jet> Converter<Construct<J>, node::Construct<J>> for Populator {
109109
type Error = ();
110110

111111
fn convert_witness(

src/value.rs

+24-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use either::Either;
55
use hex_conservative::DisplayHex;
66
use miniscript::iter::{Tree, TreeLike};
77
use simplicity::types::Final as SimType;
8-
use simplicity::{BitCollector, Value as SimValue};
8+
use simplicity::{BitCollector, Value as SimValue, ValueRef};
99

1010
use crate::array::{BTreeSlice, Combiner, Partition, Unfolder};
1111
use crate::error::{Error, RichError, WithSpan};
@@ -730,11 +730,11 @@ impl Value {
730730
pub fn reconstruct(value: &StructuralValue, ty: &ResolvedType) -> Option<Self> {
731731
let mut output = vec![];
732732
for data in value.destruct(ty).post_order_iter() {
733+
let size = data.node.n_children();
733734
let (value, ty) = match data.node {
734735
Destructor::Ok { value, ty } => (value, ty),
735736
Destructor::WrongType => return None,
736737
};
737-
let size = data.node.n_children();
738738
match ty.as_inner() {
739739
TypeInner::Boolean => {
740740
let bit = destruct::as_bit(value)?;
@@ -877,10 +877,10 @@ impl TreeLike for StructuralValue {
877877
fn as_node(&self) -> Tree<Self> {
878878
use simplicity::dag::{Dag, DagLike};
879879

880-
match (&self.0).as_dag_node() {
880+
match self.0.as_ref().as_dag_node() {
881881
Dag::Nullary => Tree::Nullary,
882-
Dag::Unary(l) => Tree::Unary(Self(l.shallow_clone())),
883-
Dag::Binary(l, r) => Tree::Binary(Self(l.shallow_clone()), Self(r.shallow_clone())),
882+
Dag::Unary(l) => Tree::Unary(Self(l.to_value())),
883+
Dag::Binary(l, r) => Tree::Binary(Self(l.to_value()), Self(r.to_value())),
884884
}
885885
}
886886
}
@@ -1059,7 +1059,7 @@ impl StructuralValue {
10591059

10601060
fn destruct<'a>(&'a self, ty: &'a ResolvedType) -> Destructor<'a> {
10611061
Destructor::Ok {
1062-
value: self.as_ref(),
1062+
value: self.0.as_ref(),
10631063
ty,
10641064
}
10651065
}
@@ -1091,30 +1091,30 @@ impl StructuralValue {
10911091
/// The leaf values (Boolean, unsigned integer, empty tuple, empty array) are not checked.
10921092
/// Extraction of actual Simfony values (Boolean, unsigned integer, ...)
10931093
/// from the leaf Simplicity values may fail, in which case the entire tree is, again, ill-typed.
1094-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
1094+
#[derive(Clone, Debug)]
10951095
enum Destructor<'a> {
10961096
Ok {
1097-
value: &'a SimValue,
1097+
value: ValueRef<'a>,
10981098
ty: &'a ResolvedType,
10991099
},
11001100
WrongType,
11011101
}
11021102

11031103
impl<'a> Destructor<'a> {
11041104
/// Create a destructor for the given Simplicity `value` and the given Simfony type.
1105-
pub const fn new(value: &'a SimValue, ty: &'a ResolvedType) -> Self {
1105+
pub const fn new(value: ValueRef<'a>, ty: &'a ResolvedType) -> Self {
11061106
Self::Ok { value, ty }
11071107
}
11081108

1109-
const fn new_pair((value, ty): (&'a SimValue, &'a ResolvedType)) -> Self {
1109+
const fn new_pair((value, ty): (ValueRef<'a>, &'a ResolvedType)) -> Self {
11101110
Self::Ok { value, ty }
11111111
}
11121112
}
11131113

11141114
impl TreeLike for Destructor<'_> {
11151115
fn as_node(&self) -> Tree<Self> {
11161116
let (value, ty) = match self {
1117-
Self::Ok { value, ty } => (value, ty),
1117+
Self::Ok { value, ty } => (value.clone(), ty),
11181118
Self::WrongType => return Tree::Nullary,
11191119
};
11201120
match ty.as_inner() {
@@ -1166,8 +1166,9 @@ impl TreeLike for Destructor<'_> {
11661166
/// Functions for destructing Simplicity values alongside Simfony types.
11671167
mod destruct {
11681168
use super::*;
1169+
use simplicity::ValueRef;
11691170

1170-
pub fn as_bit(value: &SimValue) -> Option<bool> {
1171+
pub fn as_bit(value: ValueRef) -> Option<bool> {
11711172
match value.as_left() {
11721173
Some(unit) if unit.is_unit() => Some(false),
11731174
_ => match value.as_right() {
@@ -1177,10 +1178,10 @@ mod destruct {
11771178
}
11781179
}
11791180

1180-
pub fn as_integer(value: &SimValue, ty: UIntType) -> Option<UIntValue> {
1181+
pub fn as_integer(value: ValueRef, ty: UIntType) -> Option<UIntValue> {
11811182
let bit_len = ty.bit_width().get();
11821183
let unfolder = Unfolder::new(value, bit_len);
1183-
let bit_values = unfolder.unfold(SimValue::as_product)?;
1184+
let bit_values = unfolder.unfold(|v| v.as_product())?;
11841185
let (bytes, written_bits) = bit_values.into_iter().filter_map(as_bit).collect_bits();
11851186
if bit_len != written_bits {
11861187
return None;
@@ -1196,31 +1197,31 @@ mod destruct {
11961197
}
11971198
}
11981199

1199-
pub fn as_tuple(value: &SimValue, size: usize) -> Option<Vec<&SimValue>> {
1200-
Unfolder::new(value, size).unfold(SimValue::as_product)
1200+
pub fn as_tuple(value: ValueRef, size: usize) -> Option<Vec<ValueRef>> {
1201+
Unfolder::new(value, size).unfold(|v| v.as_product())
12011202
}
12021203

1203-
pub fn as_array(value: &SimValue, size: usize) -> Option<Vec<&SimValue>> {
1204-
Unfolder::new(value, size).unfold(SimValue::as_product)
1204+
pub fn as_array(value: ValueRef, size: usize) -> Option<Vec<ValueRef>> {
1205+
Unfolder::new(value, size).unfold(|v| v.as_product())
12051206
}
12061207

1207-
pub fn as_list<'a>(value: &'a SimValue, bound: NonZeroPow2Usize) -> Option<Vec<&'a SimValue>> {
1208-
let as_block = |value: &'a SimValue, size: usize| match as_option(value) {
1208+
pub fn as_list<'a>(value: ValueRef<'a>, bound: NonZeroPow2Usize) -> Option<Vec<ValueRef<'a>>> {
1209+
let as_block = |value: ValueRef<'a>, size: usize| match as_option(value) {
12091210
Some(Some(folded)) => as_array(folded, size),
12101211
Some(None) => Some(vec![]),
12111212
None => None,
12121213
};
1213-
Combiner::new(value, bound).unfold(as_block, SimValue::as_product)
1214+
Combiner::new(value, bound).unfold(as_block, |v| v.as_product())
12141215
}
12151216

1216-
pub fn as_either(value: &SimValue) -> Option<Either<&SimValue, &SimValue>> {
1217+
pub fn as_either(value: ValueRef) -> Option<Either<ValueRef, ValueRef>> {
12171218
match value.as_left() {
12181219
Some(inner) => Some(Either::Left(inner)),
12191220
None => value.as_right().map(Either::Right),
12201221
}
12211222
}
12221223

1223-
pub fn as_option(value: &SimValue) -> Option<Option<&SimValue>> {
1224+
pub fn as_option(value: ValueRef) -> Option<Option<ValueRef>> {
12241225
match value.as_left() {
12251226
Some(inner) if inner.is_unit() => Some(None),
12261227
_ => value.as_right().map(Some),

0 commit comments

Comments
 (0)