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

feat: added doc-generator #3350

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d79b8ed
added doc-generator
Sakapoi Oct 30, 2023
9c9d53b
fmt
Sakapoi Oct 30, 2023
a200d2d
Merge branch 'master' into doc-generator
Sakapoi Oct 30, 2023
ab42284
fixed comment display
Sakapoi Oct 30, 2023
3d2eee1
Merge branch 'master' into doc-generator
kevaundray Oct 30, 2023
8bb08b1
chore!: Move circuit serialization circuit into acir (#3345)
kevaundray Oct 30, 2023
718f878
changed Cargo.lock
Sakapoi Oct 30, 2023
e0c127b
Merge branch 'master' into doc-generator
Sakapoi Oct 30, 2023
2d12504
added doc-domments
Sakapoi Oct 30, 2023
656b662
Merge branch 'master' into doc-generator
Sakapoi Oct 30, 2023
7ca5ce1
changed fork to main repo, fixed bugs
Sakapoi Nov 8, 2023
cd766d5
fmt
Sakapoi Nov 8, 2023
490a0ce
Merge branch 'master' into doc-generator
Sakapoi Nov 8, 2023
415c673
added cli
Sakapoi Nov 8, 2023
2a16001
Merge branch 'master' into doc-generator
Sakapoi Nov 8, 2023
e3074f5
added tests
Sakapoi Nov 8, 2023
ac81b1d
fmt
Sakapoi Nov 8, 2023
bf7be71
removed panics and fixed problems
Sakapoi Nov 15, 2023
e872287
Merge branch 'master' into doc-generator
Sakapoi Nov 15, 2023
a083e50
chore: update `Cargo.lock`
Dec 1, 2023
b9fdf3e
Merge branch 'master' into doc-generator
Dec 1, 2023
0d78c1f
chore: fix typo :)
Dec 1, 2023
551748f
chore: make clippy happy
Dec 1, 2023
19fe804
chore: fix Cargo.toml :)
Dec 1, 2023
338c10e
chore: add lints :)
Dec 1, 2023
169b350
chore: thiserror.workspace = true
Dec 1, 2023
cf0c976
chore: fix tests
Dec 1, 2023
7db76eb
Merge branch 'master' into doc-generator
kevaundray Dec 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"tooling/bb_abstraction_leaks",
"tooling/lsp",
"tooling/debugger",
"tooling/doc_generator",
"tooling/nargo",
"tooling/nargo_fmt",
"tooling/nargo_cli",
Expand Down Expand Up @@ -56,6 +57,7 @@ nargo_cli = { path = "tooling/nargo_cli" }
nargo_toml = { path = "tooling/nargo_toml" }
noir_lsp = { path = "tooling/lsp" }
noir_debugger = { path = "tooling/debugger" }
doc_generator ={ path = "tooling/doc_generator"}
noirc_abi = { path = "tooling/noirc_abi" }
bb_abstraction_leaks = { path = "tooling/bb_abstraction_leaks" }
noirc_driver = { path = "compiler/noirc_driver" }
Expand Down
10 changes: 10 additions & 0 deletions tooling/doc_generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "doc-generator"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
askama = "0.12"
noirc_frontend = {git = "https://github.com/Sakapoi/noir_fork.git", branch = "doc_comments"}
Sakapoi marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions tooling/doc_generator/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Noir doc generator

## General information

This program generates the documentation files for the Noir language. The input files with Noir code are placed in the `input_files` folder. When you run the program with `cargo run`, the documentation files in the `generated_doc` folder are generated.

## Screenshots

### Main page

![mainpage](Screenshots/Main_page.png)

### Code page

![codepage](Screenshots/Code_page.png)

### Function page

![functionpage](Screenshots/Function_page.png)

### Structure page

![structpage](Screenshots/Struct_page.png)

### Trait page

![traitpage](Screenshots/Trait_page.png)

### Search page

![searchpage](Screenshots/Search_page.png)
Binary file added tooling/doc_generator/Screenshots/Code_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tooling/doc_generator/Screenshots/Main_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tooling/doc_generator/Screenshots/Search_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tooling/doc_generator/Screenshots/Trait_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tooling/doc_generator/Screenshots/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tooling/doc_generator/input_files/another_module.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn main1(x : Field, y : pub Field) {
assert(x != y);
}

struct MyStruct1 {
mana: i32,
name: String,
}

impl MyStruct1 {
fn new() {}
}
7 changes: 7 additions & 0 deletions tooling/doc_generator/input_files/function_example.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
///doc comment
/*
This is a block comment describing a complex function.
*/
fn main(x : Field, y : pub Field) {
assert(x != y);
}
244 changes: 244 additions & 0 deletions tooling/doc_generator/input_files/prog.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
//! Note the documentation for the primitives **str** and **[T]** (also
//! called 'slice'). Many method calls on **String** and **Vec<T>** are actually
//! calls to methods on **str** and **[T]** respectively, via **deref
//! coercions**.



///doc comment
/*
This is a block comment describing a complex function.
*/
fn main(x : Field, y : pub Field) {
assert(x != y);
}

///qwe
///rty
fn simple_fn(){}

///qwe
///rty
pub fn pub_fn(){}

//! Data available to helper can be found in [Helper](struct.Helper.html). And there are more
//! examples in [HelperDef](trait.HelperDef.html) page.
//!
//! You can learn more about helpers by looking into source code of built-in helpers.
//!
//! Like our JavaScript counterparts, handlebars allows user to define simple helpers with
//! a scripting language, [rhai](https://docs.rs/crate/rhai/). This can be enabled by
//! turning on `script_helper` feature flag.

/// struct
struct MyStruct {
mana: i32,
name: String,
}

///a
///lot
///of
/**
doc
comments
*/
fn another_fn(){}

pub struct AnotherStruct {
pub name: String,
pub number: i32,
}

impl MyStruct {
fn new() {}
}

impl<X: SampleUniform> MyStruct<X> {
/// Create a new `Uniform` instance which samples uniformly from the half
/// open range `[low, high)` (excluding `high`). Panics if `low >= high`.
pub fn new<B1, B2>(low: B1, high: B2) -> Uniform<X>
where
B1: SampleBorrow<X> + Sized,
B2: SampleBorrow<X> + Sized,
{
Uniform(X::Sampler::new(low, high))
}

/// Create a new `Uniform` instance which samples uniformly from the closed
/// range `[low, high]` (inclusive). Panics if `low > high`.
pub fn new_inclusive<B1, B2>(low: B1, high: B2) -> Uniform<X>
where
B1: SampleBorrow<X> + Sized,
B2: SampleBorrow<X> + Sized,
{
Uniform(X::Sampler::new_inclusive(low, high))
}
}

/// Range that supports generating a single sample efficiently.
///
/// Any type implementing this trait can be used to specify the sampled range
/// for `Rng::gen_range`.
pub trait SampleRange<T> {
/// Generate a sample from the given range.
fn sample_single<R: RngCore + ?Sized>(self, rng: &mut R) -> T;

/// Check whether the range is empty.
fn is_empty(&self) -> bool;
}

impl<T: SampleUniform + PartialOrd> SampleRange<T> for AnotherStruct<T> {
#[inline]
fn sample_single<R: RngCore + ?Sized>(self, rng: &mut R) -> T {
T::Sampler::sample_single(self.start, self.end, rng)
}

#[inline]
fn is_empty(&self) -> bool {
!(self.start < self.end)
}
}

/// this is a trait =-=
//! Helper trait handling actual uniform sampling.
//!
//! See the [module documentation] on how to implement [`Uniform`] range
//! sampling for a custom type.
//!
//! Implementation of [`sample_single`] is optional, and is only useful when
//! the implementation can be faster than `Self::new(low, high).sample(rng)`.
//!
//! [module documentation]: crate::distributions::uniform
//! [`sample_single`]: UniformSampler::sample_single
pub trait UniformSampler: Sized {
/// The type sampled by this implementation.
type X;

/// Construct self, with inclusive lower bound and exclusive upper bound
/// `[low, high)`.
///
/// Usually users should not call this directly but instead use
/// `Uniform::new`, which asserts that `low < high` before calling this.
fn new<B1, B2>(low: B1, high: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized;

/// Construct self, with inclusive bounds `[low, high]`.
///
/// Usually users should not call this directly but instead use
/// `Uniform::new_inclusive`, which asserts that `low <= high` before
/// calling this.
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized;

/// Sample a value.
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X;

/// Sample a single value uniformly from a range with inclusive lower bound
/// and exclusive upper bound `[low, high)`.
///
/// By default this is implemented using
/// `UniformSampler::new(low, high).sample(rng)`. However, for some types
/// more optimal implementations for single usage may be provided via this
/// method (which is the case for integers and floats).
/// Results may not be identical.
///
/// Note that to use this method in a generic context, the type needs to be
/// retrieved via `SampleUniform::Sampler` as follows:
/// ```
/// use rand::{thread_rng, distributions::uniform::{SampleUniform, UniformSampler}};
/// # #[allow(unused)]
/// fn sample_from_range<T: SampleUniform>(lb: T, ub: T) -> T {
/// let mut rng = thread_rng();
/// <T as SampleUniform>::Sampler::sample_single(lb, ub, &mut rng)
/// }
/// ```
fn sample_single<R: Rng + ?Sized, B1, B2>(low: B1, high: B2, rng: &mut R) -> Self::X
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
{
let uniform: Self = UniformSampler::new(low, high);
uniform.sample(rng)
}

fn new_fn() -> i32;

/// Sample a single value uniformly from a range with inclusive lower bound
/// and inclusive upper bound `[low, high]`.
///
/// By default this is implemented using
/// `UniformSampler::new_inclusive(low, high).sample(rng)`. However, for
/// some types more optimal implementations for single usage may be provided
/// via this method.
/// Results may not be identical.
fn sample_single_inclusive<R: Rng + ?Sized, B1, B2>(low: B1, high: B2, rng: &mut R)
-> Self::X
where B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized
{
let uniform: Self = UniformSampler::new_inclusive(low, high);
uniform.sample(rng)
}
}

impl UniformSampler for UniformChar {
type X = char;

#[inline] // if the range is constant, this helps LLVM to do the
// calculations at compile-time.
fn new<B1, B2>(low_b: B1, high_b: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
{
let low = char_to_comp_u32(*low_b.borrow());
let high = char_to_comp_u32(*high_b.borrow());
let sampler = UniformInt::<u32>::new(low, high);
UniformChar { sampler }
}

#[inline] // if the range is constant, this helps LLVM to do the
// calculations at compile-time.
fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
{
let low = char_to_comp_u32(*low_b.borrow());
let high = char_to_comp_u32(*high_b.borrow());
let sampler = UniformInt::<u32>::new_inclusive(low, high);
UniformChar { sampler }
}

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
let mut x = self.sampler.sample(rng);
if x >= CHAR_SURROGATE_START {
x += CHAR_SURROGATE_LEN;
}
// SAFETY: x must not be in surrogate range or greater than char::MAX.
// This relies on range constructors which accept char arguments.
// Validity of input char values is assumed.
unsafe { core::char::from_u32_unchecked(x) }
}
}

mod MyModule {
///module function
fn module_fn() {
let a = 100;
}

struct MyStruct {
mana: i32,
name: String,
}
}

mod another_module;

fn yes () {}
5 changes: 5 additions & 0 deletions tooling/doc_generator/input_files/struct_example.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
///struct
struct MyStruct {
mana: i32,
name: String,
}
Loading