Skip to content

Commit 16300ce

Browse files
authored
[FFI] Phase out ObjectPath in favor of AccessPath (#18192)
This PR phases out ObjectPath in favor of AccessPath
1 parent a40a140 commit 16300ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+579
-1534
lines changed

ffi/include/tvm/ffi/container/tuple.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,5 @@ inline constexpr bool type_contains_v<Tuple<T...>, Tuple<U...>> = (type_contains
269269
} // namespace details
270270

271271
} // namespace ffi
272-
273-
// Expose to the tvm namespace
274-
// Rationale: convinience and no ambiguity
275-
using ffi::Tuple;
276272
} // namespace tvm
277273
#endif // TVM_FFI_CONTAINER_TUPLE_H_

include/tvm/node/object_path.h

Lines changed: 0 additions & 287 deletions
This file was deleted.

include/tvm/node/repr_printer.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#ifndef TVM_NODE_REPR_PRINTER_H_
2424
#define TVM_NODE_REPR_PRINTER_H_
2525

26+
#include <tvm/ffi/reflection/access_path.h>
2627
#include <tvm/node/functor.h>
2728
#include <tvm/node/script_printer.h>
2829

@@ -87,6 +88,51 @@ inline std::ostream& operator<<(std::ostream& os, const Variant<V...>& n) { //
8788
return os;
8889
}
8990

91+
namespace reflection {
92+
93+
inline std::ostream& operator<<(std::ostream& os, const AccessStep& step) {
94+
namespace refl = ffi::reflection;
95+
switch (step->kind) {
96+
case refl::AccessKind::kAttr: {
97+
os << '.' << step->key.cast<String>();
98+
return os;
99+
}
100+
case refl::AccessKind::kArrayItem: {
101+
os << "[" << step->key.cast<int64_t>() << "]";
102+
return os;
103+
}
104+
case refl::AccessKind::kMapItem: {
105+
os << "[" << step->key << "]";
106+
return os;
107+
}
108+
case refl::AccessKind::kAttrMissing: {
109+
os << ".<missing attr " << step->key.cast<String>() << "`>";
110+
return os;
111+
}
112+
case refl::AccessKind::kArrayItemMissing: {
113+
os << "[<missing item at " << step->key.cast<int64_t>() << ">]";
114+
return os;
115+
}
116+
case refl::AccessKind::kMapItemMissing: {
117+
os << "[<missing item at " << step->key << ">]";
118+
return os;
119+
}
120+
default: {
121+
LOG(FATAL) << "Unknown access step kind: " << static_cast<int>(step->kind);
122+
}
123+
}
124+
return os;
125+
}
126+
127+
inline std::ostream& operator<<(std::ostream& os, const AccessPath& path) {
128+
Array<AccessStep> steps = path->ToSteps();
129+
os << "<root>";
130+
for (const auto& step : steps) {
131+
os << step;
132+
}
133+
return os;
134+
}
135+
} // namespace reflection
90136
} // namespace ffi
91137
} // namespace tvm
92138
#endif // TVM_NODE_REPR_PRINTER_H_

include/tvm/node/script_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
#include <tvm/ffi/any.h>
2727
#include <tvm/ffi/container/array.h>
2828
#include <tvm/ffi/container/map.h>
29+
#include <tvm/ffi/reflection/access_path.h>
2930
#include <tvm/ffi/reflection/registry.h>
3031
#include <tvm/ffi/string.h>
3132
#include <tvm/node/functor.h>
32-
#include <tvm/node/object_path.h>
3333
#include <tvm/runtime/data_type.h>
3434

3535
#include <iostream>
3636
#include <string>
3737

3838
namespace tvm {
3939

40-
class PrinterConfigNode : public Object {
40+
class PrinterConfigNode : public ffi::Object {
4141
public:
4242
/*! \brief A stack that tracks the names of the binding hierarchy */
4343
Array<String> binding_names = {};
@@ -113,9 +113,9 @@ class PrinterConfigNode : public Object {
113113
bool show_all_struct_info = true;
114114

115115
/* \brief Object path to be underlined */
116-
Array<ObjectPath> path_to_underline = Array<ObjectPath>();
116+
Array<ffi::reflection::AccessPath> path_to_underline;
117117
/*! \brief Object path to be annotated. */
118-
Map<ObjectPath, String> path_to_annotate = Map<ObjectPath, String>();
118+
Map<ffi::reflection::AccessPath, String> path_to_annotate;
119119
/*! \brief Object to be underlined. */
120120
Array<ObjectRef> obj_to_underline = Array<ObjectRef>();
121121
/*! \brief Object to be annotated. */

0 commit comments

Comments
 (0)