Skip to content

Unstable rustc internal attribute to disable optimizations on a module/function basis #87801

Open
@wesleywiser

Description

@wesleywiser

Occasionally, it would be nice to use a debugger with rustc. However, currently the options generally available are to either compile with optimizations enabled which makes debugging difficult but the compiler performs reasonably or to disable optimizations which greatly increases the debugability but makes rustc unbearably slow in many situations.

It would be nice if we had the ability to to selectively disable optimizations at the function or module level via an attribute like #[rustc_optnone]. This would allow building most all of rustc with optimizations (thus retaining reasonable speed) while still allowing them to be disabled on a very small scale for the purpose of increased debugability.

Other compilers offer similar functionality:

  • clang: [[clang::optnone]]
  • gcc: __attribute__((optimize("O0")))
  • msvc: #pragma optimize( "", off )

For the LLVM backend, we would just need to adjust the functions' attributes to include optnone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.F-rustc_attrsInternal rustc attributes gated on the `#[rustc_attrs]` feature gate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions