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

circuit.rs: Introduce AssignedCell struct. #383

Merged
merged 5 commits into from
Nov 30, 2021
Merged

circuit.rs: Introduce AssignedCell struct. #383

merged 5 commits into from
Nov 30, 2021

Conversation

therealyingtong
Copy link
Collaborator

@therealyingtong therealyingtong commented Oct 11, 2021

Addresses #288.

@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2021

Codecov Report

Merging #383 (c556c92) into main (069aa1d) will decrease coverage by 0.26%.
The diff coverage is 61.53%.

❗ Current head c556c92 differs from pull request most recent head 4b8f0f0. Consider uploading reports for the commit 4b8f0f0 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #383      +/-   ##
==========================================
- Coverage   70.65%   70.38%   -0.27%     
==========================================
  Files          42       42              
  Lines        5227     5278      +51     
==========================================
+ Hits         3693     3715      +22     
- Misses       1534     1563      +29     
Impacted Files Coverage Δ
benches/plonk.rs 0.00% <0.00%> (ø)
src/circuit.rs 48.48% <60.00%> (+2.45%) ⬆️
src/plonk/circuit.rs 59.05% <100.00%> (+0.15%) ⬆️
tests/plonk_api.rs 89.63% <100.00%> (ø)
src/plonk/error.rs 6.45% <0.00%> (+0.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 069aa1d...4b8f0f0. Read the comment docs.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

utACK. I'd like to see some examples (in another PR) of how this works to improve the Orchard circuit.

@therealyingtong therealyingtong changed the title circuit.rs: Introduce AllocatedCell struct. circuit.rs: Introduce AssignedCell struct. Oct 14, 2021
Copy link
Contributor

@ebfull ebfull left a comment

Choose a reason for hiding this comment

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

ACK modulo a question.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

Flusing comments from my pairing with @therealyingtong.

We only need V: Clone and for<'v> Assigned<F>: From<&'v V> for
specific methods.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
@str4d str4d mentioned this pull request Nov 30, 2021
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

utACK 839f9ec

@@ -110,7 +110,7 @@ fn bench_with_k(name: &str, k: u32, c: &mut Criterion) {
region.assign_fixed(|| "b", self.config.sb, 0, || Ok(FF::zero()))?;
region.assign_fixed(|| "c", self.config.sc, 0, || Ok(FF::one()))?;
region.assign_fixed(|| "a * b", self.config.sm, 0, || Ok(FF::one()))?;
Ok((lhs, rhs, out))
Ok((lhs.cell(), rhs.cell(), out.cell()))
Copy link
Contributor

Choose a reason for hiding this comment

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

We should clean up the examples to use the newer APIs where possible. I've opened #412 to track this.

@@ -92,6 +92,64 @@ pub struct Cell {
column: Column<Any>,
}

/// An assigned cell.
#[derive(Clone, Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Something neat I probably already knew but just became aware of is that if you add #[derive(Clone)] to a struct with generics, Rust will implement it in a way that the struct is Clone when its type parameters are all Clone.

I think it's okay to have impl Clone for AssignedCell, because the underlying Cell is a pointer to the actual cell, so what we'd be cloning is the pointer in addition to the value, which is fine to do without layouter awareness. I don't believe this will be confused with AssignedCell::copy_advice, which clones only the value and assigns a new Cell, because Clone can't be used to satisfy a constraint (as the cell will be in the wrong location).

let mut value = None;
let cell =
self.region
.assign_advice(&|| annotation().into(), column, offset, &mut || {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't the annotation just passed in directly in these sorts of places, instead of wrapping it in another closure?

Copy link
Contributor

@str4d str4d Nov 30, 2021

Choose a reason for hiding this comment

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

Lifetimes IIRC. This pattern is unaltered by this PR.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
@str4d
Copy link
Contributor

str4d commented Nov 30, 2021

GitHub wouldn't let me batch all of @daira's code comment suggestions, so I created several commits, then no-op force-pushed to squash them into a single commit.

b.0.copy_advice(|| "rhs", &mut region, config.advice[1], 0)?;

// Now we can assign the multiplication result, which is to be assigned
// into the output position.
Copy link
Contributor

@daira daira Nov 30, 2021

Choose a reason for hiding this comment

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

This comment was missed; change it to be like the others ("Now we can compute the multiplication result, which is to be assigned into the output position.").

Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid another round of re-ACKs, I'll defer this to #412.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

utACK with comments.

@str4d str4d merged commit afd7bc5 into main Nov 30, 2021
@str4d str4d deleted the allocated-cell branch November 30, 2021 23:42
@str4d str4d mentioned this pull request Dec 8, 2021
str4d added a commit that referenced this pull request Dec 11, 2021
In #383 we altered the bounds on region assignment methods
like `Region::assign_advice` to constrain the value closure's result on
`for<'vr> Assigned<F>: From<&'vr VR>` instead of `VR: Into<Assigned<F>>`.
This had the unintended side-effect that `Assigned<F>` could no longer
be returned from the closure, because we were previously relying on the
implicit `impl From<T> for T` provided by Rust, which no longer fits the
bound. This commit adds the missing from-reference impl to restore
functionality, re-enabling inversion deferrment.
str4d added a commit that referenced this pull request Jan 3, 2022
In #383 we altered the bounds on region assignment methods
like `Region::assign_advice` to constrain the value closure's result on
`for<'vr> Assigned<F>: From<&'vr VR>` instead of `VR: Into<Assigned<F>>`.
This had the unintended side-effect that `Assigned<F>` could no longer
be returned from the closure, because we were previously relying on the
implicit `impl From<T> for T` provided by Rust, which no longer fits the
bound. This commit adds the missing from-reference impl to restore
functionality, re-enabling inversion deferrment.
str4d added a commit that referenced this pull request Jan 21, 2022
In #383 we altered the bounds on region assignment methods
like `Region::assign_advice` to constrain the value closure's result on
`for<'vr> Assigned<F>: From<&'vr VR>` instead of `VR: Into<Assigned<F>>`.
This had the unintended side-effect that `Assigned<F>` could no longer
be returned from the closure, because we were previously relying on the
implicit `impl From<T> for T` provided by Rust, which no longer fits the
bound. This commit adds the missing from-reference impl to restore
functionality, re-enabling inversion deferrment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants