Skip to content

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

@CAD97

Description

@CAD97

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsC-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions