When to use reference vs pointer

Hi, Here is an example

Expr Rewrite_(const CallNode* call_node, const Expr& post) final {
    const Call& ref_call = GetRef<Call>(call_node);
...
...
  const auto* post_node = post.as<CallNode>();

....

This is a fairly standard convention in TVM C++ codebase. I am really confused about when we should pass Objects by pointer and when by const reference. It seems you can easily convert between the two, then why not always just pass Object pointer or reference/const reference?

We should pass by the ObjectRef in most part of the codebase. The only exception for now is the Functor dispatching classes, where the first argument is the Object node class itself, and can be viewed as a Weak reference to the original node.

There are some interest in moving the functor dispatching argument to be ObjectRef as well, which might be a good idea, but would need another round of refactor(perhaps after this round)

Thanks for the explaination.

I saw some places passing ObjectRef by value, and some pass the ObjectRef by reference. ObjectRef if some kind of a shared pointer, so passing it “by value” hold reference semantics. What is the “correct” way to pass it?