Skip to content

Avoid some bounds checks in binary_heap::{PeekMut,Hole} - #58123

Merged
bors merged 1 commit into
rust-lang:masterfrom
lnicola:binary-heap-no-bounds-checks
Feb 7, 2019
Merged

Avoid some bounds checks in binary_heap::{PeekMut,Hole}#58123
bors merged 1 commit into
rust-lang:masterfrom
lnicola:binary-heap-no-bounds-checks

Conversation

@lnicola

Copy link
Copy Markdown
Member

Fixes#58121.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 3, 2019
@rust-highfive

Copy link
Copy Markdown
Contributor

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:015f1616:start=1549211516335855140,finish=1549211517361644809,duration=1025789669
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout
Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:04:43] Compiling rustc-demangle v0.1.10
[00:04:44] error[E0308]: mismatched types
[00:04:44] --> src/liballoc/collections/binary_heap.rs:876:36
[00:04:44] |
[00:04:44] 876 | elt: ManuallyDrop::new(elt),
[00:04:44] | ^^^ expected type parameter, found &T
[00:04:44] = note: expected type `T`
[00:04:44] found type `&T`
[00:04:44] [00:04:46] error: aborting due to previous error
---
[00:04:46] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:04:46] expected success, got: exit code: 101
[00:04:46] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:04:46] Build completed unsuccessfully in 0:00:37
[00:04:46] make: *** [all] Error 1
[00:04:46] Makefile:18: recipe for target 'all' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:099616bc
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun Feb 3 16:36:54 UTC 2019
---
travis_time:end:101f963a:start=1549211815336947275,finish=1549211815343399426,duration=6452151
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:2cdaf37c
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0da015a6
travis_time:start:0da015a6
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:106eb4a1
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@lnicola
lnicolaforce-pushed the binary-heap-no-bounds-checks branch from ed675f9 to ca7c8a9CompareFebruary 3, 2019 16:46
@rust-highfive

Copy link
Copy Markdown
Contributor

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:15a31ec2:start=1549212458035764223,finish=1549212458959316648,duration=923552425
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout
Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:04:38] Compiling rustc-demangle v0.1.10
[00:04:42] error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
[00:04:42] --> src/liballoc/collections/binary_heap.rs:262:11
[00:04:42] |
[00:04:42] 262 | { self.heap.data.get_unchecked_mut(0) }
[00:04:42] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
[00:04:42] |
[00:04:42] = note: consult the function's documentation for information on how to avoid undefined behavior
[00:04:42] error: aborting due to previous error
[00:04:42] [00:04:42] For more information about this error, try `rustc --explain E0133`.
[00:04:42] error: Could not compile `alloc`.
[00:04:42] error: Could not compile `alloc`.
[00:04:42] [00:04:42] To learn more, run the command again with --verbose.
[00:04:42] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:04:42] expected success, got: exit code: 101
[00:04:42] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:04:42] Build completed unsuccessfully in 0:00:42
[00:04:42] Makefile:18: recipe for target 'all' failed
[00:04:42] make: *** [all] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0f08d30b
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun Feb 3 16:52:32 UTC 2019

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@lnicola
lnicolaforce-pushed the binary-heap-no-bounds-checks branch from ca7c8a9 to 1b29a03CompareFebruary 3, 2019 16:53
@lnicola
lnicolaforce-pushed the binary-heap-no-bounds-checks branch from 1b29a03 to ea72066CompareFebruary 3, 2019 18:38
@lnicola

lnicola commented Feb 3, 2019

Copy link
Copy Markdown
MemberAuthor

test code

use std::collections::BinaryHeap;#[no_mangle]pubexternfnis_opt(heap:&mutBinaryHeap<u32>) -> bool{ifletSome(mut peek) = heap.peek_mut(){*peek = 1;true}else{false}}

before

