Closed
Description
The assembly generated in debug builds (-C opt-level=0) worsened for this code that uses an associated constant from a trait.This seems to be caused by the fact that the function is generic,even though the associated constant doesn't depend on the generic parameters of the function.
trait NeedsDrop:Sized{
const NEEDS:bool=std::mem::needs_drop::<Self>();
}
impl<This> NeedsDrop for This{}
pub fn hello<T>(){
if <bool>::NEEDS {
panic!()
}
}
pub fn hi(){
hello::<()>();
hello::<Vec<()>>();
}
The entirety of the generated assembly for stable 1.41.0 in a debug build:
playground::hello:
retq
playground::hello:
retq
playground::hi:
pushq %rax
callq *playground::hello@GOTPCREL(%rip)
callq *playground::hello@GOTPCREL(%rip)
popq %rax
retq
The assembly generated for the same functions by rustc 1.42.0-beta.2 (2020-02-04 3d2613e) in a debug build:
playground::hello:
pushq %rax
xorl %eax, %eax
testb $1, %al
jne .LBB45_2
jmp .LBB45_1
.LBB45_1:
popq %rax
retq
.LBB45_2:
leaq .Lanon.257b63aea292a17f4811b89c35bea688.2(%rip), %rdi
leaq .Lanon.257b63aea292a17f4811b89c35bea688.4(%rip), %rdx
movq std::panicking::begin_panic@GOTPCREL(%rip), %rax
movl $14, %esi
callq *%rax
ud2
playground::hello:
pushq %rax
xorl %eax, %eax
testb $1, %al
jne .LBB46_2
jmp .LBB46_1
.LBB46_1:
popq %rax
retq
.LBB46_2:
leaq .Lanon.257b63aea292a17f4811b89c35bea688.2(%rip), %rdi
leaq .Lanon.257b63aea292a17f4811b89c35bea688.4(%rip), %rdx
movq std::panicking::begin_panic@GOTPCREL(%rip), %rax
movl $14, %esi
callq *%rax
ud2
playground::hi:
pushq %rax
callq *playground::hello@GOTPCREL(%rip)
callq *playground::hello@GOTPCREL(%rip)
popq %rax
retq
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Constant evaluation, covers all const contexts (static, const fn, ...)Issue: Problems and improvements with respect to performance of generated code.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from stable to beta.