@@ -73,25 +73,28 @@ impl<'a> Debug for PcodeOpRef<'a> {
7373
7474/// A store of p-code operations.
7575///
76- /// Implementations return `Option<PcodeOpRef<'a >>`. Callers that only need to
76+ /// Implementations return `Option<PcodeOpRef<'op >>`. Callers that only need to
7777/// observe/borrow the operation should use `op_ref.as_ref()` to get a `&PcodeOperation`.
7878/// If an owned operation is required, clone via `.as_ref().clone()`.
79- pub trait PcodeStore {
80- fn get_pcode_op_at < ' a , T : Borrow < ConcretePcodeAddress > > (
81- & ' a self ,
79+ ///
80+ /// The trait is lifetime-parameterized so stores can tie the returned operation
81+ /// reference lifetime to the borrow of the store, avoiding unnecessary cloning.
82+ pub trait PcodeStore < ' op > {
83+ fn get_pcode_op_at < T : Borrow < ConcretePcodeAddress > > (
84+ & ' op self ,
8285 addr : T ,
83- ) -> Option < PcodeOpRef < ' a > > ;
86+ ) -> Option < PcodeOpRef < ' op > > ;
8487}
8588
8689pub trait EntryPoint {
8790 fn get_entry ( & self ) -> ConcretePcodeAddress ;
8891}
8992
90- impl < ' a > PcodeStore for LoadedSleighContext < ' a > {
91- fn get_pcode_op_at < ' b , T : Borrow < ConcretePcodeAddress > > (
92- & ' b self ,
93+ impl < ' a > PcodeStore < ' a > for LoadedSleighContext < ' a > {
94+ fn get_pcode_op_at < T : Borrow < ConcretePcodeAddress > > (
95+ & ' a self ,
9396 addr : T ,
94- ) -> Option < PcodeOpRef < ' b > > {
97+ ) -> Option < PcodeOpRef < ' a > > {
9598 let addr = addr. borrow ( ) ;
9699 // `instruction_at` produces an owned `Instruction` per call. Its `ops`
97100 // are owned inside that `Instruction`, so we cannot return references
@@ -105,11 +108,11 @@ impl<'a> PcodeStore for LoadedSleighContext<'a> {
105108 }
106109}
107110
108- impl < T : PcodeStore + ?Sized > PcodeStore for & T {
109- fn get_pcode_op_at < ' a , B : Borrow < ConcretePcodeAddress > > (
110- & ' a self ,
111+ impl < ' op , T : PcodeStore < ' op > + ?Sized > PcodeStore < ' op > for & T {
112+ fn get_pcode_op_at < B : Borrow < ConcretePcodeAddress > > (
113+ & ' op self ,
111114 addr : B ,
112- ) -> Option < PcodeOpRef < ' a > > {
115+ ) -> Option < PcodeOpRef < ' op > > {
113116 ( * self ) . get_pcode_op_at ( addr)
114117 }
115118}
0 commit comments