Details
	.text	.file	"peekmut.71651wce-cgu.0"	.section	.text._ZN4core3ptr18real_drop_in_place17hb6242b27b5771784E,"ax",@progbits	.p2align	4,0x90	.type	_ZN4core3ptr18real_drop_in_place17hb6242b27b5771784E,@function_ZN4core3ptr18real_drop_in_place17hb6242b27b5771784E:	.cfi_startproc	pushq	%rax	.cfi_def_cfa_offset 16	cmpb$0,8(%rdi)je	.LBB0_12movq	(%rdi), %raxmovq16(%rax), %r9	testq	%r9, %r9je	.LBB0_13movq	(%rax), %rax	movl	(%rax), %r8d	cmpq$1, %r9jne	.LBB0_4	xorl	%esi, %esijmp	.LBB0_11.LBB0_4:	movl$1, %edi	xorl	%ecx, %ecx	.p2align	4,0x90.LBB0_5:	leaq	1(%rdi), %rsi	cmpq	%r9, %rsijae	.LBB0_8	movl	(%rax,%rdi,4), %edx	cmpl	4(%rax,%rdi,4), %edxja	.LBB0_8movq	%rsi, %rdi.LBB0_8:movq	%rdi, %rsi	movl	(%rax,%rdi,4), %edi	cmpl	%edi, %r8djae	.LBB0_9	movl	%edi, (%rax,%rcx,4)	leaq	(%rsi,%rsi), %rdi	addq$1, %rdimovq	%rsi, %rcx	cmpq	%r9, %rdijb	.LBB0_5jmp	.LBB0_11.LBB0_9:movq	%rcx, %rsi.LBB0_11:	movl	%r8d, (%rax,%rsi,4).LBB0_12:	popq	%rax	.cfi_def_cfa_offset 8	retq.LBB0_13:	.cfi_def_cfa_offset 16	leaq	.L__unnamed_1(%rip), %rdi	xorl	%esi, %esi	xorl	%edx, %edx	callq	*_ZN4core9panicking18panic_bounds_check17h59684c930baf7d8bE@GOTPCREL(%rip)ud2.Lfunc_end0:	.size	_ZN4core3ptr18real_drop_in_place17hb6242b27b5771784E, .Lfunc_end0-_ZN4core3ptr18real_drop_in_place17hb6242b27b5771784E	.cfi_endproc	.section	.text.is_opt,"ax",@progbits	.globl	is_opt	.p2align	4,0x90	.type	is_opt,@functionis_opt:.Lfunc_begin0:	.cfi_startproc	.cfi_personality 155, DW.ref.rust_eh_personality	.cfi_lsda 27, .Lexception0	subq$24, %rsp	.cfi_def_cfa_offset 32	cmpq$0,16(%rdi)je	.LBB1_18movq	%rdi,8(%rsp)	movb$1,16(%rsp)	cmpq$0,16(%rdi)je	.LBB1_2movq	(%rdi), %rax	movl$1, (%rax)movq16(%rdi), %r9	testq	%r9, %r9je	.LBB1_6movq	(%rdi), %rax	movl	(%rax), %r8d	cmpq$1, %r9jne	.LBB1_9	xorl	%esi, %esijmp	.LBB1_16.LBB1_18:	xorl	%ecx, %ecx	movl	%ecx, %eax	addq$24, %rsp	.cfi_def_cfa_offset 8	retq.LBB1_9:	.cfi_def_cfa_offset 32	movl$1, %edi	xorl	%ecx, %ecx	.p2align	4,0x90.LBB1_10:	leaq	1(%rdi), %rsi	cmpq	%r9, %rsijae	.LBB1_13	movl	(%rax,%rdi,4), %edx	cmpl	4(%rax,%rdi,4), %edxja	.LBB1_13movq	%rsi, %rdi.LBB1_13:movq	%rdi, %rsi	movl	(%rax,%rdi,4), %edi	cmpl	%edi, %r8djae	.LBB1_14	movl	%edi, (%rax,%rcx,4)	leaq	(%rsi,%rsi), %rdi	addq$1, %rdimovq	%rsi, %rcx	cmpq	%r9, %rdijb	.LBB1_10jmp	.LBB1_16.LBB1_14:movq	%rcx, %rsi.LBB1_16:	movl	%r8d, (%rax,%rsi,4)	movb$1, %cl	movl	%ecx, %eax	addq$24, %rsp	.cfi_def_cfa_offset 8	retq.LBB1_2:	.cfi_def_cfa_offset 32.Ltmp3:	leaq	.L__unnamed_2(%rip), %rdi	xorl	%esi, %esi	xorl	%edx, %edx	callq	*_ZN4core9panicking18panic_bounds_check17h59684c930baf7d8bE@GOTPCREL(%rip).Ltmp4:jmp	.LBB1_3.LBB1_6:.Ltmp0:	leaq	.L__unnamed_1(%rip), %rdi	xorl	%esi, %esi	xorl	%edx, %edx	callq	*_ZN4core9panicking18panic_bounds_check17h59684c930baf7d8bE@GOTPCREL(%rip).Ltmp1:.LBB1_3:ud2.LBB1_4:.Ltmp2:ud2ud2.LBB1_19:.Ltmp5:	leaq	8(%rsp), %rdi	callq	_ZN4core3ptr18real_drop_in_place17hb6242b27b5771784Eud2ud2.Lfunc_end1:	.size	is_opt, .Lfunc_end1-is_opt	.cfi_endproc	.section	.gcc_except_table,"a",@progbits	.p2align	2GCC_except_table1:.Lexception0:	.byte255	.byte255	.byte1	.uleb128 .Lcst_end0-.Lcst_begin0.Lcst_begin0:	.uleb128 .Ltmp3-.Lfunc_begin0	.uleb128 .Ltmp4-.Ltmp3	.uleb128 .Ltmp5-.Lfunc_begin0	.byte0	.uleb128 .Ltmp0-.Lfunc_begin0	.uleb128 .Ltmp1-.Ltmp0	.uleb128 .Ltmp2-.Lfunc_begin0	.byte0	.uleb128 .Ltmp1-.Lfunc_begin0	.uleb128 .Lfunc_end1-.Ltmp1	.byte0	.byte0.Lcst_end0:	.p2align	2	.type	str.0,@object	.section	.rodata.str.0,"a",@progbits	.p2align	4str.0:	.ascii	"/rustc/8a57831a4b7dfa960110599748f3b7382ae28237/src/libcore/slice/mod.rs"	.size	str.0,72	.type	.L__unnamed_2,@object	.section	.data.rel.ro..L__unnamed_2,"aw",@progbits	.p2align	3.L__unnamed_2:	.quad	str.0	.quad	72	.long	2541	.long	14	.size	.L__unnamed_2,24	.type	str.1,@object	.section	.rodata.str.1,"a",@progbits	.p2align	4str.1:	.ascii	"/rustc/8a57831a4b7dfa960110599748f3b7382ae28237/src/liballoc/collections/binary_heap.rs"	.size	str.1,87	.type	.L__unnamed_1,@object	.section	.data.rel.ro..L__unnamed_1,"aw",@progbits	.p2align	3.L__unnamed_1:	.quad	str.1	.quad	87	.long	868	.long	30	.size	.L__unnamed_1,24	.hidden	DW.ref.rust_eh_personality	.weak	DW.ref.rust_eh_personality	.section	.data.DW.ref.rust_eh_personality,"aGw",@progbits,DW.ref.rust_eh_personality,comdat	.p2align	3	.type	DW.ref.rust_eh_personality,@object	.size	DW.ref.rust_eh_personality,8DW.ref.rust_eh_personality:	.quad	rust_eh_personality	.section".note.GNU-stack","",@progbits

