-
Notifications
You must be signed in to change notification settings - Fork 234
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
Add initial proc-macro frontend bits #1259
Conversation
a5cf590
to
07a8b2c
Compare
This comment was marked as resolved.
This comment was marked as resolved.
There's also the issue that the proc-macros having their own output files as tracked files currently seems to result in cargo always considering them to require recompilation. I have an idea for a fix, and will try to remember pushing it as a separate commit to make review easier. |
8c61fa2
to
3b6c2cf
Compare
Now there's one clear person responsible for reviewing or tagging the next person. Still, I feel like I should cc one more person (@badboy) just so everyone involved has a chance of checking out what my idea discussed over the last week looks like in code. |
Will give it a look. |
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 is really exciting. The general direction seems good to me, I left a few comments about specifics, but I like the way it's going overall.
|
||
impl From<uniffi_meta::FnMetadata> for Function { | ||
fn from(meta: uniffi_meta::FnMetadata) -> Self { | ||
let checksum = uniffi_meta::checksum(&meta); |
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 makes checksums specific to a scaffolding function, rather than based on entire interface. This seems like it will work fine and I think it matches the decision from the planning meeting. Can you confirm @tarikeshaq?
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.
Yup! I haven't gotten the time to write it up just yet but having checksums be per function is pretty much what we talked about
We landed on per type checksums + an overall ComponentInterface schema version of some sort
default: None, | ||
} | ||
} | ||
} |
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.
These conversion functions seem like a good starting point, but it makes me wonder if we could eventually use the uniffi_meta
types directly. The fact that they implement Serialize
opens the door to using them with other templating engines like handlebars or terra.
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.
My thinking was that this would be a good starting point that would work well while the UDL stuff still exists as well. I think it makes sense to remove the other types after the proc-macro has fully replaced UDL.
// influenced by things added later from proc-macro metadata. Those have their own | ||
// namespacing mechanism. | ||
assert!(!ci.namespace.is_empty()); | ||
ci.ffi_namespace = format!("{}_{:x}", ci.namespace, ci.checksum()); |
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.
Maybe it's time to drop the interface-wide namespace?
- For user functions/methods/callback interfaces, I like your system of using a checksum that's just based on the function args. It seems like we could do that regardless of if we're using UDL or a proc-macro.
- For the uniffi functions like
rustbuffer_alloc
, maybe we can skip the checksum? I doubt we're going to need to change the signatures for those much and if we do we can pick a new name. BTW, I like you were prefixing everything with__uniffi
, maybe we could use names like__uniffi__rustbuffer_alloc
If there's no interface-wide namespace, then the derive_ffi_funcs()
methods might not be needed since the names don't depend on the ci_prefix
.
I think this could be done in a separate PR that could be merged now.
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.
I think this could be done in a separate PR
Definitely. Doesn't really matter whether it would be merged before or after this PR, right?
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.
After thinking about this more, the issue with dropping the interface-wide namespace is trying to combine multiple UniFFI crates in the same .so, like we currently do. In that case, you need each rustbuffer_alloc
function to have a different name (for now at least, at some point maybe we could figure out a way to avoid this duplication). Also, if 2 functions from different UniFFIed crates have the same name and signature then we would get a collision.
It's unfortunate that derive_ffi_funcs()
needs to stay and the way we generate the prefix differs between the UDL approach and the macro-based approach, but I think we can live with that.
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.
Indeed exciting. And much more self-contained than I would have expected.
And even for those things where I thought it might be tricky (placement of the json files, ...) it doesn't seem to be an issue.
👏
Only a couple comments from my side, on top of what's already been reported.
Span::call_site(), | ||
"impl blocks are not yet supported", | ||
)), | ||
// FIXME: Support const / static? |
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.
What do you think about supporting a module here as well? That would be equivalent to wrapping each item in the module.
Some users like how the UDL lets you see the entire API in one place. In a proc-macro world, I think that would translate to a single ffi module with the uniffi:export
attribute.
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.
I guess it could work 🤷🏼
Doing it well (w.r.t. error handling) would be a decent amount of work though, I think.
Regarding the Is that the only thing that needs to be resolved before this can be merged? |
I think it's fine if it evolves as you develop this feature.
I think everyone needs to be on board with the plan of developing this in That said, if not having it merged is holding you back, then I'd be okay with merging it right now. |
So, the question is if it's okay to commit to merging this into main. The biggest risk is that we find out down the line that something isn't going to work out and need to back out the code. I think we've thought this one through pretty well, so that risk is quite small. Also, most of the changes are self-contained like @badboy mentioned. But I'm just going to flag some more devs just in case (@jhugman @skhamis @rfk) The main question I have is the FFI naming change. I made #1271 which focuses on just that. Does that plan seem good to others? Are there any other concerns that should block this from being merged? |
`from_webidl` is more explicit and hardly less convenient.
9bf4f0e
to
500eb7f
Compare
Rebased to fix merge conflicts. The last two commits are new and address more recent review feedback. I guess this is now waiting for #1271 either way though, right? |
c72d06e
to
b8c82f9
Compare
The feedback from #1271 has been positive, I think we can be pretty confident on the direction of the naming changes. I don't see any concerns against this PR, so I'm just going to go ahead and merge it so that we can continue to iterate. |
Based on #1258.
First part of #1257.