Skip to content

Conversation

@tritao
Copy link
Contributor

@tritao tritao commented Jun 28, 2025

Description

  • Bump the toolchain to fuel-abi-types 0.16 and point every fuels-* dependency at the matching branch so codegen and tests consume the alias-aware ABI schema (Cargo.toml:82, Cargo.toml:264).

  • Restructure the Fuel ABI emitter so both metadata and concrete type declarations share the same builders and run through AbiContext caches, preventing duplicate structs/enums in the serialized ABI (sway-core/src/abi_generation/fuel_abi.rs:42).

  • Plumb the experimental abi_type_aliases toggle from forc-pkg into ABI string generation and metadata collection so alias names survive resolution without being classified as generics (forc-pkg/src/pkg.rs:1811, sway-features/src/lib.rs:173, sway-core/src/type_system/id.rs:266, sway-core/src/types/collect_types_metadata.rs:128).

  • Teach TypeInfo::Alias to either inline or preserve the alias name depending on the feature, and add validation so ABI names remain unique/valid before being emitted (sway-core/src/abi_generation/abi_str.rs:11, sway-core/src/abi_generation/fuel_abi.rs:167).

  • Add an abi_with_alias_experimental contract plus oracle JSONs for both encoding modes to lock in the expected output while the feature flag is on (test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/abi_with_alias_experimental/Forc.toml:1), along with snapshot tweaks where alias strings changed (test/src/e2e_vm_tests/test_programs/should_fail/attributes_invalid_args/stdout.snap:1).

Commits

Fixes #6564.

There is a matching PR for Rust SDK support at: FuelLabs/fuels-rs#1677

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

Note

Introduce an experimental abi_type_aliases feature and refactor ABI emission to preserve type aliases with caching/dedup, updating deps and tests accordingly.

  • Compiler/ABI generation (Fuel):
    • Preserve type aliases in ABI when experimental.abi_type_aliases is enabled; emit aliasOf links and keep alias names in type strings.
    • Refactor ABI builders to share logic and add caches for metadata and concrete declarations; deduplicate types and standardize IDs.
    • Update generic detection and ABI string rendering to respect aliases; handle hashing/name validation; add full dealiasing for targets.
  • Forc/Plumbing:
    • Thread abi_type_aliases through forc and metadata collection (logs/panic), enabling alias-aware JSON generation.
  • Features/Docs:
    • Add abi_type_aliases experimental feature (incl. #[cfg] support) and document it in the book.
  • Dependencies:
    • Bump to fuel-abi-types 0.16; patch fuels-* crates to matching branch.
  • Tests:
    • Add contracts validating alias-preserving ABI for both encoding modes; update snapshots (e.g., cfg help) and ABI oracles.

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

@tritao tritao self-assigned this Jun 28, 2025
@tritao tritao added compiler General compiler. Should eventually become more specific as the issue is triaged ABI Everything to do the ABI, especially the JSON representation compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Jun 28, 2025
@tritao tritao force-pushed the abi-aliased-types branch from 1a6a2fb to 5989ba2 Compare June 28, 2025 21:20
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 1, 2025

CodSpeed Performance Report

Merging #7261 will not alter performance

Comparing tritao:abi-aliased-types (1f39f64) with master (886becb)

Summary

✅ 25 untouched

@tritao tritao force-pushed the abi-aliased-types branch from f0d3478 to 66db5dc Compare October 14, 2025 14:50
@tritao tritao force-pushed the abi-aliased-types branch from 66db5dc to e565e43 Compare October 16, 2025 15:43
@tritao tritao force-pushed the abi-aliased-types branch from e565e43 to 75d1794 Compare October 18, 2025 13:33
@tritao tritao force-pushed the abi-aliased-types branch from 75d1794 to b7251ef Compare October 20, 2025 08:25
@tritao tritao force-pushed the abi-aliased-types branch from b7251ef to 909004a Compare October 20, 2025 08:27
@tritao tritao force-pushed the abi-aliased-types branch from 909004a to 3be6772 Compare October 26, 2025 22:15
@tritao tritao force-pushed the abi-aliased-types branch from 3be6772 to 4880b44 Compare October 26, 2025 22:16
@tritao tritao force-pushed the abi-aliased-types branch from 4880b44 to 136282a Compare November 2, 2025 22:11
@tritao tritao marked this pull request as ready for review November 12, 2025 13:12
@tritao tritao requested review from a team as code owners November 12, 2025 13:12
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.

Bug: Array Type ID Inconsistency Causes ABI Errors

Array element type IDs use raw initial_type_id.index() instead of the metadata ID from the generated declaration. This is inconsistent with the refactoring applied to enum variants, struct fields, and tuple elements, and can produce incorrect type IDs in the ABI JSON when type caching is enabled, potentially causing type ID mismatches or references to non-existent metadata types.

sway-core/src/abi_generation/fuel_abi.rs#L1268-L1283

// `program_abi::TypeApplication` for the array element type
Some(vec![program_abi::TypeApplication {
name: "__array_element".to_string(),
type_id: program_abi::TypeId::Metadata(MetadataTypeId(
elem_ty.initial_type_id.index(),
)),
error_message: None,
type_arguments: elem_ty.initial_type_id.get_abi_type_arguments(
handler,
ctx,
engines,
metadata_types,
concrete_types,
elem_ty.type_id,
metadata_types_to_add,
)?,

Fix in Cursor Fix in Web


Bug: Resolve Slice Type ID Metadata Inconsistency

Slice element type IDs use raw initial_type_id.index() instead of the metadata ID from the generated declaration. This is inconsistent with the refactoring applied to enum variants, struct fields, and tuple elements, and can produce incorrect type IDs in the ABI JSON when type caching is enabled, potentially causing type ID mismatches or references to non-existent metadata types.

sway-core/src/abi_generation/fuel_abi.rs#L1304-L1319

// `program_abi::TypeApplication` for the array element type
Some(vec![program_abi::TypeApplication {
name: "__slice_element".to_string(),
type_id: program_abi::TypeId::Metadata(MetadataTypeId(
elem_ty.initial_type_id.index(),
)),
error_message: None,
type_arguments: elem_ty.initial_type_id.get_abi_type_arguments(
handler,
ctx,
engines,
metadata_types,
concrete_types,
elem_ty.type_id,
metadata_types_to_add,
)?,

Fix in Cursor Fix in Web


@@ -2723,7 +2724,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d162beedaa69905488a8da94f5ac3edb4dd4788b732fadb7bd120b2625c1976"
dependencies = [
"data-encoding",
"syn 2.0.106",
"syn 1.0.109",
Copy link

Choose a reason for hiding this comment

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

Bug: Dependency Version Mismatch Threatens Stability.

The data-encoding-macro-internal dependency downgrades from syn 2.0.106 to syn 1.0.109, which is a major version regression. This is inconsistent with the rest of the codebase where syn is being upgraded to 2.0.109, and could cause compilation failures or API incompatibilities since syn 1.x and 2.x have breaking changes between them.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was done by the resolve step of cargo update itself so not sure if it should be touched.

@tritao
Copy link
Contributor Author

tritao commented Nov 12, 2025

The issues being flagged by the review bot are from pre-existing code that I've not touched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ABI Everything to do the ABI, especially the JSON representation compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type alias name is missing in types

2 participants