Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding default codegen backend on a per-target basis #670

Closed
1 of 3 tasks
WaffleLapkin opened this issue Sep 4, 2023 · 3 comments
Closed
1 of 3 tasks
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@WaffleLapkin
Copy link
Member

WaffleLapkin commented Sep 4, 2023

Proposal

Add a field to TargetOptions, which allows overriding default codegen backend (CFG_DEFAULT_CODEGEN_BACKEND). Such that the priority for choosing codegen backend will be:

  • Explicit target passed to the compiler
  • Target default codegen backend (new!)
  • CFG_DEFAULT_CODEGEN_BACKEND env variable
  • "llvm"

This can be really helpful, given an exotic target that can only be compiled by a specific codegen backend. Full disclosure: at my {dayjob} we are working on a custom backend for rustc that supports an exotic target. This is something we'll add to our fork either way, but also would like to upstream.


This may not sound like a major thing, however, this creates a cyclic dependency because of target_override:

https://github.com/rust-lang/rust/blob/bf1e3f31f95c0f75b9bf51a58e8684f750f919f2/compiler/rustc_codegen_ssa/src/traits/backend.rs#L73-L76

So my current idea is to "iterate till fixpoint". Get a backend for the target, ask it for override, ask the target for backend override, ... and so on, untill the target stops changing. Note that in practice, it's unlikely that this will take more that 1 (0?) iterations, backends should return targets that either don't have an override or that have an override for the same backend.

Based on discussions in the zulip thread I've changed my opinion on this. It seems like forbidding target and backend to overwrite each other at the same time is a better idea, as it both simplifies the implementation/required changes and prevents surprising behavior.

Mentors or Reviewers

I'm planning to implement this; I don't have anyone in mind for reviews.

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@WaffleLapkin WaffleLapkin added T-compiler Add this label so rfcbot knows to poll the compiler team major-change A proposal to make a major change to rustc labels Sep 4, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 4, 2023

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

cc @rust-lang/compiler @rust-lang/compiler-contributors

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Sep 4, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Sep 7, 2023
@davidtwco
Copy link
Member

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Sep 20, 2023
@apiraino
Copy link
Contributor

apiraino commented Oct 2, 2023

@rustbot label -final-comment-period +major-change-accepted

@apiraino apiraino closed this as completed Oct 2, 2023
@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Oct 2, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Oct 12, 2023
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 7, 2024
…end, r=cjgillot

Allow targets to override default codegen backend

Implements rust-lang/compiler-team#670.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 11, 2024
…end, r=cjgillot

Allow targets to override default codegen backend

Implements rust-lang/compiler-team#670.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 11, 2024
Rollup merge of rust-lang#116793 - WaffleLapkin:target_rules_the_backend, r=cjgillot

Allow targets to override default codegen backend

Implements rust-lang/compiler-team#670.
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Mar 12, 2024
…gillot

Allow targets to override default codegen backend

Implements rust-lang/compiler-team#670.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants