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

Generate special code for rustdoc compilations #32

Closed
Robbepop opened this issue Mar 15, 2019 · 2 comments
Closed

Generate special code for rustdoc compilations #32

Robbepop opened this issue Mar 15, 2019 · 2 comments
Assignees
Labels
A-ink_lang [ink_lang] Work item B-enhancement New feature or request

Comments

@Robbepop
Copy link
Collaborator

Currently the auto generated documentation for smart contracts written in the eDSL (pdsl_lang) is sup optimal. For example messages have their env: &EnvHandler argument that should not be visible in the documentation.

Using rust-lang/rust#43781 we can get further with conditional compilation.
So upon using pdsl_lang we can catch a rustfmt or cargo fmt run with #[cfg(rustdoc)] and can generate special code just for documentation purposes.

@Robbepop Robbepop added B-enhancement New feature or request D-medium A-ink_lang [ink_lang] Work item labels Mar 15, 2019
@Robbepop Robbepop changed the title Make generating auto-docs simple Generate special code for rustdoc compilations Mar 27, 2019
@Robbepop
Copy link
Collaborator Author

Robbepop commented Mar 27, 2019

We want to make use of this Rust feature in order to generate special code upon rustfmt compilation. In the end we want clear and concise docs for our smart contracts.

Example

If we take the simple example Flipper smart contract we want to generate code in rustfmt mode as if our code was actually just the following:

/// The flipper contracts that can flip its value and return its current state.
struct Flipper {
    /// Our to-be-flipped value.
    value: storage::Value<bool>,
}

impl Flipper {
    /// Flips the state of the value.
    pub fn flip(&mut self) {
        if *self.value {
            *self.value = false;
        } else {
            *self.value = true;
        }
    }

    /// Returns the current state of the value.
    pub fn get(&self) {
        *self.value
    }
}

Note

Since we want to support source code inspection we also need to generate all private functions and need to implement the only-doc generated functions like they are supposed to be.

However, for the sake of simplicity we do not require the generated code to be syntactically correct since it might be using env without source (no longer appears in the parameters). Fortunately rustfmt doesn't require the documented source to be valid.

@Robbepop Robbepop self-assigned this Mar 28, 2019
@Robbepop Robbepop removed the D-medium label Nov 22, 2019
@Robbepop
Copy link
Collaborator Author

Superseeded by newer #336.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_lang [ink_lang] Work item B-enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant