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

Add impl AddAssign<char> for Cow<'_, str> #66215

Closed

Conversation

Ruster-a11y
Copy link

@Ruster-a11y Ruster-a11y commented Nov 8, 2019

There are two obvious ways to append a char to a String:

  1. String.push(char)
  2. String += &(char.to_string())

The second way is almost 3x slower for up to 1000 iterations and slows down much further when the iteration count increases.

Since the second way might be preferred by some due to the legibility of += operator -- an AddAssign<char> implementation for String makes sense without losing the speed benefits of String.push(char)

With this addition, the second way could be reconstructed simply as:

  • String += char

Edit:

The following operation is also possible now:

  • new_string = old_string + char

Update:

This PR has now been relegated to just an implementation for impl AddAssign<char> for Cow<'_, str>. Further commits will ensure the PR code only effects/improves upon the said implementation.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cramertj (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 8, 2019
@Ruster-a11y
Copy link
Author

@Centril Please see.

src/liballoc/borrow.rs Outdated Show resolved Hide resolved
src/liballoc/borrow.rs Outdated Show resolved Hide resolved
@Centril Centril added relnotes Marks issues that should be documented in the release notes of the next release. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 8, 2019
@Centril Centril added this to the 1.41 milestone Nov 8, 2019
@Centril
Copy link
Contributor

Centril commented Nov 8, 2019

r? @dtolnay cc @rust-lang/libs

@rust-highfive rust-highfive assigned dtolnay and unassigned cramertj Nov 8, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, 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.
2019-11-08T09:58:19.1118197Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-08T09:58:19.1319127Z ##[command]git config gc.auto 0
2019-11-08T09:58:19.1409028Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-08T09:58:19.1458387Z ##[command]git config --get-all http.proxy
2019-11-08T09:58:19.1614398Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66215/merge:refs/remotes/pull/66215/merge
---
2019-11-08T10:04:54.3243165Z Found 0 error codes with no tests
2019-11-08T10:04:54.3243424Z Done!
2019-11-08T10:04:54.3243618Z 
2019-11-08T10:04:54.3243793Z 
2019-11-08T10:04:54.3250513Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-11-08T10:04:54.3252881Z 
2019-11-08T10:04:54.3253042Z 
2019-11-08T10:04:54.3253473Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-11-08T10:04:54.3253686Z Build completed unsuccessfully in 0:01:36
2019-11-08T10:04:54.3253686Z Build completed unsuccessfully in 0:01:36
2019-11-08T10:04:54.3297647Z == clock drift check ==
2019-11-08T10:04:54.3307422Z   local time: Fri Nov  8 10:04:54 UTC 2019
2019-11-08T10:04:54.8627627Z   network time: Fri, 08 Nov 2019 10:04:54 GMT
2019-11-08T10:04:54.8629826Z == end clock drift check ==
2019-11-08T10:04:56.1419578Z 
2019-11-08T10:04:56.1532210Z ##[error]Bash exited with code '1'.
2019-11-08T10:04:56.1561155Z ##[section]Starting: Checkout
2019-11-08T10:04:56.1563018Z ==============================================================================
2019-11-08T10:04:56.1563099Z Task         : Get sources
2019-11-08T10:04:56.1563152Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@Centril Centril changed the title Added AddAssign<char> implementation for String Add impl AddAssign<char> for Cow<'_, str> Nov 8, 2019
@Centril
Copy link
Contributor

Centril commented Nov 8, 2019

@Ruster-a11y I would also recommend amending the PR description to describe the use case & motivation for this change.

@Ruster-a11y
Copy link
Author

@Centril On it. Thanks again!