after

Details
	.text	.file	"peekmut.71651wce-cgu.0"	.section	.text.is_opt,"ax",@progbits	.globl	is_opt	.p2align	4,0x90	.type	is_opt,@functionis_opt:	.cfi_startproc	cmpq$0,16(%rdi)je	.LBB0_1movq	(%rdi), %rax	movl$1, (%rax)movq16(%rdi), %r9	movb$1, %al	cmpq$2, %r9jb	.LBB0_11movq	(%rdi), %r10	movl	(%r10), %r8d	movl$1, %esi	xorl	%edx, %edx	.p2align	4,0x90.LBB0_4:	leaq	1(%rsi), %rdi	cmpq	%r9, %rdijae	.LBB0_7	movl	(%r10,%rsi,4), %ecx	cmpl	4(%r10,%rsi,4), %ecxja	.LBB0_7movq	%rdi, %rsi.LBB0_7:movq	%rsi, %rdi	movl	(%r10,%rsi,4), %esi	cmpl	%esi, %r8djae	.LBB0_8	movl	%esi, (%r10,%rdx,4)	leaq	(%rdi,%rdi), %rsi	addq$1, %rsimovq	%rdi, %rdx	cmpq	%r9, %rsijb	.LBB0_4jmp	.LBB0_10.LBB0_1:	xorl	%eax, %eax	retq.LBB0_8:movq	%rdx, %rdi.LBB0_10:	movl	%r8d, (%r10,%rdi,4).LBB0_11:	retq.Lfunc_end0:	.size	is_opt, .Lfunc_end0-is_opt	.cfi_endproc	.section".note.GNU-stack","",@progbits

@sfackler

Copy link
Copy Markdown
Member

@bors r+

Thanks!

@bors

bors commented Feb 4, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit ea72066 has been approved by sfackler

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 4, 2019
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors rollup

kennytm added a commit to kennytm/rust that referenced this pull request Feb 7, 2019
…s, r=sfackler
Avoid some bounds checks in binary_heap::{PeekMut,Hole}
Fixesrust-lang#58121.
@kennytmkennytm mentioned this pull request Feb 7, 2019
bors added a commit that referenced this pull request Feb 7, 2019
Rollup of 23 pull requests
Successful merges:
- #58118 (Transition libtest to 2018 edition)
- #58119 (libproc_macro => 2018)
- #58123 (Avoid some bounds checks in binary_heap::{PeekMut,Hole})
- #58124 (libsyntax_pos => 2018)
- #58133 (libsyntax_ext => 2018)
- #58136 (Improve error message and docs for non-UTF-8 bytes in stdio on Windows)
- #58156 (update submodule: rust-installer from 27dec6c to ccdc47b)
- #58192 (Do not ICE in codegen when using a extern_type static)
- #58193 (Move librustc to 2018)
- #58210 (Make an assert debug-only in `find_constraint_paths_between_regions`.)
- #58217 (librustc_tsan => 2018)
- #58218 (librustc_msan => 2018)
- #58219 (librustc_asan => 2018)
- #58220 (libprofiler_builtins => 2018)
- #58223 (librustc_lsan => 2018)
- #58225 (librustc_fs_util => 2018)
- #58228 (librustc_plugin => 2018)
- #58236 (librustc_resolve => 2018)
- #58237 (Fix broken grammar in iter::from_fn() docs)
- #58239 (librustc_apfloat => 2018)
- #58240 (librustc_errors => 2018)
- #58241 (librustc_llvm => 2018)
- #58242 (Document the one TyKind that isn't documented)
Failed merges:
- #58185 (Remove images' url to make it work even without internet connection)
r? @ghost
@bors
bors merged commit ea72066 into rust-lang:masterFeb 7, 2019
@lnicola
lnicola deleted the binary-heap-no-bounds-checks branch December 11, 2024 09:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@lnicola@rust-highfive@sfackler@bors@Mark-Simulacrum