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

Decouple CrateNum of CrateInfo from the compilation session #67516

Closed
wants to merge 2 commits into from
Closed

Decouple CrateNum of CrateInfo from the compilation session #67516

wants to merge 2 commits into from

Conversation

0dvictor
Copy link
Contributor

CrateNum used inside a CrateInfo is self-contained and hence can be decoupled from the compilation session. By doing so, a compilation session can consume CrateInfo generated from a different compilation session. Ultimately, it allows splitting linker invocation into a separate compilation session.

@rust-highfive
Copy link
Collaborator

r? @cramertj

(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 22, 2019
@0dvictor
Copy link
Contributor Author

r? @bjorn3

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 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-12-22T11:49:43.5779060Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-12-22T11:49:43.5788203Z ##[command]git config gc.auto 0
2019-12-22T11:49:43.5791241Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-12-22T11:49:43.5794015Z ##[command]git config --get-all http.proxy
2019-12-22T11:49:43.5797478Z ##[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/67516/merge:refs/remotes/pull/67516/merge
---
2019-12-22T11:54:39.1812109Z    Compiling serde_json v1.0.40
2019-12-22T11:54:39.8486759Z    Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
2019-12-22T11:54:47.7992367Z     Finished release [optimized] target(s) in 1m 03s
2019-12-22T11:54:47.8069013Z tidy check
2019-12-22T11:54:48.4069688Z tidy error: /checkout/src/librustc_codegen_ssa/base.rs:735: line longer than 100 chars
2019-12-22T11:54:48.4069820Z tidy error: /checkout/src/librustc_codegen_ssa/base.rs:736: line longer than 100 chars
2019-12-22T11:54:49.7934059Z Found 485 error codes
2019-12-22T11:54:49.7934125Z Found 0 error codes with no tests
2019-12-22T11:54:49.7934164Z Done!
2019-12-22T11:54:49.7934215Z some tidy checks failed
2019-12-22T11:54:49.7934215Z some tidy checks failed
2019-12-22T11:54:49.7938008Z 
2019-12-22T11:54:49.7938064Z 
2019-12-22T11:54:49.7938818Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/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-12-22T11:54:49.7938929Z 
2019-12-22T11:54:49.7938949Z 
2019-12-22T11:54:49.7945002Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-12-22T11:54:49.7945256Z Build completed unsuccessfully in 0:01:06
2019-12-22T11:54:49.7945256Z Build completed unsuccessfully in 0:01:06
2019-12-22T11:54:49.7987930Z == clock drift check ==
2019-12-22T11:54:49.7995023Z   local time: Sun Dec 22 11:54:49 UTC 2019
2019-12-22T11:54:50.3205937Z   network time: Sun, 22 Dec 2019 11:54:50 GMT
2019-12-22T11:54:50.3214416Z == end clock drift check ==
2019-12-22T11:54:51.9954185Z 
2019-12-22T11:54:52.0048165Z ##[error]Bash exited with code '1'.
2019-12-22T11:54:52.0072505Z ##[section]Starting: Checkout
2019-12-22T11:54:52.0073851Z ==============================================================================
2019-12-22T11:54:52.0073893Z Task         : Get sources
2019-12-22T11:54:52.0073946Z 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)

@bjorn3
Copy link
Member

bjorn3 commented Dec 22, 2019

Not a member of rust-lang, so your r? didn't work.

Copy link
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

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

This is indeed what I had in mind in #67195 (comment).

@@ -117,6 +116,19 @@ bitflags::bitflags! {
}
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CrateNum(pub u32);
Copy link
Member

Choose a reason for hiding this comment

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

This name can be confused with def_id::CrateNum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I chose to keep the name CrateNum mainly because I feel LinkingCrateNum is misleading. LinkingCrateNum gives an impression that this "crate num" is solely for the purpose of linking, but in fact it is just for CrateInfo to index multiple crates. In addition, this new rustc_codegen_ssa::CrateNum serves the same purpose as def_id::CrateNum does under different scope; so I decided to keep its name CrateNum. While reviewing this PR, we can think about it more and find it a better name.

src/librustc_codegen_ssa/base.rs Outdated Show resolved Hide resolved
src/librustc_codegen_ssa/lib.rs Show resolved Hide resolved
@bjorn3
Copy link
Member

bjorn3 commented Dec 22, 2019

@0dvictor Could you please add changes as extra commits instead of force-pushing them while this PR is still being reviewed. Quoting @rust-highfive:

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.

@0dvictor
Copy link
Contributor Author

Could you please add changes as extra commits instead of force-pushing them while this PR is still being reviewed. Quoting @rust-highfive:

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.

Apologize for my mistake and the inconvenience. I'll definitely add any further changes as extra commits.

@bors
Copy link
Contributor

bors commented Dec 23, 2019

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

@0dvictor
Copy link
Contributor Author

Rebased to resolve merge conflicts.

@bors
Copy link
Contributor

bors commented Jan 6, 2020

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

@0dvictor
Copy link
Contributor Author

0dvictor commented Jan 8, 2020

Rebased to resolve merge conflicts.

@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-01-08T03:06:20.1881679Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-08T03:06:20.1894496Z ##[command]git config gc.auto 0
2020-01-08T03:06:20.1903083Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-08T03:06:20.1906690Z ##[command]git config --get-all http.proxy
2020-01-08T03:06:20.1911477Z ##[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/67516/merge:refs/remotes/pull/67516/merge
---
2020-01-08T03:14:14.3420493Z     Checking rustc_plugin_impl v0.0.0 (/checkout/src/librustc_plugin_impl)
2020-01-08T03:14:14.5259092Z     Checking rustc_resolve v0.0.0 (/checkout/src/librustc_resolve)
2020-01-08T03:14:17.2811536Z     Checking rustc_privacy v0.0.0 (/checkout/src/librustc_privacy)
2020-01-08T03:14:17.5313734Z     Checking rustc_codegen_ssa v0.0.0 (/checkout/src/librustc_codegen_ssa)
2020-01-08T03:14:17.7336898Z error[E0252]: the name `CrateNum` is defined multiple times
2020-01-08T03:14:17.7337892Z   --> src/librustc_codegen_ssa/back/link.rs:21:61
2020-01-08T03:14:17.7339203Z 12 | use rustc_hir::def_id::CrateNum;
2020-01-08T03:14:17.7339742Z    |     --------------------------- previous import of the type `CrateNum` here
2020-01-08T03:14:17.7340161Z ...
2020-01-08T03:14:17.7340161Z ...
2020-01-08T03:14:17.7340729Z 21 |     looks_like_rust_object_file, CodegenResults, CrateInfo, CrateNum, METADATA_FILENAME,
2020-01-08T03:14:17.7341285Z    |                                                             ^^^^^^^^ `CrateNum` reimported here
2020-01-08T03:14:17.7343092Z    = note: `CrateNum` must be defined only once in the type namespace of this module
2020-01-08T03:14:17.7343715Z help: you can use `as` to change the binding name of the import
2020-01-08T03:14:17.7344229Z    |
2020-01-08T03:14:17.7344229Z    |
2020-01-08T03:14:17.7345474Z 21 |     looks_like_rust_object_file, CodegenResults, CrateInfo, CrateNum as OtherCrateNum, METADATA_FILENAME,
2020-01-08T03:14:17.7351467Z 
2020-01-08T03:14:17.7817365Z     Checking rustc_save_analysis v0.0.0 (/checkout/src/librustc_save_analysis)
2020-01-08T03:14:17.8962590Z error: unused import: `CrateNum`
2020-01-08T03:14:17.8962590Z error: unused import: `CrateNum`
2020-01-08T03:14:17.8963739Z   --> src/librustc_codegen_ssa/back/link.rs:21:61
2020-01-08T03:14:17.8964169Z    |
2020-01-08T03:14:17.8964743Z 21 |     looks_like_rust_object_file, CodegenResults, CrateInfo, CrateNum, METADATA_FILENAME,
2020-01-08T03:14:17.8965667Z    |
2020-01-08T03:14:17.8966141Z    = note: `-D unused-imports` implied by `-D warnings`
2020-01-08T03:14:17.8966314Z 
2020-01-08T03:14:18.5320233Z error[E0308]: mismatched types
2020-01-08T03:14:18.5320233Z error[E0308]: mismatched types
2020-01-08T03:14:18.5320561Z    --> src/librustc_codegen_ssa/back/link.rs:269:11
2020-01-08T03:14:18.5320753Z     |
2020-01-08T03:14:18.5320998Z 269 |         f(cnum, &path);
2020-01-08T03:14:18.5321290Z     |           ^^^^ expected enum `rustc_hir::def_id::CrateNum`, found struct `CrateNum`
2020-01-08T03:14:18.6749183Z error[E0308]: mismatched types
2020-01-08T03:14:18.6749183Z error[E0308]: mismatched types
2020-01-08T03:14:18.6749941Z    --> src/librustc_codegen_ssa/back/link.rs:424:59
2020-01-08T03:14:18.6750356Z     |
2020-01-08T03:14:18.6750983Z 424 |         let name = &codegen_results.crate_info.crate_name[&cnum];
2020-01-08T03:14:18.6751768Z     |                                                           ^^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:18.6752757Z     = note: expected reference `&CrateNum`
2020-01-08T03:14:18.6753817Z                found reference `&rustc_hir::def_id::CrateNum`
2020-01-08T03:14:18.6753891Z 
2020-01-08T03:14:18.7999784Z error[E0308]: mismatched types
2020-01-08T03:14:18.7999784Z error[E0308]: mismatched types
2020-01-08T03:14:18.8000081Z    --> src/librustc_codegen_ssa/back/link.rs:425:72
2020-01-08T03:14:18.8000301Z     |
2020-01-08T03:14:19.3185917Z 425 |         let native_libs = &codegen_results.crate_info.native_libraries[&cnum];
2020-01-08T03:14:19.3186934Z     |                                                                        ^^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:19.3187399Z     = note: expected reference `&CrateNum`
2020-01-08T03:14:19.3187803Z                found reference `&rustc_hir::def_id::CrateNum`
2020-01-08T03:14:19.3187836Z 
2020-01-08T03:14:19.3188047Z error[E0308]: mismatched types
2020-01-08T03:14:19.3188047Z error[E0308]: mismatched types
2020-01-08T03:14:19.3188276Z    --> src/librustc_codegen_ssa/back/link.rs:453:76
2020-01-08T03:14:19.3188583Z     |
2020-01-08T03:14:19.3188902Z 453 |         all_native_libs.extend(codegen_results.crate_info.native_libraries[&cnum].iter().cloned());
2020-01-08T03:14:19.3189287Z     |                                                                            ^^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:19.3189717Z     = note: expected reference `&CrateNum`
2020-01-08T03:14:19.3190133Z                found reference `&rustc_hir::def_id::CrateNum`
2020-01-08T03:14:19.3190165Z 
2020-01-08T03:14:19.3190562Z error[E0308]: mismatched types
2020-01-08T03:14:19.3190562Z error[E0308]: mismatched types
2020-01-08T03:14:19.3190792Z    --> src/librustc_codegen_ssa/back/link.rs:753:44
2020-01-08T03:14:19.3190996Z     |
2020-01-08T03:14:19.3191270Z 753 |         && (info.compiler_builtins == Some(cnum) || info.is_no_builtins.contains(&cnum))
2020-01-08T03:14:19.3191625Z     |                                            ^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:19.3191860Z error[E0308]: mismatched types
2020-01-08T03:14:19.3191860Z error[E0308]: mismatched types
2020-01-08T03:14:19.3192078Z    --> src/librustc_codegen_ssa/back/link.rs:753:82
2020-01-08T03:14:19.3192270Z     |
2020-01-08T03:14:19.3192543Z 753 |         && (info.compiler_builtins == Some(cnum) || info.is_no_builtins.contains(&cnum))
2020-01-08T03:14:19.3192922Z     |                                                                                  ^^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:19.3193569Z     = note: expected reference `&CrateNum`
2020-01-08T03:14:19.3194003Z                found reference `&rustc_hir::def_id::CrateNum`
2020-01-08T03:14:19.3194040Z 
2020-01-08T03:14:19.3628846Z error[E0308]: mismatched types
2020-01-08T03:14:19.3628846Z error[E0308]: mismatched types
2020-01-08T03:14:19.3629313Z     --> src/librustc_codegen_ssa/back/link.rs:1416:87
2020-01-08T03:14:19.3629503Z      |
2020-01-08T03:14:19.3629790Z 1416 |                 add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, crate_type, cnum);
2020-01-08T03:14:19.3630164Z      |                                                                                       ^^^^ expected enum `rustc_hir::def_id::CrateNum`, found struct `CrateNum`
2020-01-08T03:14:19.4725000Z error[E0308]: mismatched types
2020-01-08T03:14:19.4725000Z error[E0308]: mismatched types
2020-01-08T03:14:19.4725358Z     --> src/librustc_codegen_ssa/back/link.rs:1422:81
2020-01-08T03:14:19.4725581Z      |
2020-01-08T03:14:19.4725933Z 1422 |                 link_sanitizer_runtime::<B>(cmd, sess, codegen_results, tmpdir, cnum);
2020-01-08T03:14:19.4726714Z      |                                                                                 ^^^^ expected enum `rustc_hir::def_id::CrateNum`, found struct `CrateNum`
2020-01-08T03:14:19.5854495Z error[E0308]: mismatched types
2020-01-08T03:14:19.5854495Z error[E0308]: mismatched types
2020-01-08T03:14:19.5854829Z     --> src/librustc_codegen_ssa/back/link.rs:1432:87
2020-01-08T03:14:19.5855075Z      |
2020-01-08T03:14:19.5855919Z 1432 |                 add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, crate_type, cnum);
2020-01-08T03:14:19.5856384Z      |                                                                                       ^^^^ expected enum `rustc_hir::def_id::CrateNum`, found struct `CrateNum`
2020-01-08T03:14:19.6990411Z error[E0308]: mismatched types
2020-01-08T03:14:19.6990411Z error[E0308]: mismatched types
2020-01-08T03:14:19.6990850Z     --> src/librustc_codegen_ssa/back/link.rs:1448:79
2020-01-08T03:14:19.6991063Z      |
2020-01-08T03:14:19.6991325Z 1448 |         add_static_crate::<B>(cmd, sess, codegen_results, tmpdir, crate_type, cnum);
2020-01-08T03:14:19.6991671Z      |                                                                               ^^^^ expected enum `rustc_hir::def_id::CrateNum`, found struct `CrateNum`
2020-01-08T03:14:20.3228046Z error[E0308]: mismatched types
2020-01-08T03:14:20.3228046Z error[E0308]: mismatched types
2020-01-08T03:14:20.3228333Z     --> src/librustc_codegen_ssa/back/link.rs:1471:65
2020-01-08T03:14:20.3228558Z      |
2020-01-08T03:14:20.3229184Z 1471 |         let src = &codegen_results.crate_info.used_crate_source[&cnum];
2020-01-08T03:14:20.3229534Z      |                                                                 ^^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:20.3229963Z      = note: expected reference `&CrateNum`
2020-01-08T03:14:20.3230196Z                 found reference `&rustc_hir::def_id::CrateNum`
2020-01-08T03:14:20.3230226Z 
2020-01-08T03:14:20.3230410Z error[E0308]: mismatched types
2020-01-08T03:14:20.3230410Z error[E0308]: mismatched types
2020-01-08T03:14:20.3230638Z     --> src/librustc_codegen_ssa/back/link.rs:1541:65
2020-01-08T03:14:20.3230805Z      |
2020-01-08T03:14:20.3231062Z 1541 |         let src = &codegen_results.crate_info.used_crate_source[&cnum];
2020-01-08T03:14:20.3231683Z      |                                                                 ^^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:20.3232294Z      = note: expected reference `&CrateNum`
2020-01-08T03:14:20.3232510Z                 found reference `&rustc_hir::def_id::CrateNum`
2020-01-08T03:14:20.3232540Z 
2020-01-08T03:14:20.3232746Z error[E0308]: mismatched types
2020-01-08T03:14:20.3232746Z error[E0308]: mismatched types
2020-01-08T03:14:20.3232962Z     --> src/librustc_codegen_ssa/back/link.rs:1547:72
2020-01-08T03:14:20.3233370Z      |
2020-01-08T03:14:20.3233838Z 1547 |         let native_libs = &codegen_results.crate_info.native_libraries[&cnum];
2020-01-08T03:14:20.3234320Z      |                                                                        ^^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:20.3234861Z      = note: expected reference `&CrateNum`
2020-01-08T03:14:20.3235131Z                 found reference `&rustc_hir::def_id::CrateNum`
2020-01-08T03:14:20.3235185Z 
2020-01-08T03:14:20.3235425Z error[E0308]: mismatched types
2020-01-08T03:14:20.3235425Z error[E0308]: mismatched types
2020-01-08T03:14:20.3235693Z     --> src/librustc_codegen_ssa/back/link.rs:1594:80
2020-01-08T03:14:20.3235935Z      |
2020-01-08T03:14:20.3236275Z 1594 |                         || !codegen_results.crate_info.is_no_builtins.contains(&cnum));
2020-01-08T03:14:20.3237020Z      |                                                                                ^^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:20.3237453Z      = note: expected reference `&CrateNum`
2020-01-08T03:14:20.3237686Z                 found reference `&rustc_hir::def_id::CrateNum`
2020-01-08T03:14:20.3237714Z 
2020-01-08T03:14:20.3237901Z error[E0308]: mismatched types
2020-01-08T03:14:20.3237901Z error[E0308]: mismatched types
2020-01-08T03:14:20.3238140Z     --> src/librustc_codegen_ssa/back/link.rs:1616:73
2020-01-08T03:14:20.3238314Z      |
2020-01-08T03:14:20.3238580Z 1616 |                 && codegen_results.crate_info.compiler_builtins != Some(cnum)
2020-01-08T03:14:20.3239752Z      |                                                                         ^^^^ expected struct `CrateNum`, found enum `rustc_hir::def_id::CrateNum`
2020-01-08T03:14:21.4975778Z error: aborting due to 17 previous errors
2020-01-08T03:14:21.4975930Z 
2020-01-08T03:14:21.4976249Z Some errors have detailed explanations: E0252, E0308.
2020-01-08T03:14:21.4976511Z For more information about an error, try `rustc --explain E0252`.
2020-01-08T03:14:21.4976511Z For more information about an error, try `rustc --explain E0252`.
2020-01-08T03:14:21.5133939Z error: could not compile `rustc_codegen_ssa`.
2020-01-08T03:14:21.5134026Z 
2020-01-08T03:14:21.5134294Z To learn more, run the command again with --verbose.
2020-01-08T03:14:21.5157485Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "-Zconfig-profile" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--color" "always" "--features" " llvm" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json-render-diagnostics"
2020-01-08T03:14:21.5166188Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
2020-01-08T03:14:21.5166265Z Build completed unsuccessfully in 0:05:46
2020-01-08T03:14:21.5214571Z == clock drift check ==
2020-01-08T03:14:21.5224285Z   local time: Wed Jan  8 03:14:21 UTC 2020
2020-01-08T03:14:21.5224285Z   local time: Wed Jan  8 03:14:21 UTC 2020
2020-01-08T03:14:21.8074821Z   network time: Wed, 08 Jan 2020 03:14:21 GMT
2020-01-08T03:14:21.8080034Z == end clock drift check ==
2020-01-08T03:14:22.2898641Z 
2020-01-08T03:14:22.2964648Z ##[error]Bash exited with code '1'.
2020-01-08T03:14:22.2991206Z ##[section]Starting: Checkout
2020-01-08T03:14:22.2992785Z ==============================================================================
2020-01-08T03:14:22.2992832Z Task         : Get sources
2020-01-08T03:14:22.2992870Z 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)

