Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixes
  • Loading branch information
JonasKruckenberg committed Jan 13, 2025
commit beeb370e6ce066c8165816d4f94f788f90e115ba
2 changes: 2 additions & 0 deletions cranelift/codegen/src/machinst/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ pub fn first_user_vreg_index() -> usize {
pub struct Reg(VReg);

impl Reg {
/// Create a register from a physical register
// FIXME(const-hack) remove in favor of `From` impl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say more here -- I'm not that familiar with the current state of constification of everything; is there some feature this is waiting on to stabilize or...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, the feature that would be waiting for is const associated functions in traits (therefore allowing From::from to be const) but that afaik is in "never type land". I can remove the note as it doesn't make much sense to hold our breath on it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that's best -- usually when we have a FIXME we want it to be actionable, or at least give sufficient context so that we know what we're waiting on (i.e.: if someone else walked up to this code tomorrow, would they know what they need in order to fix it?). It's fine to evaluate questions like this once new Rust features land in the future.

Copy link
Contributor Author

@JonasKruckenberg JonasKruckenberg Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue with constness is that theres no good way to detect constness workarounds after the fact (ie reevaluating code like this is tricky since it appears as just somewhat odd but regular code) which is the whole reason for the const-hack comments but usually you'd tie them to specific RFCs so yeah i agree getting rid of it is fine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant RFC fresh off the press: rust-lang/rfcs#3762

pub const fn from_preg(preg: PReg) -> Reg {
Reg(RealReg(preg).to_vreg())
}

/// Create a register from a virtual register
pub const fn from_vreg(vreg: VReg) -> Reg {
Reg(vreg)
}
Expand Down