The current implementation of the CallGraphNode
|
struct CallGraphNode<'a> { |
simply uses
summarize_fn::FnID to represent a function's callers and callees. It works fine, but more naturally, we should directly use
CallGraphNode instead of
FnID, which means something like
struct CallGraphNode<'a> {
fn_id: FnID,
crate_name: &'a str,
fn_name: &'a str,
callees: FxHashSet<Rc<RefCell<CallGraphNode<'a>>>>,
callers: FxHashSet<Rc<RefCell<CallGraphNode<'a>>>>,
}
However, there seems to be no idiomatic way to implement this. This CallGraphNode cannot derive Hash. Simply implementing Hash for it as follows does not work:
impl Hash for CallGraphNode<'_> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.fn_id.hash(state);
}
}
We still got unsatisfied traits bounds forLrc<RefCell<CallGraphNode<'_>>>: Hash and "the trait Hash is not implemented for RefCell<CallGraphNode<'a>>".
It seems that this can be "solved" by adding a wrapper to CallGraphNode, and implement Hash for this wrapper. However, this is not elegant as there would be unnecessary layers.
References:
HashMap keyed by Rc<RefCell<..>>
Hash based on address (not value) of Rc
Set of Rc where T isn't Hash or Ord?
Hash trait does not work for Rc<RefCell> in enum
The current implementation of the
CallGraphNodeSURust/compiler/rustc_mir_transform/src/sandbox/wpa.rs
Line 15 in 5e7efdb
simply uses
summarize_fn::FnIDto represent a function's callers and callees. It works fine, but more naturally, we should directly useCallGraphNodeinstead ofFnID, which means something likeHowever, there seems to be no idiomatic way to implement this. This
CallGraphNodecannot deriveHash. Simply implementingHashfor it as follows does not work:We still got unsatisfied traits bounds for
Lrc<RefCell<CallGraphNode<'_>>>: Hashand "the traitHashis not implemented forRefCell<CallGraphNode<'a>>".It seems that this can be "solved" by adding a wrapper to
CallGraphNode, and implementHashfor this wrapper. However, this is not elegant as there would be unnecessary layers.References:
HashMap keyed by Rc<RefCell<..>>
Hash based on address (not value) of Rc
Set of Rc where T isn't Hash or Ord?
Hash trait does not work for Rc<RefCell> in enum