-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate auxiliary changes from cross crate (#160)
## What Changed? These are changes and fixes from the `cross-crate` branch that are independent of cross crate analysis itself. - Factor the local analysis from `construct.rs` into its own module (`local_analysis.rs`). - Factor out the function approximations into `approximations.rs` - Additional test cases - Full caching for child graphs independent of call strings - Removal of `FnResolution`, instead expecting `Instance` everywhere. ## Why Does It Need To? Expands the test suite and lines up test cases for as-yet-unfixed issues. Makes `construct.rs` more readable and navigable. ## Checklist - [x] Above description has been filled out so that upon quash merge we have a good record of what changed. - [ ] New functions, methods, types are documented. Old documentation is updated if necessary - [x] Documentation in Notion has been updated - [x] Tests for new behaviors are provided - [ ] New test suites (if any) ave been added to the CI tests (in `.github/workflows/rust.yml`) either as compiler test or integration test. *Or* justification for their omission from CI has been provided in this PR description.
- Loading branch information
1 parent
b96d18d
commit f7c6562
Showing
33 changed files
with
2,413 additions
and
1,772 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,76 @@ | ||
use log::trace; | ||
|
||
use rustc_abi::VariantIdx; | ||
|
||
use rustc_hir::def_id::DefId; | ||
use rustc_index::IndexVec; | ||
use rustc_middle::{ | ||
mir::{visit::Visitor, AggregateKind, Location, Operand, Place, Rvalue}, | ||
ty::TyKind, | ||
}; | ||
|
||
use crate::local_analysis::LocalAnalysis; | ||
|
||
pub(crate) type ApproximationHandler<'tcx, 'a> = | ||
fn(&LocalAnalysis<'tcx, 'a>, &mut dyn Visitor<'tcx>, &[Operand<'tcx>], Place<'tcx>, Location); | ||
|
||
impl<'tcx, 'a> LocalAnalysis<'tcx, 'a> { | ||
/// Special case behavior for calls to functions used in desugaring async functions. | ||
/// | ||
/// Ensures that functions like `Pin::new_unchecked` are not modularly-approximated. | ||
pub(crate) fn can_approximate_async_functions( | ||
&self, | ||
def_id: DefId, | ||
) -> Option<ApproximationHandler<'tcx, 'a>> { | ||
let lang_items = self.tcx().lang_items(); | ||
if Some(def_id) == lang_items.new_unchecked_fn() { | ||
Some(Self::approximate_new_unchecked) | ||
} else if Some(def_id) == lang_items.into_future_fn() | ||
// FIXME: better way to get retrieve this stdlib DefId? | ||
|| self.tcx().def_path_str(def_id) == "<F as std::future::IntoFuture>::into_future" | ||
{ | ||
Some(Self::approximate_into_future) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
fn approximate_into_future( | ||
&self, | ||
vis: &mut dyn Visitor<'tcx>, | ||
args: &[Operand<'tcx>], | ||
destination: Place<'tcx>, | ||
location: Location, | ||
) { | ||
trace!("Handling into_future as assign for {destination:?}"); | ||
let [op] = args else { | ||
unreachable!(); | ||
}; | ||
vis.visit_assign(&destination, &Rvalue::Use(op.clone()), location); | ||
} | ||
|
||
fn approximate_new_unchecked( | ||
&self, | ||
vis: &mut dyn Visitor<'tcx>, | ||
args: &[Operand<'tcx>], | ||
destination: Place<'tcx>, | ||
location: Location, | ||
) { | ||
let lang_items = self.tcx().lang_items(); | ||
let [op] = args else { | ||
unreachable!(); | ||
}; | ||
let mut operands = IndexVec::new(); | ||
operands.push(op.clone()); | ||
let TyKind::Adt(adt_id, generics) = destination.ty(&self.mono_body, self.tcx()).ty.kind() | ||
else { | ||
unreachable!() | ||
}; | ||
assert_eq!(adt_id.did(), lang_items.pin_type().unwrap()); | ||
let aggregate_kind = | ||
AggregateKind::Adt(adt_id.did(), VariantIdx::from_u32(0), generics, None, None); | ||
let rvalue = Rvalue::Aggregate(Box::new(aggregate_kind), operands); | ||
trace!("Handling new_unchecked as assign for {destination:?}"); | ||
vis.visit_assign(&destination, &rvalue, location); | ||
} | ||
} |
This file contains 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 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 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.