@0dvictor
Copy link
Contributor Author

0dvictor commented Jan 8, 2020

Rebased again to fix the error introduced by the previous rebase.

fn into(self) -> def_id::CrateNum {
def_id::CrateNum::from_u32(self.0)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is used in src/librustc_codegen_ssa/back/write.rs:995.
each_linked_rlib_for_lto.push((cnum.into(), path.to_path_buf()));

Copy link
Member

Choose a reason for hiding this comment

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

I think you should use this CrateNum for each_linked_rlib_for_lto and exported_symbols too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, updated.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 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-01-09T14:10:16.3361336Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-09T14:10:16.3449680Z ##[command]git config gc.auto 0
2020-01-09T14:10:16.3526257Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-09T14:10:16.3578131Z ##[command]git config --get-all http.proxy
2020-01-09T14:10:16.3729383Z ##[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/67516/merge:refs/remotes/pull/67516/merge

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)

@bors
Copy link
Contributor

bors commented Jan 11, 2020

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

@0dvictor
Copy link
Contributor Author

Rebased to resolve merge conflicts.

@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-01-13T02:23:53.9894103Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-13T02:23:53.9905713Z ##[command]git config gc.auto 0
2020-01-13T02:23:53.9908079Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-13T02:23:53.9910118Z ##[command]git config --get-all http.proxy
2020-01-13T02:23:53.9915568Z ##[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/67516/merge:refs/remotes/pull/67516/merge
---
2020-01-13T02:31:55.9129406Z     Checking rustc_save_analysis v0.0.0 (/checkout/src/librustc_save_analysis)
2020-01-13T02:31:56.6841119Z error[E0599]: no method named `is_sanitizer_runtime` found for type `rustc::ty::TyCtxt<'_>` in the current scope
2020-01-13T02:31:56.6841585Z    --> src/librustc_codegen_ssa/base.rs:842:20
2020-01-13T02:31:56.6841815Z     |
2020-01-13T02:31:56.6842914Z 842 |             if tcx.is_sanitizer_runtime(cnum) {
2020-01-13T02:31:56.6843363Z 
2020-01-13T02:31:56.6888873Z error[E0609]: no field `sanitizer_runtime` on type `CrateInfo`
2020-01-13T02:31:56.6889210Z    --> src/librustc_codegen_ssa/base.rs:843:22
2020-01-13T02:31:56.6889470Z     |
2020-01-13T02:31:56.6889470Z     |
2020-01-13T02:31:56.6890465Z 843 |                 info.sanitizer_runtime = Some(cnum.into());
2020-01-13T02:31:56.6891113Z     |
2020-01-13T02:31:56.6891113Z     |
2020-01-13T02:31:56.6891485Z     = note: available fields are: `panic_runtime`, `compiler_builtins`, `profiler_runtime`, `is_no_builtins`, `native_libraries` ... and 9 others
2020-01-13T02:31:57.5292904Z error: aborting due to 2 previous errors
2020-01-13T02:31:57.5293085Z 
2020-01-13T02:31:57.5293466Z Some errors have detailed explanations: E0599, E0609.
2020-01-13T02:31:57.5293764Z For more information about an error, try `rustc --explain E0599`.
2020-01-13T02:31:57.5293764Z For more information about an error, try `rustc --explain E0599`.
2020-01-13T02:31:57.5454075Z error: could not compile `rustc_codegen_ssa`.
2020-01-13T02:31:57.5454188Z 
2020-01-13T02:31:57.5454451Z To learn more, run the command again with --verbose.
2020-01-13T02:31:57.5504566Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "-Zconfig-profile" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--color" "always" "--features" " llvm" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json-render-diagnostics"
2020-01-13T02:31:57.5511974Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
2020-01-13T02:31:57.5512273Z Build completed unsuccessfully in 0:05:43
2020-01-13T02:31:57.5567256Z == clock drift check ==
2020-01-13T02:31:57.5578347Z   local time: Mon Jan 13 02:31:57 UTC 2020
2020-01-13T02:31:57.5578347Z   local time: Mon Jan 13 02:31:57 UTC 2020
2020-01-13T02:31:57.8208071Z   network time: Mon, 13 Jan 2020 02:31:57 GMT
2020-01-13T02:31:57.8208948Z == end clock drift check ==
2020-01-13T02:31:58.2242090Z 
2020-01-13T02:31:58.2349815Z ##[error]Bash exited with code '1'.
2020-01-13T02:31:58.2383815Z ##[section]Starting: Checkout
2020-01-13T02:31:58.2385471Z ==============================================================================
2020-01-13T02:31:58.2385541Z Task         : Get sources
2020-01-13T02:31:58.2385588Z 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)

