Skip to content

Conversation

@xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Nov 4, 2025

Description

This PR forbids "const generics" on abis. The reason is that to correctly support it, we will need to introduce changes to the ABI json.

This will be reserved to the future.

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

Disallows const generics in ABI method parameters/returns (including nested forms), adjusts type substitution to ignore const params, and adds failing tests to validate.

  • ABI/type checking:
    • Add has_const_generics(..) to detect const generics in TypeInfo (including arrays/strings, nested structs/enums/tuples).
    • Enforce via TyAbiDecl::forbid_const_generics(..) emitting CompileError::ConstGenericNotSupportedHere for ABI interface fn params/returns and implementation items.
    • Invoke the check after constructing ty::TyAbiDecl in sway-core/src/semantic_analysis/ast_node/declaration/abi.rs.
  • Type substitution:
    • In TypeSubstMap::from_superset_and_subset for Enum/Struct, use filter_map(|x| x.as_type_parameter()) so only type parameters participate in substitution (ignores const params).
  • Tests:
    • Add should_fail/unsupported_const_generics with ABIs using const generics directly and via nested types; update snapshots and project files to expect errors.

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

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 4, 2025

CodSpeed Performance Report

Merging #7483 will not alter performance

Comparing xunilrj/forbid-const-generics-on-abis (1bf3210) with master (886becb)

Summary

✅ 25 untouched

@xunilrj xunilrj self-assigned this Nov 4, 2025
@xunilrj xunilrj marked this pull request as ready for review November 4, 2025 22:54
@xunilrj xunilrj requested a review from a team as a code owner November 4, 2025 22:54
@xunilrj xunilrj requested a review from a team November 5, 2025 09:42
@xunilrj xunilrj force-pushed the xunilrj/forbid-const-generics-on-abis branch from 8234416 to 1bf3210 Compare November 12, 2025 16:59
@xunilrj xunilrj enabled auto-merge (squash) November 12, 2025 17:00
@xunilrj xunilrj merged commit fb10b2f into master Nov 12, 2025
47 checks passed
@xunilrj xunilrj deleted the xunilrj/forbid-const-generics-on-abis branch November 12, 2025 17:16
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.

4 participants