Skip to content
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

Docstrings for proc macros #1862

Merged
merged 5 commits into from
Nov 30, 2023
Merged

Conversation

ptitjes
Copy link
Contributor

@ptitjes ptitjes commented Nov 26, 2023

No description provided.

@ptitjes ptitjes requested a review from a team as a code owner November 26, 2023 18:11
@ptitjes ptitjes requested review from mhammond and removed request for a team November 26, 2023 18:11
@ptitjes ptitjes changed the title Docstrings for proc macros WIP: Docstrings for proc macros Nov 26, 2023
@ptitjes ptitjes force-pushed the docstrings-for-proc-macros branch 4 times, most recently from 143b0b7 to 5d1e374 Compare November 26, 2023 19:04
Copy link
Collaborator

@jplatte jplatte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

Maybe you're already aware, but there is an alternate PR at #1498 for supporting something like this. As per comments there, I prefer your approach though (as a frequent contributor, not a maintainer) so I'm glad there's now a PR for it :)

fixtures/docstring-proc-macro/Cargo.toml Outdated Show resolved Hide resolved
fixtures/docstring-proc-macro/src/lib.rs Outdated Show resolved Hide resolved
uniffi_macros/src/export/callback_interface.rs Outdated Show resolved Hide resolved
uniffi_macros/src/object.rs Outdated Show resolved Hide resolved
@ptitjes
Copy link
Contributor Author

ptitjes commented Nov 26, 2023

Thanks for working on this!

You're welcome! Please note that I am a very new Rust coder.

Maybe you're already aware, but there is an alternate PR at #1498 for supporting something like this. As per comments there, I would prefer an approach like this though (as a frequent contributor, not a maintainer) so I'm glad there's now a PR for it :)

No, I missed it. But it indeed seems the approach used here is more straightforward.

@ptitjes ptitjes changed the title WIP: Docstrings for proc macros Docstrings for proc macros Nov 26, 2023
@ptitjes
Copy link
Contributor Author

ptitjes commented Nov 26, 2023

@jplatte I took the liberty to add a commit to add .idea to .gitignore. Also added an entry to the unreleased changelog.

@ptitjes ptitjes requested a review from jplatte November 26, 2023 20:56
@jplatte
Copy link
Collaborator

jplatte commented Nov 27, 2023

cc @bendk @badboy

@badboy badboy self-requested a review November 27, 2023 10:07
@badboy
Copy link
Member

badboy commented Nov 27, 2023

oh yey, I did the same work in the past couple of days and it looks very similar. Given this was posted before I could even get to it I will spend some time on reviewing this instead.

Copy link
Member

@badboy badboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for some naming and ordering this is the same as my implementation that I did 2 days ago and didn't yet push.

So ... good job! Minimal nits.

fixtures/docstring-proc-macro/README.md Outdated Show resolved Hide resolved
uniffi_bindgen/src/bindings/swift/templates/macros.swift Outdated Show resolved Hide resolved
fixtures/docstring-proc-macro/src/lib.rs Show resolved Hide resolved
fixtures/docstring-proc-macro/Cargo.toml Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
@mhammond
Copy link
Member

This is great, thanks! I've a minor preference that we reused the existing docstring fixture for procmacros too, just so as things move forward it's much easier to test and rationalize about any differences between procmacros and UDL - so if you think that makes sense and have the energy to do that it would be great, but I'm not going to try and block this landing for that.

@ptitjes
Copy link
Contributor Author

ptitjes commented Nov 27, 2023

oh yey, I did the same work in the past couple of days and it looks very similar. Given this was posted before I could even get to it I will spend some time on reviewing this instead.

I am really sorry if stepped on your toes. There was no issue open, so I jumped on it as I needed it.

@ptitjes
Copy link
Contributor Author

ptitjes commented Nov 27, 2023

just so as things move forward it's much easier to test and rationalize about any differences between procmacros and UDL

Not that I am too lazy, but I really think it is better to have separate fixture to easily compare the generated code with UDL or procmacros. As the symbols have the same names, you can easily diff and spot the differences. For example:

--- uniffi-fixture-docstring-49c2dd0b0f909ef/uniffi/fixture/docstring/uniffi_docstring.kt	2023-11-27 19:27:01.335778828 +0100
+++ uniffi-fixture-docstring-proc-macro-a3df46f603a93fe/uniffi/fixture/docstring/proc/macro/uniffi_docstring_proc_macro.kt	2023-11-27 19:27:12.867338022 +0100

...

@@ -999,6 +999,9 @@
      */
     data class Test(
         
+        /**
+         * <docstring-variant-field>
+         */
         val `code`: Short
         ) : AssociatedEnumTest() {
         companion object

BTW, I think we should improve the docstring use in templates. Fields' docstring should really be used as a @param in the parent symbol, at for Kotlin. But that is a job for another time. (I will create an issue.)

@ptitjes
Copy link
Contributor Author

ptitjes commented Nov 27, 2023

@badboy @mhammond @jplatte All changes done.

@ptitjes
Copy link
Contributor Author

ptitjes commented Nov 27, 2023

I forgot to commit the Cargo.lock. Now we should be good.

Copy link
Contributor

@skeet70 skeet70 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traits and trait methods get docstrings, and in the test code the implementer of the callback trait inherits the CallbackTest docstring. Does the same happen with a

#[uniffi::export]
pub trait NotCallbackTest {
  /// <docstring-trait-method>
  fn other_test(&self);
}

#[uniffi::export]
impl NotCallbackTest for Object {
  fn other_test(&self) {}
}

or does the method that shows up from the impl require its own duplicate docstring be defined?

@mhammond
Copy link
Member

BTW, I think we should improve the docstring use in templates. Fields' docstring should really be used as a @param in the parent symbol, at for Kotlin. But that is a job for another time. (I will create an issue.)

Yeah - I agree - and that's why I think a single fixture is better. IMO, the fact that the existing fixture uses such trivial strings is actually a mis-feature - it will eventually need to grow into richer strings, so we can test newlines, indentation, whitespace, and as you mention, even more advanced things like @param. If we assume we want the same behaviour in both cases, it seems having 2 discrete fixtures will make life more complicated as they diverge.

Not that I am too lazy, but I really think it is better to have separate fixture to easily compare the generated code with UDL or procmacros. As the symbols have the same names, you can easily diff and spot the differences. For example:

I'm mildly skeptical this will work in the future. If we take the @param example, we'd need to be very careful that both fixtures were changed in a lock-step way to ensure that remained true. More likely in reality is that someone will submit a PR which touches only 1 - either because they are not aware of the other fixture at all, or not aware they should be kept so lock-step to enable this kind of manual diffing. A single fixture would make that less likely and even allow CI to help - it's much easier to test for invariants inside a single fixture than across 2 discrete ones.

(I'm still not too bothered and still not going to try and block this landing for this, but figured I'd expand on my thinking here.)

@badboy
Copy link
Member

badboy commented Nov 27, 2023

I am really sorry if stepped on your toes. There was no issue open, so I jumped on it as I needed it.

no worries, I started working on this on the weekend.

BTW, I think we should improve the docstring use in templates. Fields' docstring should really be used as a @param in the parent symbol, at for Kotlin. But that is a job for another time. (I will create an issue.)

Yeah - I agree - and that's why I think a single fixture is better. IMO, the fact that the existing fixture uses such trivial strings is actually a mis-feature - it will eventually need to grow into richer strings, so we can test newlines, indentation, whitespace, and as you mention, even more advanced things like @param. If we assume we want the same behaviour in both cases, it seems having 2 discrete fixtures will make life more complicated as they diverge.

I actually get what you mean and I'd be willing to tackle this separately after we merge this PR.

@badboy
Copy link
Member

badboy commented Nov 30, 2023

GitHub complained about merge conflicts even after I resolved them in the web UI, so I opted to rebase manually and force-push. All I did was clear up the merge conflict in changelog.md.

@badboy badboy merged commit 45d0f34 into mozilla:main Nov 30, 2023
0 of 5 checks passed
@ptitjes ptitjes deleted the docstrings-for-proc-macros branch November 30, 2023 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants