-
Notifications
You must be signed in to change notification settings - Fork 100
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 initial implementation of the reachability algorithm #1683
Conversation
TODO: - Cleanup the code. - Add more tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, @celinval! A few minor comments.
let src_ty_inner = find_pointer(tcx, src_ty); | ||
|
||
trace!(?dst_ty_inner, ?src_ty_inner, "find_trait_conversion"); | ||
(vtable_metadata(dst_ty_inner) && !vtable_metadata(src_ty_inner)).then(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this line mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the same as:
if cond {
Some(val)
} else {
None
}
} | ||
} | ||
|
||
impl<'tcx> Iterator for ReceiverIter<'tcx> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This level of inner impls makes my head hurt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this code needs some polishing for sure. I'll create another issue to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move these definitions to be out of the function. I also need to rewrite how we're handling unsized coercion to support custom smart pointers. I created #1683 to capture this work.
Thus, we no longer print "Failed to compile crate"
if items.is_empty() { | ||
// There's nothing to do. | ||
return codegen_results(tcx, rustc_metadata, gcx.symbol_table.machine_model()); | ||
} | ||
|
||
// we first declare all functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare all "items"
codegen_units | ||
.iter() | ||
.flat_map(|cgu| cgu.items_in_deterministic_order(tcx)) | ||
.map(|(item, _)| item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
let harnesses = collect_harnesses(tcx, gcx); | ||
collect_reachable_items(tcx, &harnesses).into_iter().collect() | ||
} | ||
ReachabilityType::None => Vec::new(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment that?
|
||
impl<'tcx> MonoItemsCollector<'tcx> { | ||
/// Collects all reachable items starting from the given root. | ||
pub fn collect(&mut self, root: MonoItem<'tcx>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// Collect drop function. | ||
let static_ty = instance.ty(self.tcx, ParamEnv::reveal_all()); | ||
let instance = Instance::resolve_drop_in_place(self.tcx, static_ty); | ||
self.queue.push(MonoItem::Fn(instance.polymorphize(self.tcx))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know!
Description of changes:
Add a new module
reachability
which implements the reachability algorithm. Add the end to end logic for the reachability starting from all the harnesses in the target crate.Resolved issues:
Resolves #1672
Related RFC:
Optional #1588
Call-outs:
compiletest
.cargo-kani/asm/global_error/doesnt_call_crate_with_global_asm.expected
: The global assembly is out of the scope so it doesn't get processed. If we want to keep that behavior, we will have to inspect all items manually.cargo-kani/cargo-tests-dir/expected
: This might be a legit issue that I need to fix onkani-driver
logic.cargo-ui/dry-run/expected
: Not an issue (arguments to the compiler changes).Testing:
How is this change tested? New tests + manually run the regression with
RUSTFLAGS=--cfg=mir_linker
Is this a refactor change? No
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.