How to covert a Call Node to Expr in the new unified Object protocol?

The problem is as following:

I have a Call node from which I want to make an instance of a Expr.

Previously before the Unified object protocol. I could achieve that by following:

Call call = Call::make(...); 
Expr e = Expr(call->GetNodePtr());

Previously, Expr had the following constructor:

explicit Expr(NodePtr<Node> ptr) : NodeRef(ptr) {}

I could pass the NodePtr<Node> by calling the GetNodePtr on the Call Node pointer.

In the new unified protocol,

the new constructor for the Expr is following:

  explicit Expr(ObjectPtr<Object> ptr) : NodeRef(ptr) {}

however, i can not find a way to get ObjectPtr<Object> from the call node pointer.

@tqchen
@xqdan
@zhiics

You don’t have to get node ptr out in order to assign to a parent reference type. Just do

Expr e = call; 

should work;

For downcast, use the Downcast function

1 Like

Thanks Tianqi.

I have another question related to new object protocol.

Let’s say, I have a Stmt and I want to reset its internal pointer.

eg. following:

Stmt s = Allocate::make(...);

Before unified object protocol to reset the data pointer, I could do something like following:

s.node_.reset()

But now, node_ is replaced by protected data_ and i can not call reset() on it directly.

Is there a way to achieve the same effect ?

The Stmt will get de-allocated automatically when it goes out of scope, so rarely you have to call the reset function. But if you really want to set it to null, you can do s = Stmt(), which assigns s to an empty node and it is equivalent to reset

1 Like

Hello Tianqi,

Thanks for the previous answers. I have one more question.

Let’ say I have a pointer Node* from which I want to make an instance of Operation which is derived from NodeRef . How do i go about that one in the new object protocol ? I don’t think i can use Downcast or GetRef in this case.

e.g. Previosly, I could simply do something like following:

Node* n;

Operation i = Operation(n->GetNodePtr()); 

Or

Do you think it is a good idea to add method similar to GetNodePtr() to Object e.g. GetObjectPtr ? Because many Nodes have constructors that take in ObjectPtr<Object>.