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

Use AllocRef for ZSTs in RawVec #69824

Closed
wants to merge 1 commit into from

Conversation

TimDiekmann
Copy link
Member

@TimDiekmann TimDiekmann commented Mar 8, 2020

Moves the responsibility for handling ZSTs from RawVec to AllocRef. On the same occasion I have moved the logic for reserving and shrinking into the new methods grow and shrink to keep the logic in one place without changing the behavior.

Every grow/shrink operation now has three steps:

  1. Calculate the new size, either by doubling the current capacity, calculate the amortized size, or use an exact size
  2. Call AllocRef
  3. Update self.ptr and self.cap

There are no more checks in RawVec needed for taking a different path for ZSTs.


This is the last item on the roadmap to support ZSTs in AllocRef: rust-lang/wg-allocators#38 (comment)

Requires #69799 to land first, otherwise Global will be called with zero-sized layouts.

closes rust-lang/wg-allocators#38

r? @Amanieu

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 8, 2020
@rust-highfive
Copy link
Collaborator

The job mingw-check 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.
2020-03-08T12:45:08.5516399Z ========================== Starting Command Output ===========================
2020-03-08T12:45:08.5525082Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/dc8ebb8d-778a-449f-a181-90c3ff3c12bb.sh
2020-03-08T12:45:08.5525800Z 
2020-03-08T12:45:08.5531503Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-08T12:45:08.5553760Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T12:45:08.5557658Z Task         : Get sources
2020-03-08T12:45:08.5558029Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-08T12:45:08.5558349Z Version      : 1.0.0
2020-03-08T12:45:08.5558567Z Author       : Microsoft
---
2020-03-08T12:45:09.5369734Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-08T12:45:09.5375520Z ##[command]git config gc.auto 0
2020-03-08T12:45:09.5379557Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-08T12:45:09.5383232Z ##[command]git config --get-all http.proxy
2020-03-08T12:45:09.5390168Z ##[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/69824/merge:refs/remotes/pull/69824/merge
---
2020-03-08T12:49:47.0916046Z     Checking backtrace v0.3.44
2020-03-08T12:49:47.6228635Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T12:49:47.6229506Z   --> src/liballoc/raw_vec.rs:77:70
2020-03-08T12:49:47.6230102Z    |
2020-03-08T12:49:47.6230918Z 77 |         let allocation = if zeroed { a.alloc_zeroed(layout) } else { a.alloc(layout) };
2020-03-08T12:49:47.6232328Z    |                                                                      ^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T12:49:47.6234177Z    = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T12:49:47.6234642Z 
2020-03-08T12:49:47.6235312Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T12:49:47.6236083Z   --> src/liballoc/raw_vec.rs:77:38
2020-03-08T12:49:47.6236083Z   --> src/liballoc/raw_vec.rs:77:38
2020-03-08T12:49:47.6236643Z    |
2020-03-08T12:49:47.6237448Z 77 |         let allocation = if zeroed { a.alloc_zeroed(layout) } else { a.alloc(layout) };
2020-03-08T12:49:47.6238580Z    |                                      ^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T12:49:47.6240141Z    = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T12:49:47.6240601Z 
2020-03-08T12:49:47.6241264Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T12:49:47.6242041Z    --> src/liballoc/raw_vec.rs:544:38
2020-03-08T12:49:47.6242041Z    --> src/liballoc/raw_vec.rs:544:38
2020-03-08T12:49:47.6242606Z     |
2020-03-08T12:49:47.6243339Z 544 |                 (Allocate, false) => self.a.alloc(new_layout),
2020-03-08T12:49:47.6244408Z     |                                      ^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T12:49:47.6246689Z     = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T12:49:47.6247156Z 
2020-03-08T12:49:47.6257826Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T12:49:47.6259042Z    --> src/liballoc/raw_vec.rs:545:37
2020-03-08T12:49:47.6259042Z    --> src/liballoc/raw_vec.rs:545:37
2020-03-08T12:49:47.6259890Z     |
2020-03-08T12:49:47.6260861Z 545 |                 (Allocate, true) => self.a.alloc_zeroed(new_layout),
2020-03-08T12:49:47.6262153Z     |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T12:49:47.6264188Z     = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T12:49:47.6264787Z 
2020-03-08T12:49:47.6348450Z error: aborting due to 4 previous errors
2020-03-08T12:49:47.6348780Z 
---
2020-03-08T12:49:48.7200676Z   local time: Sun Mar  8 12:49:47 UTC 2020
2020-03-08T12:49:48.7200966Z   network time: Sun, 08 Mar 2020 12:49:47 GMT
2020-03-08T12:49:48.7201214Z == end clock drift check ==
2020-03-08T12:49:48.8863246Z 
2020-03-08T12:49:48.8959697Z ##[error]Bash exited with code '1'.
2020-03-08T12:49:48.8974904Z ##[section]Finishing: Run build
2020-03-08T12:49:48.9025018Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T12:49:48.9030836Z Task         : Get sources
2020-03-08T12:49:48.9031234Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-08T12:49:48.9031620Z Version      : 1.0.0
2020-03-08T12:49:48.9031874Z Author       : Microsoft
2020-03-08T12:49:48.9031874Z Author       : Microsoft
2020-03-08T12:49:48.9032298Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-08T12:49:48.9032784Z ==============================================================================
2020-03-08T12:49:49.2165934Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-08T12:49:49.2210812Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T12:49:49.2289168Z Cleaning up task key
2020-03-08T12:49:49.2290294Z Start cleaning up orphan processes.
2020-03-08T12:49:49.2452061Z Terminate orphan process: pid (3954) (python)
2020-03-08T12:49:49.2571841Z ##[section]Finishing: Finalize Job

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 @rust-lang/infra. (Feature Requests)

