Skip to content

Codegen backend handles compare binops for the unit type #63551

Closed

Description

@bjorn3

mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt |
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => if is_unit {
bx.cx().const_bool(match op {
mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt => false,
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => true,
_ => unreachable!()
})

libcore however doesn't use those for the implementations for PartialEq and PartialOrd for the unit type.

rust/src/libcore/cmp.rs

Lines 933 to 939 in c43d03a

#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for () {
#[inline]
fn eq(&self, _other: &()) -> bool { true }
#[inline]
fn ne(&self, _other: &()) -> bool { false }
}

rust/src/libcore/cmp.rs

Lines 980 to 985 in c43d03a

impl PartialOrd for () {
#[inline]
fn partial_cmp(&self, _: &()) -> Option<Ordering> {
Some(Equal)
}
}

This means that the special case in cg_ssa can be removed.

Activity

  1. added
    A-codegenArea: Code generation
    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 14, 2019
  2. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-help-wantedCall for participation: Help is requested to fix this issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    on Aug 14, 2019
  3. punitkoura commented on Aug 14, 2019

    @punitkoura

    Hi @bjorn3 @Centril, I'd like to work on this. Would be a good initial contribution to Rust :)

  4. punitkoura commented on Aug 14, 2019

    @punitkoura

    I'm really new to the code base, though. Could you clarify what the cg_ssa means above?

  5. jonas-schievink commented on Aug 14, 2019

    @jonas-schievink
    Contributor

    Could you clarify what the cg_ssa means above?

    That's librustc_codegen_ssa, a part of the code generation code in rustc. The code in the first snippet is located there.

  6. punitkoura commented on Aug 15, 2019

    @punitkoura

    Thanks for clarifying that! I'll go through the code and post any questions here.

  7. TheOregonTrail commented on Aug 25, 2019

    @TheOregonTrail
    Contributor

    Would love to help but don't know where to start. If mentoring is still possible please ping me or send me in the right direction somehow 👍 . @bjorn3 @Centril

  8. TheOregonTrail commented on Aug 25, 2019

    @TheOregonTrail
    Contributor

    or maybe @jonas-schievink if your up to the task :)

  9. jonas-schievink commented on Aug 25, 2019

    @jonas-schievink
    Contributor

    @luigisHat I think you just need to look at src/librustc_codegen_ssa/mir/rvalue.rs and remove the check for is_unit that was mentioned. You can check https://rust-lang.github.io/rustc-guide/ for an overview of the compiler and instruction on how to build it and run tests.

  10. TheOregonTrail commented on Aug 25, 2019

    @TheOregonTrail
    Contributor

    @jonas-schievink Thanks seems to be a little simpler then I thought once I dug into the docs. Will do hope your having a good one 👍 .

  11. added a commit that references this issue on Sep 18, 2019
  12. added 2 commits that reference this issue on Oct 20, 2019
    6e875a9
    4f74fd7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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