In many node objects we introduced recently, we use the Node suffix to hold 
IR/AST nodes and no suffix for reference classes.

```c++
class RangeNode : public Object {
 public:
  Expr min;
  Expr extent;
};

class Range : public ObjectRef {
 public:
  // constructor
  Range(Expr begin, Expr end);
  // static factory.
  static Range make_by_min_extent(Expr min, extent);
};
```

In the above example:

- ```RangeNode``` is the container object.
- ```Range``` is the reference class.
- New objects are constructed via constructors in the reference class.
- We also define clear factory function ```make_by_min_extent`` in the 
reference class.

However, due to legacy reasons, we also have a few different styles in the 
codebase.
In particular, some IR container object does have a ```Node``` suffix or a 
reference class.
Because not every IR container object has a reference class,
the references are constructed via static make functions in the object 
container class
instead. The code block below shows an example:

```
class IntImm : public ExprNode {
 public:
  Expr make(DataType dtype, int64_t value);
};
```



## Proposal

This RFC proposes to adopt a single style throughout the codebase.
We propose to adopt the following convention as a strawman:

- Always use ```Node``` as the suffix for IR node container objects.
- Always introduce a reference class(which does not have suffix) to each 
container object.
- Because we have a reference class for each object class, we can use a 
constructor to directly
  construct a reference class
- In some instances where we need a clearly named factory function,
  we can put them as a static function of the corresponding reference class.

Notably, for object containers that are not part of IR, some end in Obj(e.g. 
ADTObj) and some end in Node(e.g. ModuleNode).
This RFC will not seek to consolidate these names, but it would also be great 
to hear from everyone's thoughts about this topic as well.

The main advantage of the proposed style is that the C++ code will be more 
consistent with the python version.
It is also more natural to construct reference via constructors.

Migrated from 
https://discuss.tvm.ai/t/unify-naming-convetion-for-ir-node-and-reference-classes

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-tvm/issues/4648

Reply via email to