Skip to content

Commit 1c82be8

Browse files
authored
[FFI][REFACTOR] Phase out getattr based attribute handling (apache#18189)
[REFACTOR] Phase out getattr based attribute handling This PR phases out getattar based attribute handling as they are slower and introduces extra code path. This does mean that if an Object is not explicitly registered in python side, we will no longer be able to access the field by name. Likely this is also desirable as we would like to enable faster use that updates the python end and do not rely on these behavior.
1 parent 606b4d8 commit 1c82be8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ffi/extra/serialization.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,20 @@ class ObjectGraphDeserializer {
408408

409409
Any FromJSONGraph(const json::Value& value) { return ObjectGraphDeserializer::Deserialize(value); }
410410

411+
// string version of the api
412+
Any FromJSONGraphString(const String& value) { return FromJSONGraph(json::Parse(value)); }
413+
414+
String ToJSONGraphString(const Any& value, const Any& metadata) {
415+
return json::Stringify(ToJSONGraph(value, metadata));
416+
}
417+
411418
TVM_FFI_STATIC_INIT_BLOCK({
412419
namespace refl = tvm::ffi::reflection;
413-
refl::GlobalDef().def("ffi.ToJSONGraph", ToJSONGraph).def("ffi.FromJSONGraph", FromJSONGraph);
420+
refl::GlobalDef()
421+
.def("ffi.ToJSONGraph", ToJSONGraph)
422+
.def("ffi.ToJSONGraphString", ToJSONGraphString)
423+
.def("ffi.FromJSONGraph", FromJSONGraph)
424+
.def("ffi.FromJSONGraphString", FromJSONGraphString);
414425
refl::EnsureTypeAttrColumn("__data_to_json__");
415426
refl::EnsureTypeAttrColumn("__data_from_json__");
416427
});

0 commit comments

Comments
 (0)