FuelLabs / FuelLabs/sway

Allow use of `consts` in place of immediates in asm blocks

Open
#810 4 comments 1 reaction 0 assignees View on GitHub
compiler enhancement good first issue language feature P: low team:compiler
Dominant language
Rust
Stars
61.4k
Forks
5.4k
Avg merge
3h 33m
Merged PRs (30d)
4

Description

## Motivation
https://github.com/FuelLabs/sway-lib-std/pull/46
We should be able to directly use the `const` in the asm block if it is small enough to fit in that immediate size.

## Summary

Currently, immediates are size-checked in the compiler. If an opcode takes a 12-bit immediate, the size of that immediate is checked at compile time. Since we also know the value of `const`s at compile time, we should be able to directly allow the use of `const`s inside of `asm` blocks instead of passing them in. This will require a modification to the grammar and then size checking the const.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the linked sway-lib-std pull request and the compiler's asm grammar and immediate size-checking paths. Trace how compile-time const values are represented in asm, then verify that a const is accepted only when its value fits the opcode's immediate size.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.