Skip to content

Commit bedb6d7

Browse files
committed
policy: unwrap a few impossible error cases in compile_tr
We have a few error returns that are impossible to hit: * A sanity check on a tapleaf that just came out of the compiler (if this is hit it is a compiler bug and we want to know about it). * An error return from with_huffman_tree which can only happen if it's given an empty input (impossible) * An error if the final compilation (all tapleaves assembled into a tree) can't fit into a Descriptor::tr; but again, this is a compiler bug if we hit it. (Actually, I think that by manually constructing a policy that exceeds the maximum recursion depth you can trigger this error path, but the compiler output is not the place to flag this manual violation of invariants). The next commit will clean up the error types. These changes are in their own commit because they are potentially controversial.
1 parent a3338fb commit bedb6d7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/policy/concrete.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,17 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
242242
continue;
243243
}
244244
let compilation = compiler::best_compilation::<Pk, Tap>(pol)?;
245-
compilation.sanity_check()?;
245+
compilation
246+
.sanity_check()
247+
.expect("compiler produces sane output");
246248
leaf_compilations.push((OrdF64(prob), compilation));
247249
}
248-
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations)?;
250+
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
249251
Some(tap_tree)
250252
}
251253
},
252-
)?;
254+
)
255+
.expect("compiler produces sane output");
253256
Ok(tree)
254257
}
255258
}

0 commit comments

Comments
 (0)