src/liballoc/borrow.rs Outdated Show resolved Hide resolved
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, 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.
2019-11-08T18:25:08.3330577Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-08T18:25:08.3530501Z ##[command]git config gc.auto 0
2019-11-08T18:25:08.3603780Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-08T18:25:08.3665899Z ##[command]git config --get-all http.proxy
2019-11-08T18:25:08.3807412Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66215/merge:refs/remotes/pull/66215/merge
---
2019-11-08T18:31:41.4826085Z Found 0 error codes with no tests
2019-11-08T18:31:41.4826479Z Done!
2019-11-08T18:31:41.4826587Z 
2019-11-08T18:31:41.4826621Z 
2019-11-08T18:31:41.4827598Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-11-08T18:31:41.4827720Z 
2019-11-08T18:31:41.4827749Z 
2019-11-08T18:31:41.4836635Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-11-08T18:31:41.4836745Z Build completed unsuccessfully in 0:01:35
2019-11-08T18:31:41.4836745Z Build completed unsuccessfully in 0:01:35
2019-11-08T18:31:41.4891257Z == clock drift check ==
2019-11-08T18:31:41.4903430Z   local time: Fri Nov  8 18:31:41 UTC 2019
2019-11-08T18:31:41.5609387Z   network time: Fri, 08 Nov 2019 18:31:41 GMT
2019-11-08T18:31:41.5643360Z == end clock drift check ==
2019-11-08T18:31:42.8266573Z 
2019-11-08T18:31:42.8373886Z ##[error]Bash exited with code '1'.
2019-11-08T18:31:42.8405784Z ##[section]Starting: Checkout
2019-11-08T18:31:42.8408934Z ==============================================================================
2019-11-08T18:31:42.8408998Z Task         : Get sources
2019-11-08T18:31:42.8409070Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused about the PR description. It mentions String += char but this impl is for Cow<str>?

src/liballoc/borrow.rs Show resolved Hide resolved
src/liballoc/borrow.rs Outdated Show resolved Hide resolved
src/liballoc/borrow.rs Outdated Show resolved Hide resolved
…w<str>`.

Added `impl Add<char> for String` to ascertain logical parity.
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, 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.
2019-11-08T21:49:15.9833787Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-08T21:49:16.0060228Z ##[command]git config gc.auto 0
2019-11-08T21:49:16.0133713Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-08T21:49:16.0222883Z ##[command]git config --get-all http.proxy
2019-11-08T21:49:16.0398919Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66215/merge:refs/remotes/pull/66215/merge
---
2019-11-08T21:55:50.6199468Z    Compiling serde_json v1.0.40
2019-11-08T21:55:52.5706216Z    Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
2019-11-08T21:56:04.6905266Z     Finished release [optimized] target(s) in 1m 33s
2019-11-08T21:56:04.6995950Z tidy check
2019-11-08T21:56:05.5277279Z tidy error: /checkout/src/liballoc/string.rs:2003: line longer than 100 chars
2019-11-08T21:56:07.5825647Z Found 485 error codes
2019-11-08T21:56:07.5828917Z Found 0 error codes with no tests
2019-11-08T21:56:07.5829053Z Done!
2019-11-08T21:56:07.5829103Z some tidy checks failed
2019-11-08T21:56:07.5829103Z some tidy checks failed
2019-11-08T21:56:07.5832145Z 
2019-11-08T21:56:07.5832224Z 
2019-11-08T21:56:07.5833277Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-11-08T21:56:07.5833413Z 
2019-11-08T21:56:07.5833439Z 
2019-11-08T21:56:07.5841063Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-11-08T21:56:07.5841133Z Build completed unsuccessfully in 0:01:37
2019-11-08T21:56:07.5841133Z Build completed unsuccessfully in 0:01:37
2019-11-08T21:56:07.5898017Z == clock drift check ==
2019-11-08T21:56:07.5907909Z   local time: Fri Nov  8 21:56:07 UTC 2019
2019-11-08T21:56:07.6770189Z   network time: Fri, 08 Nov 2019 21:56:07 GMT
2019-11-08T21:56:07.6770757Z == end clock drift check ==
2019-11-08T21:56:09.0512944Z 
2019-11-08T21:56:09.0630920Z ##[error]Bash exited with code '1'.
2019-11-08T21:56:09.0659655Z ##[section]Starting: Checkout
2019-11-08T21:56:09.0684554Z ==============================================================================
2019-11-08T21:56:09.0684617Z Task         : Get sources
2019-11-08T21:56:09.0684679Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@Ruster-a11y
Copy link
Author

Ruster-a11y commented Nov 8, 2019

@dtolnay This needs further review. Haven't added the tests yet, I plan to add a different commit for that.

Edit: Respective test procedures have been added.

@Ruster-a11y Ruster-a11y requested a review from dtolnay November 9, 2019 04:21
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, 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.
2019-11-09T04:20:54.3221893Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-09T04:20:54.3411918Z ##[command]git config gc.auto 0
2019-11-09T04:20:54.3532547Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-09T04:20:54.3570880Z ##[command]git config --get-all http.proxy
2019-11-09T04:20:54.9243264Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66215/merge:refs/remotes/pull/66215/merge
---
2019-11-09T04:27:00.9895001Z    Compiling serde_json v1.0.40
2019-11-09T04:27:02.6654166Z    Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
2019-11-09T04:27:13.3237758Z     Finished release [optimized] target(s) in 1m 22s
2019-11-09T04:27:13.3323816Z tidy check
2019-11-09T04:27:13.4697986Z tidy error: /checkout/src/liballoc/string.rs:2003: line longer than 100 chars
2019-11-09T04:27:15.8324500Z some tidy checks failed
2019-11-09T04:27:15.8324601Z Found 485 error codes
2019-11-09T04:27:15.8324638Z Found 0 error codes with no tests
2019-11-09T04:27:15.8327725Z Done!
2019-11-09T04:27:15.8327725Z Done!
2019-11-09T04:27:15.8327776Z 
2019-11-09T04:27:15.8327832Z 
2019-11-09T04:27:15.8329021Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-11-09T04:27:15.8329135Z 
2019-11-09T04:27:15.8329162Z 
2019-11-09T04:27:15.8329655Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-11-09T04:27:15.8329713Z Build completed unsuccessfully in 0:01:25
2019-11-09T04:27:15.8329713Z Build completed unsuccessfully in 0:01:25
2019-11-09T04:27:15.8381025Z == clock drift check ==
2019-11-09T04:27:15.8405179Z   local time: Sat Nov  9 04:27:15 UTC 2019
2019-11-09T04:27:16.1171815Z   network time: Sat, 09 Nov 2019 04:27:16 GMT
2019-11-09T04:27:16.1171906Z == end clock drift check ==
2019-11-09T04:27:17.5026247Z 
2019-11-09T04:27:17.5130701Z ##[error]Bash exited with code '1'.
2019-11-09T04:27:17.5152746Z ##[section]Starting: Checkout
2019-11-09T04:27:17.5154127Z ==============================================================================
2019-11-09T04:27:17.5154169Z Task         : Get sources
2019-11-09T04:27:17.5154229Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

src/liballoc/borrow.rs Outdated Show resolved Hide resolved
@dtolnay dtolnay added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2019
@Ruster-a11y
Copy link
Author

@dtolnay Can you help me with an online ID of some sort to chat and resolve this with you in realtime?

src/liballoc/string.rs Outdated Show resolved Hide resolved
@LukasKalbertodt
Copy link
Member

Hi there!

Unfortunately, adding this impl is pretty tricky. I tried this once, too, but this lead to some breakage (of code in the compiler). See this issue: #51916

So I think we can't merge this PR before we discussed and "solved" the issue I linked.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, 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.
2019-11-16T04:24:03.9077431Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-16T04:24:03.9270705Z ##[command]git config gc.auto 0
2019-11-16T04:24:03.9341344Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-16T04:24:03.9401518Z ##[command]git config --get-all http.proxy
2019-11-16T04:24:03.9554084Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66215/merge:refs/remotes/pull/66215/merge
---
2019-11-16T04:30:08.3585111Z    Compiling serde_json v1.0.40
2019-11-16T04:30:10.1369296Z    Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
2019-11-16T04:30:21.3633653Z     Finished release [optimized] target(s) in 1m 29s
2019-11-16T04:30:21.3732727Z tidy check
2019-11-16T04:30:21.5251037Z tidy error: /checkout/src/liballoc/string.rs:2003: line longer than 100 chars
2019-11-16T04:30:24.1085849Z some tidy checks failed
2019-11-16T04:30:24.1089764Z Found 441 error codes
2019-11-16T04:30:24.1143818Z Found 0 error codes with no tests
2019-11-16T04:30:24.1143903Z Done!
2019-11-16T04:30:24.1143903Z Done!
2019-11-16T04:30:24.1143931Z 
2019-11-16T04:30:24.1143954Z 
2019-11-16T04:30:24.1144740Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-11-16T04:30:24.1144856Z 
2019-11-16T04:30:24.1144878Z 
2019-11-16T04:30:24.1144919Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-11-16T04:30:24.1144980Z Build completed unsuccessfully in 0:01:33
2019-11-16T04:30:24.1144980Z Build completed unsuccessfully in 0:01:33
2019-11-16T04:30:24.1147344Z == clock drift check ==
2019-11-16T04:30:24.1210501Z   local time: Sat Nov 16 04:30:24 UTC 2019
2019-11-16T04:30:24.3952422Z   network time: Sat, 16 Nov 2019 04:30:24 GMT
2019-11-16T04:30:24.3953935Z == end clock drift check ==
2019-11-16T04:30:25.7737916Z 
2019-11-16T04:30:25.7838933Z ##[error]Bash exited with code '1'.
2019-11-16T04:30:25.7873144Z ##[section]Starting: Checkout
2019-11-16T04:30:25.7875033Z ==============================================================================
2019-11-16T04:30:25.7875099Z Task         : Get sources
2019-11-16T04:30:25.7875142Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@Ruster-a11y
Copy link
Author

Hello @LukasKalbertodt, I apologize for the late response.

You're right, this feature would require downstream changes for the respective crates as per the compile-time error messages.

Can you suggest anything to help kill this ambiguity that the compiler is unable to distinguish from?

Surely, implementing a core solution would be better than changes across the previous code/logic of other crates.

@LukasKalbertodt
Copy link
Member

Can you suggest anything to help kill this ambiguity that the compiler is unable to distinguish from?

Unfortunately, no.

I think the first step would be to find out why exactly this happens. And if this is indeed intended behavior (very likely) or not. I just asked on StackOverflow to maybe get an answer that way. I will update the issue if I completely understood the issue.

Next (assuming this is intended behavior), we have to discuss what the balance between the benefits of Add<char> for String and the potential breakage is. In my opinion, Add<char> for String is something we obviously want, so we would have to see how to reduce the breakage to a minimum. In the issue someone already suggested adding Add<&String> for String which would help with a lot of cases. We might also need to add Add<&&String> for String. Maybe with these two additional impls, we can avoid almost all breakages. These things have to be tested by crater then to confirm we are not breaking the world.

I think this is roughly how we should proceed. I'm pretty sure there is no "quick fix" for now.

@jonas-schievink
Copy link
Contributor

Yeah, this is intended behavior. When the compiler looks for an impl, and ends up with only a single one that could possibly apply, it eagerly confirms that impl regardless of the current state of type inference, and uses the impls type parameters to drive type inference forward (by unifying them with any inference variables that apply). This means it now knows that the expected type is &str and can coerce the &String to that.

If there's more than one impl, the compiler can't select one of them yet and you end up with an unknown expected type, so no coercion can happen and it ends up leaving that type set to &String.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, 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.
2019-11-20T02:35:53.5967284Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-20T02:35:53.5980525Z ##[command]git config gc.auto 0
2019-11-20T02:35:53.5984320Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-20T02:35:53.5987771Z ##[command]git config --get-all http.proxy
2019-11-20T02:35:53.5991034Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66215/merge:refs/remotes/pull/66215/merge
---
2019-11-20T03:27:58.9271111Z .................................................................................................... 1500/9256
2019-11-20T03:28:04.1002539Z .................................................................................................... 1600/9256
2019-11-20T03:28:11.6018570Z .................................................................................................... 1700/9256
2019-11-20T03:28:19.5384200Z ........i........................................................................................... 1800/9256
2019-11-20T03:28:25.1820800Z .............................................................................................iiiii.. 1900/9256
2019-11-20T03:28:43.3509116Z .................................................................................................... 2100/9256
2019-11-20T03:28:45.4371015Z .................................................................................................... 2200/9256
2019-11-20T03:28:47.6544129Z .................................................................................................... 2300/9256
2019-11-20T03:28:52.9313144Z .................................................................................................... 2400/9256
---
2019-11-20T03:31:28.5408924Z ..............................................................................................i..... 4700/9256
2019-11-20T03:31:34.5098550Z ..........i......................................................................................... 4800/9256
2019-11-20T03:31:42.9942269Z .................................................................................................... 4900/9256
2019-11-20T03:31:47.6917706Z .................................................................................................... 5000/9256
2019-11-20T03:31:57.0231582Z ..................................................................................................ii 5100/9256
2019-11-20T03:32:01.5348072Z .ii...........i..................................................................................... 5200/9256
2019-11-20T03:32:10.8231068Z .................................................................................................... 5400/9256
2019-11-20T03:32:20.2294295Z ................................................................................i................... 5500/9256
2019-11-20T03:32:27.2763049Z .................................................................................................... 5600/9256
2019-11-20T03:32:32.9877734Z .................................................................................................... 5700/9256
2019-11-20T03:32:32.9877734Z .................................................................................................... 5700/9256
2019-11-20T03:32:42.0831235Z ..................................................................ii...i..ii...........i............ 5800/9256
2019-11-20T03:33:01.8877399Z .................................................................................................... 6000/9256
2019-11-20T03:33:09.3614504Z .................................................................................................... 6100/9256
2019-11-20T03:33:09.3614504Z .................................................................................................... 6100/9256
2019-11-20T03:33:13.3222131Z .......................................................................................i..ii........ 6200/9256
2019-11-20T03:33:37.2605642Z .................................................................................................... 6400/9256
2019-11-20T03:33:41.8056747Z .......................................................i............................................ 6500/9256
2019-11-20T03:33:43.7368618Z .................................................................................................... 6600/9256
2019-11-20T03:33:45.8574755Z ............................................i....................................................... 6700/9256
---
2019-11-20T03:38:20.9138805Z  finished in 5.032
2019-11-20T03:38:20.9139099Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-20T03:38:20.9139136Z 
2019-11-20T03:38:20.9139197Z running 156 tests
2019-11-20T03:38:23.0595101Z iiii....iii......iii..iiii...i.............................i..i..................i....i...........ii 100/156
2019-11-20T03:38:24.7336052Z .i.i..iiii..............i.........iii.i.........ii......
2019-11-20T03:38:24.7337480Z 
2019-11-20T03:38:24.7341969Z  finished in 4.445
2019-11-20T03:38:24.7508955Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-20T03:38:24.8977608Z 
---
2019-11-20T03:38:26.6946044Z  finished in 1.943
2019-11-20T03:38:26.7116641Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-20T03:38:26.8547451Z 
2019-11-20T03:38:26.8548189Z running 9 tests
2019-11-20T03:38:26.8549023Z iiiiiiiii
2019-11-20T03:38:26.8549779Z 
2019-11-20T03:38:26.8549916Z  finished in 0.143
2019-11-20T03:38:26.8747842Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-20T03:38:27.0571991Z 
---
2019-11-20T03:38:43.9885001Z  finished in 17.113
2019-11-20T03:38:44.5272683Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-20T03:38:44.6916595Z 
2019-11-20T03:38:44.6917503Z running 123 tests
2019-11-20T03:39:05.3390520Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....ii..........iiii..........i...ii...i.......ii. 100/123
2019-11-20T03:39:09.3465827Z i.i.i......iii.i.....ii
2019-11-20T03:39:09.3467150Z 
2019-11-20T03:39:09.3470037Z  finished in 24.820
2019-11-20T03:39:09.3477415Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-20T03:39:09.3478275Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-11-20T03:47:10.7581971Z   local time: Wed Nov 20 03:47:10 UTC 2019
2019-11-20T03:47:11.2809705Z   network time: Wed, 20 Nov 2019 03:47:11 GMT
2019-11-20T03:47:11.2812006Z == end clock drift check ==
2019-11-20T03:47:12.8329896Z 
2019-11-20T03:47:12.8435016Z ##[error]Bash exited with code '1'.
2019-11-20T03:47:12.8464808Z ##[section]Starting: Checkout
2019-11-20T03:47:12.8466413Z ==============================================================================
2019-11-20T03:47:12.8466590Z Task         : Get sources
2019-11-20T03:47:12.8466631Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@JohnCSimon
Copy link
Member

Ping from triage:
@Ruster-a11y Can you please address the change request and build failure?
@dtolnay
Thank you!

if let Cow::Borrowed(lhs) = *self {
let base_capacity = lhs.len() + rhs.len_utf8();
//Attempt amortized memory allocation
let new_optimal_size = max(base_capacity * 2, base_capacity);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me -- we know base_capacity >= 0 so max(base_capacity * 2, base_capacity) is always the same as base_capacity * 2. Has it been written this way to account for integer overflow? If so, that needs to be handled differently; the overflowing multiplication would not be guaranteed to wrap around to 0.

fn add_assign(&mut self, rhs: char) {
if let Cow::Borrowed(lhs) = *self {
let base_capacity = lhs.len() + rhs.len_utf8();
//Attempt amortized memory allocation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to avoid duplicating this sizing heuristic from the existing amortized_new_size in raw_vec.rs? I thought you had used amortized_new_size successfully in an earlier revision.

If we make changes to the heuristic in the future, it should only be in one place.

impl AddAssign<char> for Cow<'_, str> {
fn add_assign(&mut self, rhs: char) {
if let Cow::Borrowed(lhs) = *self {
let base_capacity = lhs.len() + rhs.len_utf8();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right -- the amortized_new_size heuristic expects to receive the currently used capacity (how much is already used) and the requested extra capacity (how much is being added) as separate data points. In this AddAssign impl the currently used capacity is the length of the lhs Cow<str> and how much is being added is the size of the rhs char. Adding these together ahead of time would make the heuristic no longer applicable, or behave not as intended.

@dtolnay
Copy link
Member

dtolnay commented Nov 24, 2019

I think this PR can go on hold until we settle whether we can have Add<char> for String (#66504). I believe we wouldn't want this for Cow<str> if it can't exist on String.

@Dylan-DPC-zz Dylan-DPC-zz added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 26, 2019
@Dylan-DPC-zz
Copy link

Marking this as blocked on #66504

@Centril Centril modified the milestones: 1.41, 1.42 Dec 20, 2019
@dtolnay
Copy link
Member

dtolnay commented Jan 10, 2020

Closing, as #66504 ended up not working out. Thanks anyway @Ruster-a11y!

@dtolnay dtolnay closed this Jan 10, 2020
@Centril Centril removed this from the 1.42 milestone Jan 31, 2020
@Centril Centril removed the relnotes Marks issues that should be documented in the release notes of the next release. label Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.