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

vec![].into_boxed_slice includes extraneous panicking code #73152

Closed
CAD97 opened this issue Jun 8, 2020 · 1 comment
Closed

vec![].into_boxed_slice includes extraneous panicking code #73152

CAD97 opened this issue Jun 8, 2020 · 1 comment
Labels
A-allocators Area: Custom and system allocators C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Jun 8, 2020

This is a stable-to-stable regression between 1.43 and 1.44. Likely to do with allocator parametricity.

godbolt

pub fn new_boxed_slice(len: usize) -> Box<[u8]> {
    vec![0; len].into_boxed_slice()
}

1.43

example::new_boxed_slice:
        push    rbx
        mov     rbx, rdi
        test    rdi, rdi
        je      .LBB0_1
        mov     esi, 1
        mov     rdi, rbx
        call    qword ptr [rip + __rust_alloc_zeroed@GOTPCREL]
        test    rax, rax
        je      .LBB0_4
        mov     rdx, rbx
        pop     rbx
        ret
.LBB0_1:
        mov     eax, 1
        mov     rdx, rbx
        pop     rbx
        ret
.LBB0_4:
        mov     esi, 1
        mov     rdi, rbx
        call    qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
        ud2

1.44

core::ptr::drop_in_place:
        mov     rax, rdi
        mov     rdi, qword ptr [rdi]
        test    rdi, rdi
        je      .LBB0_2
        mov     rsi, qword ptr [rax + 8]
        test    rsi, rsi
        je      .LBB0_2
        mov     edx, 1
        jmp     qword ptr [rip + __rust_dealloc@GOTPCREL]
.LBB0_2:
        ret

alloc::raw_vec::RawVec<T,A>::allocate_in::{{closure}}:
        push    rax
        call    qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
        ud2

example::new_boxed_slice:
        push    rbx
        sub     rsp, 32
        mov     rbx, rdi
        test    rdi, rdi
        je      .LBB2_1
        mov     esi, 1
        mov     rdi, rbx
        call    qword ptr [rip + __rust_alloc_zeroed@GOTPCREL]
        test    rax, rax
        je      .LBB2_17
        mov     rsi, rbx
        jmp     .LBB2_4
.LBB2_1:
        mov     eax, 1
        xor     esi, esi
.LBB2_4:
        mov     qword ptr [rsp + 8], rax
        mov     qword ptr [rsp + 16], rsi
        mov     qword ptr [rsp + 24], rbx
        cmp     rsi, rbx
        je      .LBB2_14
        jb      .LBB2_10
        test    rsi, rsi
        je      .LBB2_14
        test    rax, rax
        je      .LBB2_14
        mov     edx, 1
        mov     rdi, rax
        test    rbx, rbx
        je      .LBB2_9
        mov     rcx, rbx
        call    qword ptr [rip + __rust_realloc@GOTPCREL]
        test    rax, rax
        jne     .LBB2_13
        mov     esi, 1
        mov     rdi, rbx
        call    qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
        ud2
.LBB2_9:
        call    qword ptr [rip + __rust_dealloc@GOTPCREL]
        mov     eax, 1
.LBB2_13:
        mov     qword ptr [rsp + 8], rax
        mov     qword ptr [rsp + 16], rbx
.LBB2_14:
        mov     rdx, rbx
        add     rsp, 32
        pop     rbx
        ret
.LBB2_17:
        mov     esi, 1
        mov     rdi, rbx
        call    alloc::raw_vec::RawVec<T,A>::allocate_in::{{closure}}
        ud2
.LBB2_10:
        lea     rdi, [rip + .L__unnamed_1]
        lea     rdx, [rip + .L__unnamed_2]
        mov     esi, 36
        call    qword ptr [rip + core::panicking::panic@GOTPCREL]
        ud2
        mov     rbx, rax
        lea     rdi, [rsp + 8]
        call    core::ptr::drop_in_place
        mov     rdi, rbx
        call    _Unwind_Resume@PLT
        ud2

.L__unnamed_1:
        .ascii  "Tried to shrink to a larger capacity"

.L__unnamed_3:
        .ascii  "/rustc/49cae55760da0a43428eba73abcb659bb70cf2e4/src/libcore/macros/mod.rs"

.L__unnamed_2:
        .quad   .L__unnamed_3
        .asciz  "I\000\000\000\000\000\000\000\"\000\000\000\t\000\000"

DW.ref.rust_eh_personality:
        .quad   rust_eh_personality
@CAD97 CAD97 added the C-bug Category: This is a bug. label Jun 8, 2020
@jonas-schievink jonas-schievink added A-allocators Area: Custom and system allocators I-slow Issue: Problems and improvements with respect to performance of generated code. T-libs Relevant to the library team, which will review and decide on the PR/issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Jun 8, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 8, 2020
@ollie27
Copy link
Member

ollie27 commented Jun 8, 2020

Duplicate of #71861

@ollie27 ollie27 marked this as a duplicate of #71861 Jun 8, 2020
@ollie27 ollie27 closed this as completed Jun 8, 2020
@Dylan-DPC-zz Dylan-DPC-zz removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-allocators Area: Custom and system allocators C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants