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
#14902 Write a MIR lint for rooting analysis #20264
Closed
+688
−191
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
89177a7
#14902 Write a MIR lint for rooting analysis
mrowqa ea0c1d4
Skip checking subexpressions (temporary variables).
mrowqa 011217b
Further progress (theoretically it should be able to detect some impr…
mrowqa 4169308
Moved forward with generics checking & refactored the code
mrowqa 41f4774
Calls to generic functions should be detected
mrowqa d5eafe0
Generic ADT with unrooted substs are detected.
mrowqa 2f4af72
Checking recursively parent generics + some proof work for allowing n…
mrowqa 53ed102
Updated way of detecting "new" methods and added test for closures.
mrowqa c6d04fa
Fixed problem with unrooted interior.
mrowqa 88a1814
Merge branch 'master' into mir-must-root
mrowqa c1e333b
Fixed generating traits by codegen.
mrowqa 2f767d2
Fixed some #[must_root] errors and added debugging code.
mrowqa 2416333
Fixed more violations.
mrowqa 3c14830
Added more exceptions to the plugin; servo should compile
mrowqa fc4c611
Temporarily commented out one test
mrowqa File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Calls to generic functions should be detected
- Loading branch information
commit 41f4774a7f4400ec7a4d5572195f6e25691b336b
| @@ -177,8 +177,6 @@ impl<'a, 'b, 'tcx> UnrootedCx<'a, 'b, 'tcx> { | ||
| }, | ||
| ty::TyParam(param_ty) => { | ||
| let ty_param_def = cx.tcx.generics_of(self.def_id).type_param(¶m_ty, cx.tcx); | ||
| // will work for `foo::<Foo>(..)` | ||
| // but won't get enough information in `bar<T>(){foo::<T>(..);}`? | ||
| if cx.tcx.has_attr(ty_param_def.def_id, "must_root") { | ||
| ret = true; | ||
| false | ||
| @@ -212,4 +210,32 @@ impl<'a, 'b, 'tcx> MirVisitor<'tcx> for MirFnVisitor<'a, 'b, 'tcx> { | ||
| _ => {}, | ||
| } | ||
| } | ||
|
|
||
| fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: mir::Location) { | ||
| self.super_constant(constant, location); | ||
|
|
||
| let ur_cx = &self.unrooted_cx; | ||
| let cx = ur_cx.late_cx; | ||
| match constant.ty.sty { | ||
| ty::TyFnDef(callee_def_id, callee_substs) => { | ||
| let callee_generics = cx.tcx.generics_of(callee_def_id); | ||
| for ty_param_def in &callee_generics.types { | ||
| // If type has `#[must_root]`, then it is ok to | ||
| // give it a must-root type, so just skip. | ||
| if cx.tcx.has_attr(ty_param_def.def_id, "must_root") { | ||
| continue; | ||
| } | ||
|
|
||
| let arg_ty = callee_substs.type_at(ty_param_def.index as usize); | ||
| if ur_cx.is_unrooted_ty(arg_ty, false) { | ||
| cx.span_lint(UNROOTED_MUST_ROOT, constant.span, "Callee generic type must be rooted.") | ||
| } | ||
| } | ||
| } | ||
| ty::TyAdt(_, _) => { | ||
| cx.span_lint(UNROOTED_MUST_ROOT, constant.span, "xd") | ||
mrowqa
Author
|
||
| } | ||
| _ => { } | ||
| } | ||
| } | ||
| } | ||
ProTip!
Use n and p to navigate between commits in a pull request.
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.
you probably don't need this here -- this corresponds to a constant value of ADT type, e.g.
const FOO: Option<i32> = Some(22)or something. This arm is checking the final type of the constant, and I think that's better done elsewhere. We only wanted to catch the case where we are supply unsuitable values for#[must_root]type parameters.