@TimDiekmann TimDiekmann force-pushed the rawvec-zst branch 2 times, most recently from a2679ba to 2c8c689 Compare March 8, 2020 13:08
@rust-highfive
Copy link
Collaborator

The job mingw-check 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.
2020-03-08T13:08:29.4857675Z ========================== Starting Command Output ===========================
2020-03-08T13:08:29.4862455Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/d19da6c9-bde8-444c-ab75-ad1c6789074f.sh
2020-03-08T13:08:29.4862907Z 
2020-03-08T13:08:29.4866786Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-08T13:08:29.4885525Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T13:08:29.4889062Z Task         : Get sources
2020-03-08T13:08:29.4889356Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-08T13:08:29.4889639Z Version      : 1.0.0
2020-03-08T13:08:29.4889850Z Author       : Microsoft
---
2020-03-08T13:08:30.4827732Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-08T13:08:30.4833242Z ##[command]git config gc.auto 0
2020-03-08T13:08:30.4836479Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-08T13:08:30.4840856Z ##[command]git config --get-all http.proxy
2020-03-08T13:08:30.4847088Z ##[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/69824/merge:refs/remotes/pull/69824/merge
---
2020-03-08T13:13:13.4513849Z     Checking backtrace v0.3.44
2020-03-08T13:13:14.5454465Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T13:13:14.5456214Z   --> src/liballoc/raw_vec.rs:77:70
2020-03-08T13:13:14.5457187Z    |
2020-03-08T13:13:14.5458192Z 77 |         let allocation = if zeroed { a.alloc_zeroed(layout) } else { a.alloc(layout) };
2020-03-08T13:13:14.5459603Z    |                                                                      ^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T13:13:14.5464081Z    = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T13:13:14.5464498Z 
2020-03-08T13:13:14.5465088Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T13:13:14.5465786Z   --> src/liballoc/raw_vec.rs:77:38
2020-03-08T13:13:14.5465786Z   --> src/liballoc/raw_vec.rs:77:38
2020-03-08T13:13:14.5466669Z    |
2020-03-08T13:13:14.5467476Z 77 |         let allocation = if zeroed { a.alloc_zeroed(layout) } else { a.alloc(layout) };
2020-03-08T13:13:14.5468559Z    |                                      ^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T13:13:14.5469847Z    = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T13:13:14.5470226Z 
2020-03-08T13:13:14.5470850Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T13:13:14.5471446Z    --> src/liballoc/raw_vec.rs:541:38
2020-03-08T13:13:14.5471446Z    --> src/liballoc/raw_vec.rs:541:38
2020-03-08T13:13:14.5471884Z     |
2020-03-08T13:13:14.5472459Z 541 |                 (Allocate, false) => self.a.alloc(new_layout),
2020-03-08T13:13:14.5473290Z     |                                      ^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T13:13:14.5474849Z     = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T13:13:14.5475238Z 
2020-03-08T13:13:14.5475833Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T13:13:14.5476515Z    --> src/liballoc/raw_vec.rs:542:37
2020-03-08T13:13:14.5476515Z    --> src/liballoc/raw_vec.rs:542:37
2020-03-08T13:13:14.5476994Z     |
2020-03-08T13:13:14.5477739Z 542 |                 (Allocate, true) => self.a.alloc_zeroed(new_layout),
2020-03-08T13:13:14.5479232Z     |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T13:13:14.5480576Z     = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T13:13:14.5480941Z 
2020-03-08T13:13:14.5539497Z error: aborting due to 4 previous errors
2020-03-08T13:13:14.5539739Z 
---
2020-03-08T13:13:14.5749791Z   local time: Sun Mar  8 13:13:14 UTC 2020
2020-03-08T13:13:14.8556782Z   network time: Sun, 08 Mar 2020 13:13:14 GMT
2020-03-08T13:13:14.8562343Z == end clock drift check ==
2020-03-08T13:13:15.8311664Z 
2020-03-08T13:13:15.8381891Z ##[error]Bash exited with code '1'.
2020-03-08T13:13:15.8395593Z ##[section]Finishing: Run build
2020-03-08T13:13:15.8439490Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T13:13:15.8444495Z Task         : Get sources
2020-03-08T13:13:15.8444815Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-08T13:13:15.8445093Z Version      : 1.0.0
2020-03-08T13:13:15.8445285Z Author       : Microsoft
2020-03-08T13:13:15.8445285Z Author       : Microsoft
2020-03-08T13:13:15.8445611Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-08T13:13:15.8445969Z ==============================================================================
2020-03-08T13:13:16.1673808Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-08T13:13:16.1725233Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T13:13:16.1813748Z Cleaning up task key
2020-03-08T13:13:16.1815161Z Start cleaning up orphan processes.
2020-03-08T13:13:16.2152565Z Terminate orphan process: pid (4252) (python)
2020-03-08T13:13:16.2198514Z ##[section]Finishing: Finalize Job

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 @rust-lang/infra. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job mingw-check 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.
2020-03-08T14:11:08.2515507Z ========================== Starting Command Output ===========================
2020-03-08T14:11:08.2517946Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/eb0e3b30-35a4-4417-bfbc-295cddfd89f8.sh
2020-03-08T14:11:08.2518207Z 
2020-03-08T14:11:08.2521503Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-08T14:11:08.2540369Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T14:11:08.2543493Z Task         : Get sources
2020-03-08T14:11:08.2543799Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-08T14:11:08.2544072Z Version      : 1.0.0
2020-03-08T14:11:08.2544258Z Author       : Microsoft
---
2020-03-08T14:11:09.2531286Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-08T14:11:09.2537028Z ##[command]git config gc.auto 0
2020-03-08T14:11:09.2541585Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-08T14:11:09.2545404Z ##[command]git config --get-all http.proxy
2020-03-08T14:11:09.2552145Z ##[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/69824/merge:refs/remotes/pull/69824/merge
---
2020-03-08T14:17:11.9782414Z     Checking backtrace v0.3.44
2020-03-08T14:17:12.5020051Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T14:17:12.5020945Z   --> src/liballoc/raw_vec.rs:67:70
2020-03-08T14:17:12.5021506Z    |
2020-03-08T14:17:12.5022319Z 67 |         let allocation = if zeroed { a.alloc_zeroed(layout) } else { a.alloc(layout) };
2020-03-08T14:17:12.5023518Z    |                                                                      ^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T14:17:12.5025167Z    = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T14:17:12.5025614Z 
2020-03-08T14:17:12.5026272Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T14:17:12.5027068Z   --> src/liballoc/raw_vec.rs:67:38
2020-03-08T14:17:12.5027068Z   --> src/liballoc/raw_vec.rs:67:38
2020-03-08T14:17:12.5027605Z    |
2020-03-08T14:17:12.5028405Z 67 |         let allocation = if zeroed { a.alloc_zeroed(layout) } else { a.alloc(layout) };
2020-03-08T14:17:12.5029534Z    |                                      ^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T14:17:12.5031102Z    = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T14:17:12.5031540Z 
2020-03-08T14:17:12.5032194Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T14:17:12.5032992Z    --> src/liballoc/raw_vec.rs:536:38
2020-03-08T14:17:12.5032992Z    --> src/liballoc/raw_vec.rs:536:38
2020-03-08T14:17:12.5033540Z     |
2020-03-08T14:17:12.5034272Z 536 |                 (Allocate, false) => self.a.alloc(new_layout),
2020-03-08T14:17:12.5035355Z     |                                      ^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T14:17:12.5036930Z     = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T14:17:12.5037390Z 
2020-03-08T14:17:12.5050259Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-08T14:17:12.5051123Z    --> src/liballoc/raw_vec.rs:537:37
2020-03-08T14:17:12.5051123Z    --> src/liballoc/raw_vec.rs:537:37
2020-03-08T14:17:12.5051709Z     |
2020-03-08T14:17:12.5052472Z 537 |                 (Allocate, true) => self.a.alloc_zeroed(new_layout),
2020-03-08T14:17:12.5053576Z     |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-08T14:17:12.5055372Z     = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-08T14:17:12.5060706Z 
2020-03-08T14:17:12.5107877Z error: aborting due to 4 previous errors
2020-03-08T14:17:12.5113088Z 
---
2020-03-08T14:17:12.5307230Z   local time: Sun Mar  8 14:17:12 UTC 2020
2020-03-08T14:17:12.6210603Z   network time: Sun, 08 Mar 2020 14:17:12 GMT
2020-03-08T14:17:12.6210961Z == end clock drift check ==
2020-03-08T14:17:13.7035326Z 
2020-03-08T14:17:13.7085379Z ##[error]Bash exited with code '1'.
2020-03-08T14:17:13.7108643Z ##[section]Finishing: Run build
2020-03-08T14:17:13.7157655Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T14:17:13.7163343Z Task         : Get sources
2020-03-08T14:17:13.7163696Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-08T14:17:13.7164015Z Version      : 1.0.0
2020-03-08T14:17:13.7164262Z Author       : Microsoft
2020-03-08T14:17:13.7164262Z Author       : Microsoft
2020-03-08T14:17:13.7164622Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-08T14:17:13.7165032Z ==============================================================================
2020-03-08T14:17:14.0525044Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-08T14:17:14.0569078Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-08T14:17:14.0660221Z Cleaning up task key
2020-03-08T14:17:14.0661479Z Start cleaning up orphan processes.
2020-03-08T14:17:14.0867875Z Terminate orphan process: pid (4838) (python)
2020-03-08T14:17:14.1012227Z ##[section]Finishing: Finalize Job

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 @rust-lang/infra. (Feature Requests)

@TimDiekmann
Copy link
Member Author

@Gankra Do you want to take a look into this, as you have written the first RawVec?

@TimDiekmann
Copy link
Member Author

I probably want to merge rust-lang/wg-allocators#44 first as well, as RawVec should use (and maybe expose) this API.

@rust-highfive
Copy link
Collaborator

The job mingw-check 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.
2020-03-09T16:34:07.8747587Z Prepare build directory.
2020-03-09T16:34:07.9014315Z Set build variables.
2020-03-09T16:34:07.9041775Z Download all required tasks.
2020-03-09T16:34:07.9143013Z Downloading task: Bash (3.163.1)
2020-03-09T16:34:09.5731897Z Checking job knob settings.
2020-03-09T16:34:09.5750848Z Finished checking job knob settings.
2020-03-09T16:34:09.6210732Z ##[section]Finishing: Initialize job
2020-03-09T16:34:09.6503874Z ##[section]Starting: Configure Job Name
2020-03-09T16:34:09.6682250Z ==============================================================================
2020-03-09T16:34:09.6682973Z Task         : Bash
---
2020-03-09T16:34:10.2187232Z ========================== Starting Command Output ===========================
2020-03-09T16:34:10.2191650Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/2c24dc4a-8c1f-43c5-b288-e2aa294b0f11.sh
2020-03-09T16:34:10.2191865Z 
2020-03-09T16:34:10.2194698Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-09T16:34:10.2213392Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-09T16:34:10.2217529Z Task         : Get sources
2020-03-09T16:34:10.2218099Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-09T16:34:10.2218501Z Version      : 1.0.0
2020-03-09T16:34:10.2218855Z Author       : Microsoft
---
2020-03-09T16:34:11.5614383Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-09T16:34:11.5620549Z ##[command]git config gc.auto 0
2020-03-09T16:34:11.5623260Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-09T16:34:11.5625670Z ##[command]git config --get-all http.proxy
2020-03-09T16:34:11.5630971Z ##[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/69824/merge:refs/remotes/pull/69824/merge
---
2020-03-09T16:38:28.2921630Z     Checking backtrace v0.3.44
2020-03-09T16:38:28.9113300Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-09T16:38:28.9113864Z   --> src/liballoc/raw_vec.rs:69:32
2020-03-09T16:38:28.9114229Z    |
2020-03-09T16:38:28.9114770Z 69 |             AllocInit::Zero => a.alloc_zeroed(layout),
2020-03-09T16:38:28.9115471Z    |                                ^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-09T16:38:28.9116656Z    = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-09T16:38:28.9120709Z 
2020-03-09T16:38:28.9125607Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-09T16:38:28.9126146Z   --> src/liballoc/raw_vec.rs:68:39
2020-03-09T16:38:28.9126146Z   --> src/liballoc/raw_vec.rs:68:39
2020-03-09T16:38:28.9126501Z    |
2020-03-09T16:38:28.9127023Z 68 |             AllocInit::Unspecified => a.alloc(layout),
2020-03-09T16:38:28.9127907Z    |                                       ^^^^^^^^^^^^^^^ call to unsafe function
2020-03-09T16:38:28.9128943Z    = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-09T16:38:28.9132555Z 
2020-03-09T16:38:28.9138712Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-09T16:38:28.9139300Z    --> src/liballoc/raw_vec.rs:558:74
2020-03-09T16:38:28.9139300Z    --> src/liballoc/raw_vec.rs:558:74
2020-03-09T16:38:28.9139663Z     |
2020-03-09T16:38:28.9140280Z 558 |                 (AllocPlacement::Unspecified, AllocInit::Unspecified) => self.a.alloc(new_layout),
2020-03-09T16:38:28.9141151Z     |                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-09T16:38:28.9142252Z     = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-09T16:38:28.9146919Z 
2020-03-09T16:38:28.9147575Z error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2020-03-09T16:38:28.9148103Z    --> src/liballoc/raw_vec.rs:559:67
2020-03-09T16:38:28.9148103Z    --> src/liballoc/raw_vec.rs:559:67
2020-03-09T16:38:28.9148463Z     |
2020-03-09T16:38:28.9149077Z 559 |                 (AllocPlacement::Unspecified, AllocInit::Zero) => self.a.alloc_zeroed(new_layout),
2020-03-09T16:38:28.9149952Z     |                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
2020-03-09T16:38:28.9151048Z     = note: consult the function's documentation for information on how to avoid undefined behavior
2020-03-09T16:38:28.9151339Z 
2020-03-09T16:38:28.9185716Z error: aborting due to 4 previous errors
2020-03-09T16:38:28.9185921Z 
---
2020-03-09T16:38:28.9338356Z   local time: Mon Mar  9 16:38:28 UTC 2020
2020-03-09T16:38:29.1995605Z   network time: Mon, 09 Mar 2020 16:38:29 GMT
2020-03-09T16:38:29.1998932Z == end clock drift check ==
2020-03-09T16:38:30.1459317Z 
2020-03-09T16:38:30.1523586Z ##[error]Bash exited with code '1'.
2020-03-09T16:38:30.1534966Z ##[section]Finishing: Run build
2020-03-09T16:38:30.1571653Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-09T16:38:30.1575673Z Task         : Get sources
2020-03-09T16:38:30.1575946Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-09T16:38:30.1576211Z Version      : 1.0.0
2020-03-09T16:38:30.1576386Z Author       : Microsoft
2020-03-09T16:38:30.1576386Z Author       : Microsoft
2020-03-09T16:38:30.1577216Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-09T16:38:30.1577580Z ==============================================================================
2020-03-09T16:38:30.4227236Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-09T16:38:30.4267279Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/69824/merge to s
2020-03-09T16:38:30.4345598Z Cleaning up task key
2020-03-09T16:38:30.4346693Z Start cleaning up orphan processes.
2020-03-09T16:38:30.4480149Z Terminate orphan process: pid (4265) (python)
2020-03-09T16:38:30.4590213Z ##[section]Finishing: Finalize Job

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 @rust-lang/infra. (Feature Requests)

@Amanieu
Copy link
Member

Amanieu commented Mar 9, 2020

My main concern with this change is that we are turning a compile-time check (size_of::<T>() == 0) into a runtime check in the allocator (layout.size() == 0). We cannot guarantee that the latter will be optimized away since it is likely located behind #[global_allocator], which is only resolved at link time.

@TimDiekmann
Copy link
Member Author

TimDiekmann commented Mar 9, 2020

AFAICT we don't have that runtime check. Let's take Vec<T> as an example:

  1. calls RawVec<T, Global>::allocate_in/grow/shrink. So far we know T.
  2. calls <Global as AllocRef>::alloc/realloc/grow/shrink. Here there is still no dynamic linking envolved, so the compiler still know the layout of T. In the AllocRef implementation of Global we calculate/lookup layout.size() (and maybe use AllocPlacement/AllocInit).
  3. We end up with calling the global alloc(_zeroed)/dealloc/realloc, which calls the dynamically linked #[global_allocator]. In the linked implementation there are no checks which has to be branched.

We basically just move the checks one layer down the road. When using AllocRef::grow/shrink, we could still try to optimize the path with intrinsics::assume(old_size < new_size).

Hopefully I didn't miss anything there... 😄

@bors
Copy link
Contributor

bors commented Mar 10, 2020

☔ The latest upstream changes (presumably #69879) made this pull request unmergeable. Please resolve the merge conflicts.

@TimDiekmann
Copy link
Member Author

Closing in favor of #69889

@TimDiekmann TimDiekmann deleted the rawvec-zst branch March 10, 2020 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add default implementation for allocating zero-sized types (or ZSTs)
4 participants