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

chore: break big files into smaller ones #316

Closed
wants to merge 5 commits into from

Conversation

guorong009
Copy link

@guorong009 guorong009 commented Apr 23, 2024

Description

Break the big files(> 1k LOC) into smaller files

Related issues

Changes

  • refactor the files in halo2_frontend/src/plonk/circuit dir
    • create new files - ../plonk/circuit/helpers.rs & ../plonk/circuit/constraint_system/helpers.rs
    • move the contents from expression.rs & constraint_system.rs to new files
  • refactor the halo2_frontend/src/circuit.rs file
    • create new file witness_collector.rs inside halo2_frontend/src/circuit/ dir

NOTE

There are additional big files - halo2_frontend/src/dev.rs & halo2_backend/src/plonk/prover.rs.
I believe they don't need splitting, since they include only what's needed.

@guorong009 guorong009 requested review from adria0 and ed255 April 23, 2024 07:26
@guorong009 guorong009 self-assigned this Apr 23, 2024
Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

Most of the changes look good to me but I have two comments:

The first is that I see the new files column.rs, phase.rs and query.rs which have definitions that were previously in expression.rs. I notice that these new files are very small. Could they be merged in a single file?

The other comment is related to plonk/circuit.rs. To me it feels strange to move the types Constraint, Constraints, SelectorsToFixed, Gate and so on, which are types directly used by the ConstraintSystem at plonk/circuit/constraint_system.rs into plonk/circuits.rs which is a more general module. In my mind, the more general things are in less deep modules, and more specific things are in more deep modules; so it's strange to see that types that are used specifically by plonk/circuit/constraint_system.rs are found in plonk/circuit.rs. I think I would prefer moving those to plonk/circuit/constraint_system/foo.rs instead.

Please let me know your thoughts about these two points. To me the second one is more important to discuss and resolve; the first one could be more related to personal taste.

@guorong009
Copy link
Author

Most of the changes look good to me but I have two comments:

The first is that I see the new files column.rs, phase.rs and query.rs which have definitions that were previously in expression.rs. I notice that these new files are very small. Could they be merged in a single file?

The other comment is related to plonk/circuit.rs. To me it feels strange to move the types Constraint, Constraints, SelectorsToFixed, Gate and so on, which are types directly used by the ConstraintSystem at plonk/circuit/constraint_system.rs into plonk/circuits.rs which is a more general module. In my mind, the more general things are in less deep modules, and more specific things are in more deep modules; so it's strange to see that types that are used specifically by plonk/circuit/constraint_system.rs are found in plonk/circuit.rs. I think I would prefer moving those to plonk/circuit/constraint_system/foo.rs instead.

Please let me know your thoughts about these two points. To me the second one is more important to discuss and resolve; the first one could be more related to personal taste.

Thanks for suggestions! @ed255

  1. I believe it is right to create less new files.
    Hence, I remove 3 new files & create plonk/circuit/helpers.rs file for Expression -related contents.

  2. I also think you are right.
    FYI, I originally moved out all of those structs to plonk/circuit.rs,
    because they are also exported & used in halo2_proofs crate.
    But, it seems that there is no need.
    I create a new file plonk/circuit/constraint_system/helpers.rs for ConstraintSystem-related contents.

Please check new updates & give more feedback.

@guorong009 guorong009 requested a review from ed255 April 24, 2024 06:18
Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

I'm not 100% convinced about naming the new modules "helpers", as it looks like a generic placeholder, but I can't think of anything better 🤔
Apart from that, LGTM!

@guorong009
Copy link
Author

Thanks for the review! @ed255

I think this PR is a bit awkward since it tries to split the code in unnatural way.
It just aims to reduce the LOC, and breaks the cohesion. Plus, a new structure is not that good.
How about closing the PR, without merge? (Maybe, close the issue also?)

@ed255
Copy link
Member

ed255 commented Apr 30, 2024

I think this PR is a bit awkward since it tries to split the code in unnatural way. It just aims to reduce the LOC, and breaks the cohesion. Plus, a new structure is not that good. How about closing the PR, without merge? (Maybe, close the issue also?)

Closing the PR and the issue sounds good to me!

@guorong009
Copy link
Author

guorong009 commented Apr 30, 2024

Close the PR since it leads to unnatural, incoherent refactoring.
Plus, close #297 as resolved.

@guorong009 guorong009 closed this Apr 30, 2024
@guorong009 guorong009 deleted the gr@refactor-big-files branch April 30, 2024 16:50
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.

Break big files into smaller ones
2 participants