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

Rewrite fuel_asm::impl_instructions! to a proc macro #804

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

Dentosal
Copy link
Member

@Dentosal Dentosal commented Aug 21, 2024

What it says on the tin. No exteranal functional changes, just refactoring.

Crate-internal test_construct function has been removed, as the associated test didn't seem to catch any errors. It has been rewritten to use a fuzzing-style property-based testing.

The purpose of this PR is to allow more complex instruction definitions in the future. This should allow moving some validity checks to instruction parsing level, and to improve type safety.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog (None!!)
  • New behavior is reflected in tests (No new behavior!)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

@Dentosal Dentosal added the fuel-asm Related to the `fuel-asm` crate. label Aug 21, 2024
@Dentosal Dentosal self-assigned this Aug 21, 2024
@Dentosal Dentosal marked this pull request as ready for review August 22, 2024 07:41
@Dentosal Dentosal requested a review from a team August 22, 2024 07:41
let name = &arg.name;
if arg.is_imm() {
quote! {
packed_integer |= (#name.to_smallest_int() as u32);
Copy link
Member

Choose a reason for hiding this comment

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

Places like this would be better with a single-use helper function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved most of these to smaller functions.

@Dentosal Dentosal requested review from MitchTurner and a team August 22, 2024 23:31
netrome
netrome previously approved these changes Aug 26, 2024
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Nice stuff! While I still find macros hard to read in general, the code after the refactor is much easier to follow than the previous implementation of this macro. Thanks for making this improvement!

fuel-asm/derive/src/codegen.rs Outdated Show resolved Hide resolved
fuel-asm/Cargo.toml Show resolved Hide resolved
fuel-derive/src/asm.rs Outdated Show resolved Hide resolved
fuel-derive/src/asm.rs Outdated Show resolved Hide resolved
fuel-derive/src/asm.rs Outdated Show resolved Hide resolved
fuel-derive/src/asm.rs Outdated Show resolved Hide resolved
fuel-derive/src/asm.rs Outdated Show resolved Hide resolved
fuel-derive/src/asm.rs Outdated Show resolved Hide resolved
fuel-derive/src/asm.rs Outdated Show resolved Hide resolved
.0
.iter()
.map(
|Instruction {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice for each closure that we use inside of the map to have a named function like make_constructor_for_opcode. Name is up to you=)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've simplified the code quite a bit and each map has only a small block of code inside. Let me know if you still feel we need to have the closures as separate functions as well.

@Dentosal Dentosal requested a review from a team August 27, 2024 01:52
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuel-asm Related to the `fuel-asm` crate.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants