-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Rustify PackedFunc & Friends #2969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
cc @ehsanmok for review Aren't PRs that have more red than green the best? |
801da1f to
6698f72
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job! I really like the enum POD repr. Here're some small comments:
| pub value: TVMValue, | ||
| pub type_code: i64, | ||
| /// Constructs a derivative of a TVMPodValue. | ||
| macro_rules! TVMPODValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat :)
rust/frontend/src/function.rs
Outdated
| .arg_buf | ||
| .iter() | ||
| .map(|tvm_arg| (tvm_arg.value, tvm_arg.type_code as ffi::TVMTypeCode)) | ||
| .map(|arg| arg.clone().into_tvm_value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be without clone after into_iter or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that would require
- type PackedFunc = Fn(&[TVMArgValue]) -> TVMRetValue;
+ type PackedFunc = Fn(Vec<TVMArgValue>) -> TVMRetValue;and the TVM module is surely not going to know how to Drop a Vec (nor can the frontend or runtime Drop a C++ std::vector).
I think that a better solution might be .as_tvm_value(), but that adds a lot of boilerplate code and it's not totally clear that rustc doesn't just optimize away the clone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, as_tvm_value seems correct. I guess I'll just make the macros more macro-y to eliminate the repetitive code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could eliminate the allocation on the rust side doing something like:
This wouldn't be able to go through Builder though.
Also, mapping a slice of tuples to a pair of slices is actually surprisingly hard to do with macros. You could avoid doing it if you're able to just call into() twice for each macro, or else you can do some advanced macro magic to map over the slice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be addressed later.
|
e: see my review |
|
@tqchen sure |
|
I replaced |
|
right! @nhynes if I remember correctly, |
|
It's no longer |
|
@tqchen Could you merge this sooner please? I'm working on a feature which requires these fundamental changes and don't want to resolve too many conflicts. |
|
awaiting approval from @kazimuth |
rust/frontend/src/function.rs
Outdated
| .arg_buf | ||
| .iter() | ||
| .map(|tvm_arg| (tvm_arg.value, tvm_arg.type_code as ffi::TVMTypeCode)) | ||
| .map(|arg| arg.clone().into_tvm_value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be addressed later.
|
Done @tqchen |
No description provided.