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

Fix AMR #214

Merged
merged 4 commits into from
Apr 23, 2024
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
1 change: 1 addition & 0 deletions simplicity-sys/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::mem;
/// [16 bytes is the greatest alignment of any architecture Rust currently supports](https://github.com/rust-lang/rust/blob/61223975d46f794466efa832bc7562b9707ecc46/library/std/src/sys/pal/common/alloc.rs).
#[repr(align(16))]
#[derive(Default, Copy, Clone)]
#[allow(dead_code)]
pub struct AlignedType([u8; 16]);

/// Minimal alignment which is valid for all C types.
Expand Down
7 changes: 2 additions & 5 deletions src/human_encoding/parse/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! Parsing

use std::mem;
use std::str::FromStr;
use std::sync::Arc;

use crate::human_encoding::{Error, ErrorSet, Position, WitnessOrHole};
Expand Down Expand Up @@ -61,7 +60,7 @@ pub enum ExprInner<J> {
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum AstCmr<J> {
Expr(Arc<Expression<J>>),
Literal(Cmr),
Literal,
}

/// A type, as represented in the AST
Expand Down Expand Up @@ -395,9 +394,7 @@ impl<J: Jet> Ast<J> {
assert_eq!(lexemes.len(), 1);
assert_eq!(lexemes[0].raw.len(), 65);

Ast::Cmr(AstCmr::Literal(
Cmr::from_str(&lexemes[0].raw[1..]).unwrap(),
))
Ast::Cmr(AstCmr::Literal)
}

fn expect_arrow(&mut self) -> (Option<Type>, Option<Type>) {
Expand Down
21 changes: 8 additions & 13 deletions src/human_encoding/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::dag::{Dag, DagLike, InternalSharing};
use crate::jet::Jet;
use crate::node;
use crate::types::Type;
use crate::Cmr;
use std::collections::HashMap;
use std::mem;
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -139,7 +138,7 @@ struct ResolvedExpression<J: Jet> {

enum ResolvedCmr<J: Jet> {
Expr(Arc<ResolvedExpression<J>>),
Literal(Cmr),
Literal,
}

enum ResolvedInner<J: Jet> {
Expand Down Expand Up @@ -312,7 +311,7 @@ pub fn parse<J: Jet + 'static>(
right.in_degree.fetch_add(1, Ordering::SeqCst);
ResolvedCmr::Expr(right)
}
ast::AstCmr::Literal(cmr) => ResolvedCmr::Literal(*cmr),
ast::AstCmr::Literal => ResolvedCmr::Literal,
};
ResolvedInner::AssertL(left, right)
}
Expand All @@ -323,7 +322,7 @@ pub fn parse<J: Jet + 'static>(
left.in_degree.fetch_add(1, Ordering::SeqCst);
ResolvedCmr::Expr(left)
}
ast::AstCmr::Literal(cmr) => ResolvedCmr::Literal(*cmr),
ast::AstCmr::Literal => ResolvedCmr::Literal,
};

let right = inline_stack.pop().unwrap();
Expand Down Expand Up @@ -413,8 +412,8 @@ pub fn parse<J: Jet + 'static>(
| ResolvedInner::AssertR(ResolvedCmr::Expr(ref left), ref right) => {
Dag::Binary(left, right)
}
ResolvedInner::AssertL(ref child, ResolvedCmr::Literal(..))
| ResolvedInner::AssertR(ResolvedCmr::Literal(..), ref child) => Dag::Unary(child),
ResolvedInner::AssertL(ref child, ResolvedCmr::Literal)
| ResolvedInner::AssertR(ResolvedCmr::Literal, ref child) => Dag::Unary(child),
ResolvedInner::Inline(ref inner) => inner.as_dag().map(|node| node),
}
}
Expand All @@ -431,10 +430,10 @@ pub fn parse<J: Jet + 'static>(
for data in expr.as_ref().post_order_iter::<InternalSharing>() {
let left = data
.left_index
.and_then(|idx| converted[idx].as_ref().map(Arc::clone));
.and_then(|idx| Option::<Arc<_>>::clone(&converted[idx]));
let right = data
.right_index
.and_then(|idx| converted[idx].as_ref().map(Arc::clone));
.and_then(|idx| Option::<Arc<_>>::clone(&converted[idx]));

let maybe_inner = match data.node.inner {
ResolvedInner::Missing { ref name, .. } => {
Expand Down Expand Up @@ -482,11 +481,7 @@ pub fn parse<J: Jet + 'static>(
}
};

let name = data
.node
.name
.as_ref()
.map(Arc::clone)
let name = Option::<Arc<str>>::clone(&data.node.name)
.unwrap_or_else(|| Arc::from(namer.assign_name(inner.as_ref()).as_str()));

let node = NamedConstructNode::new(
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// we use `bool` to represent bits and frequentely assert_eq against them
clippy::bool_assert_comparison,
// we use () as the environment for Core (FIXME we should probabl use a newtype)
clippy::let_unit_value
clippy::let_unit_value,
// We write map(Arc::clone) to signify that a cheap Arc is being cloned
clippy::map_clone
)]

#[cfg(feature = "serde")]
Expand Down
2 changes: 1 addition & 1 deletion src/merkle/amr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Amr {

/// Produce a CMR for a take combinator
pub fn take(ty: &FinalArrow, child: Amr) -> Self {
let (a, b) = ty.source.as_sum().unwrap();
let (a, b) = ty.source.as_product().unwrap();
let c = &ty.target;
Self::TAKE_IV
.update(a.tmr().into(), b.tmr().into())
Expand Down
6 changes: 3 additions & 3 deletions src/node/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<J: Jet> WitnessNode<J> {
.as_ref()
.map(Arc::clone)
.map_disconnect(Option::<Arc<_>>::clone)
.map_witness(|wit| wit.as_ref().map(Arc::clone)),
.map_witness(Option::<Arc<Value>>::clone),
})
}

Expand All @@ -83,7 +83,7 @@ impl<J: Jet> WitnessNode<J> {
_: &PostOrderIterItem<&WitnessNode<J>>,
wit: &Option<Arc<Value>>,
) -> Result<Option<Arc<Value>>, Self::Error> {
Ok(wit.as_ref().map(Arc::clone))
Ok(Option::<Arc<Value>>::clone(wit))
}

fn prune_case(
Expand Down Expand Up @@ -129,7 +129,7 @@ impl<J: Jet> WitnessNode<J> {
) -> Result<WitnessData<J>, Self::Error> {
let converted_inner = inner
.map(|node| node.cached_data())
.map_witness(|wit| wit.as_ref().map(Arc::clone));
.map_witness(Option::<Arc<Value>>::clone);
// This next line does the actual retyping.
let mut retyped = WitnessData::from_inner(converted_inner)?;
// Sometimes we set the prune bit on nodes without setting that
Expand Down
Loading