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

alloc: add some try_* methods Rust-for-Linux needs #91559

Closed
wants to merge 9 commits into from

Conversation

Xuanwo
Copy link
Contributor

@Xuanwo Xuanwo commented Dec 5, 2021

This PR is a follow-up to the #86938.

Part work of #86942


Based off of Rust-for-Linux/linux@487d757

Has been rebased onto rust-lang's master.

I will figure out all CI problems before request review.

@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 5, 2021
@rust-log-analyzer

This comment has been minimized.

@Ericson2314
Copy link
Contributor

Thank you!!!

library/std/src/collections/hash/map.rs Outdated Show resolved Hide resolved
library/std/src/collections/hash/map.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Xuanwo <[email protected]>
@Xuanwo
Copy link
Contributor Author

Xuanwo commented Dec 15, 2021

ping @Ericson2314, this PR basically works now. Can you take a quick to confirm that I'm on the right track?

@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Xuanwo <[email protected]>
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-12 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
status: exit status: 2
command: "make"
stdout:
------------------------------------------
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/alloc-no-oom-handling/alloc-no-oom-handling:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/alloc-no-oom-handling/alloc-no-oom-handling -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/alloc-no-oom-handling/alloc-no-oom-handling  --edition=2018 --crate-type=rlib ../../../../library/alloc/src/lib.rs --cfg feature=\"external_crate\" --cfg no_global_oom_handling
------------------------------------------
stderr:
------------------------------------------
error[E0432]: unresolved import `self::spec_extend`
error[E0432]: unresolved import `self::spec_extend`
   --> ../../../../library/alloc/src/vec/mod.rs:147:11
    |
147 | use self::spec_extend::TrySpecExtend;
    |           ^^^^^^^^^^^ could not find `spec_extend` in `self`
error[E0433]: failed to resolve: use of undeclared type `AllocInit`
   --> ../../../../library/alloc/src/raw_vec.rs:159:41
    |
    |
159 |         Self::try_allocate_in(capacity, AllocInit::Uninitialized, alloc)
    |                                         ^^^^^^^^^ use of undeclared type `AllocInit`
error[E0433]: failed to resolve: use of undeclared type `AllocInit`
   --> ../../../../library/alloc/src/raw_vec.rs:229:17
    |
    |
229 |                 AllocInit::Uninitialized => alloc.allocate(layout),
    |                 ^^^^^^^^^ use of undeclared type `AllocInit`
error[E0433]: failed to resolve: use of undeclared type `AllocInit`
   --> ../../../../library/alloc/src/raw_vec.rs:230:17
    |
    |
230 |                 AllocInit::Zeroed => alloc.allocate_zeroed(layout),
    |                 ^^^^^^^^^ use of undeclared type `AllocInit`
error[E0433]: failed to resolve: use of undeclared type `SetLenOnDrop`
    --> ../../../../library/alloc/src/vec/mod.rs:2576:33
     |
     |
2576 |             let mut local_len = SetLenOnDrop::new(&mut self.len);
     |                                 ^^^^^^^^^^^^ use of undeclared type `SetLenOnDrop`
error[E0412]: cannot find type `AllocInit` in this scope
   --> ../../../../library/alloc/src/raw_vec.rs:215:15
    |
215 |         init: AllocInit,
215 |         init: AllocInit,
    |               ^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `Global` in this scope
   --> ../../../../library/alloc/src/slice.rs:549:28
    |
549 |         self.try_to_vec_in(Global)
    |
help: consider importing this unit struct
    |
85  | use crate::alloc::Global;
85  | use crate::alloc::Global;
    |

error[E0412]: cannot find type `Vec` in this scope
    --> ../../../../library/alloc/src/sync.rs:2527:32
     |
2527 |     pub fn try_from_vec(mut v: Vec<T>) -> Result<Self, TryReserveError> {
     |
help: consider importing this struct
     |
7    | use crate::vec::Vec;
7    | use crate::vec::Vec;
     |

error[E0599]: no function or associated item named `try_with_capacity` found for struct `RawVec` in the current scope
   --> ../../../../library/alloc/src/boxed.rs:629:27
    |
629 |             match RawVec::try_with_capacity(len) {
    |                           |
    |                           function or associated item not found in `RawVec<_, _>`
    |                           help: there is an associated function with a similar name: `try_with_capacity_in`
    |
    |
   ::: ../../../../library/alloc/src/raw_vec.rs:52:1
    |
52  | pub(crate) struct RawVec<T, A: Allocator = Global> {
    | -------------------------------------------------- function or associated item `try_with_capacity` not found for this

error[E0599]: no function or associated item named `try_with_capacity_zeroed` found for struct `RawVec` in the current scope
   --> ../../../../library/alloc/src/boxed.rs:659:27
    |
659 |             match RawVec::try_with_capacity_zeroed(len) {
    |                           |
    |                           function or associated item not found in `RawVec<_, _>`
    |                           help: there is an associated function with a similar name: `try_with_capacity_in`
    |
    |
   ::: ../../../../library/alloc/src/raw_vec.rs:52:1
    |
52  | pub(crate) struct RawVec<T, A: Allocator = Global> {
    | -------------------------------------------------- function or associated item `try_with_capacity_zeroed` not found for this

error[E0599]: no method named `reserve_for_push` found for struct `RawVec` in the current scope
    --> ../../../../library/alloc/src/vec/mod.rs:1905:22
     |
1905 |             self.buf.reserve_for_push(self.len);
     |                      ^^^^^^^^^^^^^^^^ method not found in `RawVec<T, A>`
    ::: ../../../../library/alloc/src/raw_vec.rs:52:1
     |
     |
52   | pub(crate) struct RawVec<T, A: Allocator = Global> {
     | -------------------------------------------------- method `reserve_for_push` not found for this

error[E0599]: no method named `try_spec_extend` found for mutable reference `&mut Vec<T, A>` in the current scope
    --> ../../../../library/alloc/src/vec/mod.rs:2476:14
     |
2476 |         self.try_spec_extend(other.iter())
     |              ^^^^^^^^^^^^^^^ method not found in `&mut Vec<T, A>`
error: aborting due to 12 previous errors

Some errors have detailed explanations: E0412, E0425, E0432, E0433, E0599.
For more information about an error, try `rustc --explain E0412`.
For more information about an error, try `rustc --explain E0412`.
make: *** [Makefile:4: all] Error 1
------------------------------------------




failures:
    [run-make] run-make-fulldeps/alloc-no-oom-handling

test result: FAILED. 209 passed; 1 failed; 18 ignored; 0 measured; 0 filtered out; finished in 27.87s



command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--rustdoc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" "--rust-demangler-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/rust-demangler" "--src-base" "/checkout/src/test/run-make-fulldeps" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--suite" "run-make-fulldeps" "--mode" "run-make" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-12/bin/FileCheck" "--nodejs" "/usr/bin/node" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "12.0.0" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker engine executionengine extensions filecheck frontendopenacc frontendopenmp fuzzmutate globalisel hellonew hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interfacestub interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit orcshared orctargetprocess passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray" "--system-llvm" "--llvm-bin-dir" "/usr/lib/llvm-12/bin" "--cc" "cc" "--cxx" "c++" "--cflags" "-ffunction-sections -fdata-sections -fPIC -m64" "--ar" "ar" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--channel" "nightly" "--color" "always"


Build completed unsuccessfully in 0:30:17

@Ericson2314
Copy link
Contributor

@Xuanwo do you think you could preserve the old history splitting into multiple commits, such that each work? Also remember you need to test with --cfg no_global_oom_handling too, that is where the failure is coming from.

@Xuanwo
Copy link
Contributor Author

Xuanwo commented Dec 15, 2021

The history is so complex that I can't preserve them simply (the base is so different). My plan is to squash all old commits into one which authored with your name and keep my changes as you suggested. What do you think?

@Ericson2314
Copy link
Contributor

@Xuanwo the reason I did the split was because some of the later commits might introduce performance regressions. It was something that came up in the meetings.

@Ericson2314
Copy link
Contributor

I will take a brief look at the rebase.

@Xuanwo
Copy link
Contributor Author

Xuanwo commented Dec 15, 2021

@Ericson2314 OK, let me try it again.

Is there any convenient way to switch the base from Rust-for-Linux to rust-lang? I spent a lot time to fix the conflict :(

@Ericson2314
Copy link
Contributor

Ericson2314 commented Dec 15, 2021

@Xuanwo give me like 10 minutes to see if I can do it on your behalf. I have done a lot of rebase I think I can port over your conflict resolutions OK.

(I also feel it's a bit on me because I didn't mention that preserving history is good from the get-go. I can fix the mistake I made :) )

@Ericson2314
Copy link
Contributor

Unfortunately GitHub doesn't let one change the base branch of PRs.

@Xuanwo
Copy link
Contributor Author

Xuanwo commented Dec 15, 2021

Unfortunately GitHub doesn't let one change the base branch of PRs.

Yes, we have to do it via git.

@Ericson2314
Copy link
Contributor

@Xuanwo OK I did the rebase and forced pushed. It can now be compared to your branch, since they share your base branch.

What I recommend doing is an interactive on that same base commit (d594910), but where you edit each commit of mine, and pull over the relevant fixes from yours for that commit.

Now that can glance the diff showing your changes, they look good :). Just make sure --cfg no_global_oom_handling works as you pull over those changes, and then I think we're good!

@bors
Copy link
Contributor

bors commented Dec 24, 2021

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

@Xuanwo
Copy link
Contributor Author

Xuanwo commented Mar 13, 2022

I can't continue this work due to lack of time recently, let's close this PR for now, thanks for the help!

@Xuanwo Xuanwo closed this Mar 13, 2022
@Xuanwo Xuanwo deleted the more-try-methods branch March 13, 2022 17:16
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.

6 participants