Skip to content

Commit 7f14121

Browse files
committed
Merge #260: clippy fixes: make some lifetimes anonymous and add send/sync to types::BoundRef
5696096 types: implement `Send`/`Sync` for `BoundRef` (Andrew Poelstra) 9385b6d clippy: make lifetimes anonymous where possible (Andrew Poelstra) Pull request description: `types::BoundRef` is an internal type which includes a sort of weak pointer to an `Arc` containing a slab allocation used by the type inference engine. It is `Send` and `Sync` by construction but the compiler does not recognize this because it includes a raw pointer. Add explicit implementations with a safety comment explaining why it is okay. Fixes #258 ACKs for top commit: uncomputable: ACK 5696096 Tree-SHA512: 4498543e98c13950444029803f7a7f016861323092bc814d418b7bda67c0ddd131556d931caff47cded3f08a236673c987ebb74da9e879f5c13969001ee5116a
2 parents fbe88d6 + 5696096 commit 7f14121

File tree

12 files changed

+29
-16
lines changed

12 files changed

+29
-16
lines changed

src/bit_encoding/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ enum DecodeNode<J: Jet> {
133133
Word(Word),
134134
}
135135

136-
impl<'d, J: Jet> DagLike for (usize, &'d [DecodeNode<J>]) {
136+
impl<J: Jet> DagLike for (usize, &'_ [DecodeNode<J>]) {
137137
type Node = DecodeNode<J>;
138138

139139
fn data(&self) -> &DecodeNode<J> {

src/bit_encoding/encode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<'n, N: node::Marker> Disconnectable<EncodeNode<'n, N>> for EncodeNode<'n, N
3535
}
3636
}
3737

38-
impl<'n, N: node::Marker> DagLike for EncodeNode<'n, N> {
38+
impl<N: node::Marker> DagLike for EncodeNode<'_, N> {
3939
type Node = Self;
4040
fn data(&self) -> &Self {
4141
self
@@ -125,7 +125,7 @@ impl<N: node::Marker> Default for EncodeSharing<N> {
125125
}
126126
}
127127

128-
impl<'n, N: node::Marker> SharingTracker<EncodeNode<'n, N>> for EncodeSharing<N> {
128+
impl<N: node::Marker> SharingTracker<EncodeNode<'_, N>> for EncodeSharing<N> {
129129
fn record(&mut self, d: &EncodeNode<N>, index: usize) -> Option<usize> {
130130
let id = match d {
131131
EncodeNode::Node(n) => EncodeId::Node(n.sharing_id()?),

src/bit_machine/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl BitMachine {
221221
}
222222

223223
// Not used, but useful for debugging, so keep it around
224-
impl<'a, J: Jet> fmt::Debug for CallStack<'a, J> {
224+
impl<J: Jet> fmt::Debug for CallStack<'_, J> {
225225
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
226226
match self {
227227
CallStack::Goto(ins) => write!(f, "goto {}", ins.inner()),

src/dag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<D: DagLike> DagLike for SwapChildren<D> {
369369
}
370370
}
371371

372-
impl<'a, N: node::Marker> DagLike for &'a Node<N> {
372+
impl<N: node::Marker> DagLike for &'_ Node<N> {
373373
type Node = Node<N>;
374374

375375
fn data(&self) -> &Node<N> {

src/human_encoding/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl WitnessOrHole {
7575
}
7676
}
7777

78-
impl<'a> From<&'a NoWitness> for WitnessOrHole {
78+
impl From<&'_ NoWitness> for WitnessOrHole {
7979
fn from(_: &NoWitness) -> Self {
8080
WitnessOrHole::Witness
8181
}

src/human_encoding/named_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<J: Jet> NamedCommitNode<J> {
120120
phantom: PhantomData<J>,
121121
}
122122

123-
impl<'a, J: Jet> Converter<Named<Commit<J>>, Witness<J>> for Populator<'a, J> {
123+
impl<J: Jet> Converter<Named<Commit<J>>, Witness<J>> for Populator<'_, J> {
124124
type Error = ();
125125

126126
fn convert_witness(

src/human_encoding/parse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct ResolvedExpression<J: Jet> {
136136
in_degree: AtomicUsize,
137137
}
138138

139-
impl<'a, J: Jet> DagLike for &'a ResolvedExpression<J> {
139+
impl<J: Jet> DagLike for &'_ ResolvedExpression<J> {
140140
type Node = ResolvedExpression<J>;
141141
fn data(&self) -> &ResolvedExpression<J> {
142142
self

src/node/redeem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ impl<J: Jet> RedeemNode<J> {
288288
phantom: PhantomData<J>,
289289
}
290290

291-
impl<'bits, J: Jet, I: Iterator<Item = u8>> Converter<Construct<J>, Redeem<J>>
292-
for DecodeFinalizer<'bits, J, I>
291+
impl<J: Jet, I: Iterator<Item = u8>> Converter<Construct<J>, Redeem<J>>
292+
for DecodeFinalizer<'_, J, I>
293293
{
294294
type Error = Error;
295295
fn convert_witness(

src/policy/satisfy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ mod tests {
250250
pub index: usize,
251251
}
252252

253-
impl<'a, Pk: ToXOnlyPubkey> Satisfier<Pk> for PolicySatisfier<'a, Pk> {
253+
impl<Pk: ToXOnlyPubkey> Satisfier<Pk> for PolicySatisfier<'_, Pk> {
254254
fn lookup_tap_leaf_script_sig(
255255
&self,
256256
pk: &Pk,

src/types/context.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ pub struct BoundRef {
245245
index: usize,
246246
}
247247

248+
// SAFETY: The pointer inside `BoundRef` is always (eventually) constructed from Arc::as_ptr
249+
// from the slab of a type-inference context.
250+
//
251+
// Arc will prevent the pointer from ever changing, except to be deallocated when the last
252+
// Arc goes away. But this occurs only when the context itself goes away, which in turn
253+
// happens only when every type bound referring to the context goes away.
254+
//
255+
// If this were untrue, our use of `BoundRef` would lead to dereferences of a dangling
256+
// pointer, and `Send`/`Sync` would be the least of our concerns!
257+
unsafe impl Send for BoundRef {}
258+
// SAFETY: see comment on `Send`
259+
unsafe impl Sync for BoundRef {}
260+
248261
impl BoundRef {
249262
pub fn assert_matches_context(&self, ctx: &Context) {
250263
assert_eq!(
@@ -282,7 +295,7 @@ impl super::PointerLike for BoundRef {
282295
}
283296
}
284297

285-
impl<'ctx> DagLike for (&'ctx Context, BoundRef) {
298+
impl DagLike for (&'_ Context, BoundRef) {
286299
type Node = BoundRef;
287300
fn data(&self) -> &BoundRef {
288301
&self.1
@@ -318,7 +331,7 @@ struct LockedContext<'ctx> {
318331
slab: MutexGuard<'ctx, Vec<Bound>>,
319332
}
320333

321-
impl<'ctx> LockedContext<'ctx> {
334+
impl LockedContext<'_> {
322335
fn alloc_bound(&mut self, bound: Bound) -> BoundRef {
323336
self.slab.push(bound);
324337
let index = self.slab.len() - 1;

0 commit comments

Comments
 (0)