@0dvictor
Copy link
Contributor Author

Rebased again to fix the error introduced by the previous rebase.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

It is unclear to me what benefits this gives us. CrateNum in rustc_hir is already fairly decoupled -- I would like to see some documentation as to the difference between this CrateNum and the one in rustc_hir. We seem to be just converting into the newly introduced CrateNum in this PR, which seems odd, as then I would expect it to be the same... but if it is, then why is there a different type?

src/librustc_codegen_ssa/base.rs Show resolved Hide resolved
@Mark-Simulacrum
Copy link
Member

cc @Centril

I'm going to assign myself as reviewer here though depending on the outcome of my questions may reassign to someone else (or suggest e.g. compiler team feedback via a design meeting).

@Mark-Simulacrum Mark-Simulacrum 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 Jan 19, 2020
@0dvictor
Copy link
Contributor Author

It is unclear to me what benefits this gives us. CrateNum in rustc_hir is already fairly decoupled -- I would like to see some documentation as to the difference between this CrateNum and the one in rustc_hir. We seem to be just converting into the newly introduced CrateNum in this PR, which seems odd, as then I would expect it to be the same... but if it is, then why is there a different type?

This PR is to resolve this comment of PR #67195. I think @bjorn3's concern is def_id::CrateNum is coupled with the compilation session, so that it is not conceptually correct when serializing CodegenResults then de-serializing it into a different compilation session. To resolve the issue, this PR creates a local CrateNum within the CodegenResults . The proposed CrateNum is no longer tied with a compilation session. and hence moving CodegenResults across compilation sessions is conceptually correct.

