Skip to content

const operands in asm! should use inline consts rather than const promotion #83169

Closed
@bstrie

Description

@bstrie

Elevating an item from the asm! progress report from a comment to an issue so that it can be tracked:


const operands should switch to using the new inline consts instead of explicit promotion. In theory this should have no impact on existing code, but it requires inline consts to support references to generic paramters of the surrounding function, which is not supported yet.

One aspect of asm! that I think needs further scrutiny before stabilization is const arguments, which currently are one of the few syntactic constructs that trigger promotion. Promotion is about turning a part of a function into an anonymous const (the "promoted") and using that instead of the ripped-out part of the function body. This has all sorts of "interesting" consequences (see e.g. rust-lang/rfcs#3027).

Similar to the situation for array repeat expressions in #49147, there is an alternative: we could avoid having to deal with promotion here by requiring that the const argument be either a literal (4), a named constant (CONST), or an explicit inline const (const { arbitrary_const_expr }). If that would be acceptable to y'all, I think it would be better to only support this subset upon initial stabilization. This is forward compatible with supporting more expressions by performing promotion later. The only difference this would make is one of convenience -- one could avoid having to type const { ... }.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)F-asm`#![feature(asm)]` (not `llvm_asm`)F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions