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

BufReader: In Seek impl, remove extra discard_buffer call #61157

Merged

Conversation

Projects
None yet
5 participants
@czipperz
Copy link
Contributor

commented May 25, 2019

As far as I can tell, this code does nothing. I'm not sure why it even is there.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented May 25, 2019

r? @nikomatsakis

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

@czipperz

This comment has been minimized.

Copy link
Contributor Author

commented May 25, 2019

Since this will be peer reviewed, I might as well ask: should this refactored to not use a result variable? It would simplify the code but would require storing the pos and cap fields locally (discard_buffer resets them).

@czipperz

This comment has been minimized.

Copy link
Contributor Author

commented May 25, 2019

It seems this was introduced in the original implementation. It's been dead code for a while.

@taiki-e

This comment has been minimized.

Copy link
Contributor

commented May 25, 2019

I tried to do the same when I added async BufReader in futures-rs, but that was not correct (rust-lang-nursery/futures-rs#1573 (comment)).

There is no Pending in std::io, but there is a case to retry when ErrorKind::Interrupted is returned, so I think the same problem will occur when called in the order Ok - Err(ErrorKind::Interrupted).

@czipperz

This comment has been minimized.

Copy link
Contributor Author

commented May 25, 2019

Mmh so it's because of the ? on the next line. Shoot

@czipperz

This comment has been minimized.

Copy link
Contributor Author

commented May 25, 2019

I'm going to add try to add a test so this behavior is ensured.

@taiki-e

This comment has been minimized.

Copy link
Contributor

commented May 25, 2019

it's because of the ? on the next line.

Yeah, after early return with the next line's ? operator, enter the same branch again and call inner.seek(SeekFrom::Current(-remainder))?. Since we are calling inner.seek(SeekFrom::Current(-remainder)) twice at this point, the next line's inner.seek(SeekFrom::Current(n))? will seek the wrong position.

(If pos and cap are reset with discard_buffer, then remainder will be 0 at the next time, so it will not enter this branch.)

@czipperz czipperz force-pushed the czipperz:BufReader-Seek-remove-extra-discard_buffer branch from 26635b7 to f27ec0f May 25, 2019

@czipperz

This comment has been minimized.

Copy link
Contributor Author

commented May 25, 2019

Cool. I undid my commit and added a test that fails without that line.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented May 25, 2019

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:10dfcfe8:start=1558814688581140561,finish=1558814777780621821,duration=89199481260
$ 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
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
travis_time:start:test_codegen
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:19:51] 
[01:19:51] running 143 tests
[01:19:54] i..iii.....iii..iiii.....i......................i...i................i.....i..........ii.i..i..i.ii. 100/143
[01:19:55] test result: ok. 113 passed; 0 failed; 30 ignored; 0 measured; 0 filtered out
[01:19:55] 
[01:19:55]  finished in 4.598
[01:19:55] travis_fold:end:test_codegen
---
travis_time:start:test_assembly
Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:19:57] 
[01:19:57] running 9 tests
[01:19:57] iiiiiiiii
[01:19:57] 
[01:19:57]  finished in 0.149
[01:19:57] travis_fold:end:test_assembly

---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:20:13] 
[01:20:13] running 122 tests
[01:20:38] .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....i..........iiii..........i...ii...i.......ii.i 100/122
[01:20:43] .i.i......iii.i.....ii
[01:20:43] 
[01:20:43]  finished in 30.100
[01:20:43] travis_fold:end:test_debuginfo

---
[01:32:10] travis_fold:start:test_stage1-std
travis_time:start:test_stage1-std
Testing std stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:32:10]    Compiling std v0.0.0 (/checkout/src/libstd)
[01:32:31] error: function is never used: `test_buffered_reader_seek_underflow_discard_buffer_between_seeks`
[01:32:31]      |
[01:32:31]      |
[01:32:31] 1165 |     fn test_buffered_reader_seek_underflow_discard_buffer_between_seeks() {
[01:32:31]      |
[01:32:31]      = note: `-D dead-code` implied by `-D warnings`
[01:32:31] 
[01:32:32] error: aborting due to previous error
[01:32:32] error: aborting due to previous error
[01:32:32] 
[01:32:32] error: Could not compile `std`.
[01:32:32] 
[01:32:32] To learn more, run the command again with --verbose.
[01:32:32] 
[01:32:32] 
[01:32:32] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "std" "--" "--quiet"
[01:32:32] 
[01:32:32] 
[01:32:32] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:32:32] Build completed unsuccessfully in 0:24:34
[01:32:32] Build completed unsuccessfully in 0:24:34
[01:32:32] Makefile:48: recipe for target 'check' failed
[01:32:32] make: *** [check] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:1e28b616
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sat May 25 21:38:59 UTC 2019
---
travis_time:end:139bf697:start=1558820341431618849,finish=1558820341437339023,duration=5720174
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:240454ce
$ 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:0366f060
travis_time:start:0366f060
$ 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:0fca9e4c
$ 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)

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

commented May 28, 2019

@bors r+ rollup -- thanks!

@bors

This comment has been minimized.

Copy link
Contributor

commented May 28, 2019

📌 Commit b1ae49c has been approved by nikomatsakis

Centril added a commit to Centril/rust that referenced this pull request May 28, 2019

Rollup merge of rust-lang#61157 - czipperz:BufReader-Seek-remove-extr…
…a-discard_buffer, r=nikomatsakis

BufReader: In Seek impl, remove extra discard_buffer call

As far as I can tell, this code does nothing.  I'm not sure why it even is there.

bors added a commit that referenced this pull request May 28, 2019

Auto merge of #61289 - Centril:rollup-4ncstgj, r=Centril
Rollup of 6 pull requests

Successful merges:

 - #59625 (Refactor C FFI variadics to more closely match their C counterparts, and add Clone implementation)
 - #60756 (Add better tests for hidden lifetimes in impl trait)
 - #61024 (tests: Centralize proc macros commonly used for testing)
 - #61157 (BufReader: In Seek impl, remove extra discard_buffer call)
 - #61259 (Mailmap fixes)
 - #61273 (mention that MaybeUninit is a bit like Option)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request May 28, 2019

Rollup merge of rust-lang#61157 - czipperz:BufReader-Seek-remove-extr…
…a-discard_buffer, r=nikomatsakis

BufReader: In Seek impl, remove extra discard_buffer call

As far as I can tell, this code does nothing.  I'm not sure why it even is there.

Centril added a commit to Centril/rust that referenced this pull request May 28, 2019

Rollup merge of rust-lang#61157 - czipperz:BufReader-Seek-remove-extr…
…a-discard_buffer, r=nikomatsakis

BufReader: In Seek impl, remove extra discard_buffer call

As far as I can tell, this code does nothing.  I'm not sure why it even is there.

bors added a commit that referenced this pull request May 28, 2019

Auto merge of #61296 - Centril:rollup-5ad68b0, r=Centril
Rollup of 9 pull requests

Successful merges:

 - #60742 (Allow const parameters in array sizes to be unified)
 - #60756 (Add better tests for hidden lifetimes in impl trait)
 - #60928 (Changes the type `mir::Mir` into `mir::Body`)
 - #61024 (tests: Centralize proc macros commonly used for testing)
 - #61157 (BufReader: In Seek impl, remove extra discard_buffer call)
 - #61195 (Special-case `.llvm` in mangler)
 - #61202 (Print PermissionExt::mode() in octal in Documentation Examples)
 - #61259 (Mailmap fixes)
 - #61273 (mention that MaybeUninit is a bit like Option)

Failed merges:

r? @ghost

@bors bors merged commit b1ae49c into rust-lang:master May 29, 2019

1 check passed

Travis CI - Pull Request Build Passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.