这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@rahxephon89
Copy link
Contributor

@rahxephon89 rahxephon89 commented Nov 11, 2025

Description

This PR adds the code generation of public APIs for structs and enums to file format generator.

For structs and enums the following apis are generated:

  • pack$address$module$struct[$variant](_field_name: _field_type, ...): struct_type
  • unpack$address$module$struct[$variant](_s: struct_type): (field_type, ...)
  • borrow[_mut]$address$module$struct$field$offset[$variant](_s: &[mut] struct_type): &[mut] field_type

For enums, test variant api is generated:

  • test_variant$address$module$enum$variant(_s: &enum_type): bool

For a struct with n fields, the number of generated functions is 2 + 2 * n;
For an enum with m variants and each variant has n fields and all fields have separated borrow field functions, the number of generated functions is 3*m + 2 * m * n.

Note that attributes will be added in sub sequent PRs.

How Has This Been Tested?

New unit tests, transactional tests and e2e move test cases are added. Note that some cases are generating bytecode verification error due to limitation of current borrow semantics for functions. This will be resolved in subsequent PRs.

Key Areas to Review

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Move Compiler
  • Other (specify)

Checklist

  • I have read and followed the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I identified and added all stakeholders and component owners affected by this change as reviewers
  • I tested both happy and unhappy path of the functionality
  • I have made corresponding changes to the documentation

Note

Generate pack/unpack/borrow/test-variant APIs for public/package structs/enums and auto-wrap cross-module operations to these APIs; add supporting indices, source-map wiring, model updates, and extensive tests/config.

  • Compiler v2 (file_format_generator):
    • Add API generation for public/package structs/enums:
      • pack$…, unpack$…, borrow$…/borrow_mut$…, and test_variant$… functions (incl. variants and generics).
    • Route cross-module Pack/Unpack/TestVariant/BorrowField ops to the generated API calls (with instantiation helpers and FreezeRef as needed).
    • Introduce builders and indices for API handles; support borrow-field over variants (incl. ambiguity checks) and empty-struct early return.
    • Add function-handle→instantiation cache; improve source-map parameter/type-param mappings.
  • Model/Builder:
    • Track is_empty_struct; include visibility handling and allow attaching functions created by API generation when loading bytecode.
    • Expose well-known names for API prefixes/delimiters.
  • Tests:
    • Add e2e public_structs_enums_upgrade.
    • Add transactional tests for struct/enum visibility features and expected bytecode (structs_visibility/*).
    • Update test harness: add public-struct config and exclude new suite from other configs; adjust separate baselines.

Written by Cursor Bugbot for commit c550c6e. This will update automatically on new commits. Configure here.

Copy link
Contributor Author

rahxephon89 commented Nov 11, 2025

@rahxephon89 rahxephon89 force-pushed the teng/refactor-public-structs-remove-codegen branch from a764f00 to 927a48e Compare November 11, 2025 18:58
@rahxephon89 rahxephon89 changed the title file format code gen [compiler] add visibility modifier to structs/enums: step 2 Nov 11, 2025
@rahxephon89 rahxephon89 force-pushed the teng/file-format-gen branch 3 times, most recently from 292a245 to 7c8867c Compare November 12, 2025 01:20
@rahxephon89 rahxephon89 force-pushed the teng/refactor-public-structs-remove-codegen branch from 927a48e to 1682ec5 Compare November 12, 2025 01:20
@rahxephon89 rahxephon89 force-pushed the teng/refactor-public-structs-remove-codegen branch from 1682ec5 to b5d8385 Compare November 12, 2025 01:25
============ bytecode verification failed ========

Diagnostics:
bug: bytecode verification failed with unexpected status code `CALL_BORROWED_MUTABLE_REFERENCE_ERROR`:
Copy link
Contributor Author

@rahxephon89 rahxephon89 Nov 12, 2025

Choose a reason for hiding this comment

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

This kind of error will go away once we change the bytecode verifier.

@rahxephon89 rahxephon89 force-pushed the teng/file-format-gen branch 2 times, most recently from 6cc3c83 to 5b30bcd Compare November 12, 2025 21:47
@rahxephon89 rahxephon89 force-pushed the teng/refactor-public-structs-remove-codegen branch 2 times, most recently from e1b0417 to dfff6fd Compare November 12, 2025 22:53
@rahxephon89 rahxephon89 force-pushed the teng/file-format-gen branch 3 times, most recently from e524ad8 to d15279d Compare November 13, 2025 01:48
@rahxephon89 rahxephon89 force-pushed the teng/refactor-public-structs-remove-codegen branch from dfff6fd to 1e893c8 Compare November 13, 2025 01:48
@rahxephon89 rahxephon89 marked this pull request as ready for review November 13, 2025 01:53
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Base automatically changed from teng/refactor-public-structs-remove-codegen to main November 13, 2025 04:21
@rahxephon89 rahxephon89 force-pushed the teng/file-format-gen branch 2 times, most recently from 2542c22 to 60805ed Compare November 14, 2025 18:12
@rahxephon89 rahxephon89 force-pushed the teng/file-format-gen branch 2 times, most recently from 6eb2d64 to e1a1542 Compare November 15, 2025 04:00
FF::Bytecode::Pack,
FF::Bytecode::PackGeneric,
);
}
Copy link

Choose a reason for hiding this comment

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

Bug: Pack: Unchecked Language Version Causes Errors

The Pack operation handler is missing a language version check. Unlike PackVariant (line 863), Unpack (line 914), and UnpackVariant (line 959), the regular Pack operation does not verify that language_version_for_public_struct() is enabled before attempting to use the pack API. This causes the code to attempt accessing pack APIs that were never generated when the language feature is disabled, leading to incorrect behavior or internal errors.

Fix in Cursor Fix in Web

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.

2 participants