Skip to content

Document defaults to with xxx methods #3151

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AshAnand34
Copy link
Contributor

Pull Request Template

Checklist

  • Confirmed that cargo run-checks command has been executed.
  • Made sure the book is up to date with changes in this PR.

Tip

Want more detailed macro error diagnostics? This is especially useful for debugging tensor-related tests:

RUSTC_BOOTSTRAP=1 RUSTFLAGS="-Zmacro-backtrace" cargo run-checks

Related Issues/PRs

#2982

Changes

The Config derive macro was missing automatic documentation generation for config structs. This meant that:

  1. Field documentation wasn't being propagated to the generated new function
  2. Builder methods lacked proper documentation about their purpose and default values
  3. Users had to manually document these generated methods, leading to potential inconsistencies.

I added automatic documentation generation to the Config derive macro that:

  1. Propagates field documentation to the new function, creating a comprehensive list of all fields with their descriptions
  2. Generates documentation for builder methods, including:
    • Purpose of the method
    • Default values for fields with defaults
    • Clear indication of optional fields
  3. Handles both required fields, optional fields, and fields with default values appropriately

Testing

Unit tests in burn-core/tests/test_derive_config.rs:

  • test_config_documentation() verifies that:
    • Documentation is properly generated for required fields
    • Documentation is properly generated for optional fields
    • Documentation is properly generated for fields with default values
    • Default values are correctly displayed in the documentation

Copy link
Member

@laggui laggui left a comment

Choose a reason for hiding this comment

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

Looks like there are some issues with the modified config derive (see CI).

@@ -149,104 +149,179 @@ impl ConfigStructAnalyzer {

impl ConfigAnalyzer for ConfigStructAnalyzer {
fn gen_new_fn(&self) -> TokenStream {
Copy link
Member

Choose a reason for hiding this comment

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

The generated new method seems to be invalid.

 crates/burn-core/src/nn/conv/conv2d.rs:17:10:
  called `Result::unwrap()` on an `Err` value: Error("expected value", line: 1, column: 1)

Seems to originate from the serde_json::from_str(#value_str).unwrap(). The values are not captured properly it seems.

This also seems to be reflected in the docstrings, e.g.

Create a new instance of the config.

Fields:

#_name: #_doc
#_name: #_doc
#_name: #_doc Default: #_value_str
#_name: #_doc Default: #_value_str
#_name: #_doc Default: #_value_str
#_name: #_doc Default: #_value_str
#_name: #_doc Default: #value
#_name: #_doc Default: #_value_str

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.

2 participants