-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Relink don't rebuild: add a baseline, sound implementation that can be incrementally improved #155871
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
Open
susitsm
wants to merge
15
commits into
rust-lang:main
Choose a base branch
from
susitsm:relink-dont-rebuild-base
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Relink don't rebuild: add a baseline, sound implementation that can be incrementally improved #155871
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f877fb4
rdr: add RDRHashes field to CrateRoot
susitsm 27034fc
rdr: add public_api_hash unstable option
susitsm 5612408
derive HashStable for TargetModifier
susitsm 9db9131
derive HashStable for DeniedPartialMitigation
susitsm 9132e4b
rdr: implement rmeta public api hash as the stable hash of (almost) a…
susitsm 1ce1fe3
rdr: hash spans as if they had no parents (spans are encoded into the…
susitsm bc16057
rdr: add the public_api_hash query. Queries provided by rmeta now dep…
susitsm 280b75e
rdr: remove crate_hash from public api hash
susitsm 68bf2d4
rdr: add public api hash debug logs
susitsm 3170ab0
rdr: add rustc_public_hash_unchanged and rustc_public_hash_changed at…
susitsm a5d94e2
rdr: add incremental test exercising rustc_public_hash_changed and ru…
susitsm 8d4b5db
rdr: use public_api_hash when hashing dependencies
susitsm bd4ea04
rdr: elaborate on how EII-s should be included in the public api hash
susitsm dcfff37
rdr: document the process of hashing new fields added to CrateRoot
susitsm 981dee4
rdr: add comments indicating that public api hashing must be updated …
susitsm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ mod data; | |
| mod file_format; | ||
| mod fs; | ||
| mod load; | ||
| mod rdr_hashes; | ||
| mod save; | ||
| mod work_product; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use rustc_hir::attrs::RDRFields; | ||
| use rustc_hir::def_id::LOCAL_CRATE; | ||
| use rustc_hir::find_attr; | ||
| use rustc_macros::Diagnostic; | ||
| use rustc_middle::dep_graph::{DepKind, DepNode}; | ||
| use rustc_middle::ty::TyCtxt; | ||
| use rustc_span::{Span, Symbol}; | ||
| use tracing::debug; | ||
|
|
||
| pub(crate) fn check_rdr_test_attrs(tcx: TyCtxt<'_>) { | ||
| // can't add the attributes without opting into this feature | ||
| if !tcx.features().rustc_attrs() { | ||
| return; | ||
| } | ||
| for &(span, fields) in | ||
| find_attr!(tcx.hir_attrs(rustc_hir::CRATE_HIR_ID), RustcRDRTestAttr(e) => e) | ||
| .into_iter() | ||
| .flatten() | ||
| { | ||
| assert_dependency_public_hash(tcx, span, fields); | ||
| } | ||
| } | ||
|
|
||
| #[derive(Diagnostic)] | ||
| #[diag("found rdr hash attribute but `-Zquery-dep-graph` was not specified")] | ||
| pub(crate) struct MissingQueryDepGraph { | ||
| #[primary_span] | ||
| pub span: Span, | ||
| } | ||
|
|
||
| /// Scan for a `cfg="foo"` attribute and check whether we have a | ||
| /// cfg flag called `foo`. | ||
| fn check_config(tcx: TyCtxt<'_>, value: Symbol) -> bool { | ||
| let config = &tcx.sess.config; | ||
| debug!("check_config(config={:?}, value={:?})", config, value); | ||
| if config.iter().any(|&(name, _)| name == value) { | ||
| debug!("check_config: matched"); | ||
| return true; | ||
| } | ||
| debug!("check_config: no match found"); | ||
| false | ||
| } | ||
|
|
||
| fn assert_dependency_public_hash(tcx: TyCtxt<'_>, span: Span, fields: RDRFields) { | ||
| if !tcx.sess.opts.unstable_opts.query_dep_graph { | ||
| tcx.dcx().emit_fatal(MissingQueryDepGraph { span }); | ||
| } | ||
|
|
||
| let crate_num = tcx | ||
| .crates(()) | ||
| .iter() | ||
| .copied() | ||
| .find(|&cnum| tcx.crate_name(cnum).as_str() == fields.crate_name.as_str()) | ||
| .unwrap_or_else(|| { | ||
| tcx.dcx().span_fatal( | ||
| span, | ||
| format!("crate `{}` not found in dependencies", fields.crate_name), | ||
| ) | ||
| }); | ||
| if crate_num == LOCAL_CRATE { | ||
| tcx.dcx().span_fatal(span, "expected the name of a dependency crate"); | ||
| } | ||
|
|
||
| if !check_config(tcx, fields.cfg) { | ||
| debug!("check_attr: config does not match, ignoring attr"); | ||
| return; | ||
| } | ||
|
|
||
| let green = !fields.changed; | ||
| let dep_node = DepNode::construct(tcx, DepKind::public_api_hash, &crate_num); | ||
| let is_green = tcx.dep_graph.is_green(&dep_node); | ||
| let is_red = tcx.dep_graph.is_red(&dep_node); | ||
| if !is_red && !is_green { | ||
| tcx.dcx().span_fatal(span, "dependency color is neither red or green!"); | ||
| } | ||
|
|
||
| if green && !is_green { | ||
| tcx.dcx().span_fatal( | ||
| span, | ||
| "expected dependency to be unchanged (green) but it was changed (red)", | ||
| ); | ||
| } else if !green && is_green { | ||
| tcx.dcx().span_fatal( | ||
| span, | ||
| "expected dependency to have changed (red) but it was unchanged (green)", | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.