PR #67195 is the first step to allow splitting linker invocation from the compilation process. Therefore, one invocation of rustc serializes CodegenResults to a file in the compilation pass; then another invocation of rustc would de-serialize the file back to a CodegenResults. The two invocations would be two different compilation session.

@bjorn3: could you double check if I understand your original concern correctly?

@bjorn3
Copy link
Member

bjorn3 commented Jan 19, 2020

I think @bjorn3's concern is def_id::CrateNum is coupled with the compilation session, so that it is not conceptually correct when serializing CodegenResults then de-serializing it into a different compilation session.

Indeed, there should not be an instance of libserialize::Deserialize which doesn't remap the CrateNum as required by the current Session. Because Session will likely not exist when the linking is performed in a separate rustc invocation, this means that CrateNum as is can't be used for serializing the information required by the linking step.

Victor Ding added 2 commits January 20, 2020 10:46
`CrateNum` used inside a `CrateInfo` is self-contained and hence can be
decoupled from the compilation session. By doing so, a compilation
session can consume `CrateInfo` generated from a different compilation
session. Ultimately, it allows splitting linker invocation into a
separate compilation session.
@Mark-Simulacrum
Copy link
Member

Reading the discussion on that PR (#67195 (comment)) is somewhat helpful, in concert with your comment.

However, I still remain skeptical that this is the right approach.

In this PR, crate numbers are used within one CodegenResults, and CodegenResults only belongs to one specific session; therefore, crate numbers are unique. Then we can use CodegenResults.crate_info.used_crate_source to find the crate from a crate number.

This seems incomplete -- what are you doing with the CrateNums in that crate_info data structure? I would personally expect that if we're serializing to something like *.rlink file we'd want to encode the CrateInfo struct in a form that doesn't have crate nums (e.g., only the file paths that need to be linked or something like that).

@0dvictor
Copy link
Contributor Author

what are you doing with the CrateNums in that crate_info data structure?

It serves as unique identifiers for the crate's dependencies. Such unique identifiers do not have to be CrateNum - anything that can differentiate the dependencies would work (e.g. SVH, file path, counters etc.), but nonetheless CrateNum is the most handy one.

crate_info.used_crate_source provides a mapping table from CrateNum to CrateSource containing all dependent crates. Other fields of crate_info map CrateNum to the dependent crate's properties, for example, crate_info.compiler_builtins indicate one of the crates if a compiler builtin. Therefore, information inside crate_info is self-contained and can be used in different compilation sessions.

I would personally expect that if we're serializing to something like *.rlink file we'd want to encode the CrateInfo struct in a form that doesn't have crate nums (e.g., only the file paths that need to be linked or something like that).

Totally agree, but we still need some identifier for each dependent. Such identifier is effectively equivalent to CrateNum. For example, we could encode the .rlink file as following format:

Section used_crate_source
/path/to/dylib0 | /path/to/rlib0 | /path/to/rmeta0
/path/to/dylib1 | /path/to/rlib1 | /path/to/rmeta1
...
/path/to/dylibX | /path/to/rlibX | /path/to/rmetaX
-------------------------------------------------------
Section panic_runtime
None
-------------------------------------------------------
Section compiler_builtins
used_crate_source.entry0
-------------------------------------------------------
Section native_libraries
used_crate_source.entry5 | libc, libm
used_crate_source.entry9 | libc, pthread
-------------------------------------------------------
... other sections
-------------------------------------------------------

Entry indices to used_crate_source are effectively equivalent to CrateNum.

In addition, when decoding the .rlink file, we still have to somehow create a CrateNum unless we are open to heavily refactor existing linking code so that it doesn't use CrateNums.

@Mark-Simulacrum
Copy link
Member

Instead of having a separate CrateNum (i.e. this PR) can we do the mapping inside the serialization step for CrateInfo? AFAICT, we can deserialize and serialize CrateNum (into just u32, if necesssary) already -- just as well as this new CrateNum -- that feels sufficient to me.

@0dvictor
Copy link
Contributor Author

Definitely, and in fact it is exactly what the current version of #67195 is doing.

I’m open to either approach.

@Mark-Simulacrum
Copy link
Member

Great. Let's close this then and go with that approach, I think it's better -- at least for now.

@0dvictor 0dvictor closed this Jan 22, 2020
@0dvictor 0dvictor deleted the cratenum branch January 28, 2020 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants