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

Make unrooted_must_root a bit more aggressive. #8073

Merged
merged 2 commits into from Oct 25, 2015

Conversation

@eefriedman
Copy link
Contributor

eefriedman commented Oct 18, 2015

Basically, instead of trying to check for specific kinds of statements,
just check the types of all local variables.

Also included are some commented-out proposals for some slightly more
aggressive lints which might be useful (but trigger a little too
frequently at the moment).

Review on Reviewable

@eefriedman eefriedman force-pushed the eefriedman:root-lint branch from ec7487c to 487984a Oct 18, 2015
@@ -18,6 +18,7 @@ pub struct FileList {
}

impl FileList {
#[allow(unrooted_must_root)]
fn new_inherited(files: Vec<JS<File>>) -> FileList {

This comment has been minimized.

Copy link
@nox

nox Oct 19, 2015

Member

Anything named new or new_something is supposed to get automatically white-listed, weird that you had to add these.

This comment has been minimized.

Copy link
@Manishearth

Manishearth Oct 19, 2015

Member

No, only box unrooted is safe in new, everything else isn't.

In this case it's the pat from the argument list that's being caught. It wasn't caught in the past since check_fn is not run on new_*.

This can be fixed by adding another state to the lint, "in_argument_list", which is set unconditionally by check_fn and turned off by check_block, and bailing in check_pat when in_new_function && in_argument_list

@nox
Copy link
Member

nox commented Oct 19, 2015

cx.span_lint(UNROOTED_MUST_ROOT, expr.span,
&format!("Expression of type {:?} must be rooted", ty))
fn check_pat(&mut self, cx: &LateContext, pat: &hir::Pat) {
if let hir::PatIdent(hir::BindByValue(_), _, _) = pat.node {

This comment has been minimized.

Copy link
@Manishearth

Manishearth Oct 19, 2015

Member

This won't catch let (a, b, c) = foo(); We should allow any pat here I guess?

This comment has been minimized.

Copy link
@eefriedman

eefriedman Oct 19, 2015

Author Contributor

check_pat gets called for every hir::Pat in the tree, so we would end up checking a, b, and c individually. (This also allows us to avoid false positives involving by-ref matches.)

This comment has been minimized.

Copy link
@Manishearth

Manishearth Oct 19, 2015

Member

Oh, right, sorry.

But then, this would catch let ref a = b. It shouldn't.

This comment has been minimized.

Copy link
@Manishearth

Manishearth Oct 19, 2015

Member

Oh, no it won't. sorry.

This comment has been minimized.

Copy link
@eefriedman

eefriedman Oct 19, 2015

Author Contributor

pat_ty_opt returns the type of the variable in let ref a = b, so it works correctly.

@Manishearth
Copy link
Member

Manishearth commented Oct 19, 2015

Mostly looks good. Just need to add the second state variable for ignoring function arguments, and make the pat check handle all pats.

The alternative to the state variable is to keep check_stmt, move the ExprAssign/ExprMatch out into check_expr, along with an ExprClosure check. This will handle all possible forms of bindings without touching function bindings.

@eefriedman eefriedman force-pushed the eefriedman:root-lint branch from 487984a to b1210f9 Oct 19, 2015
@eefriedman
Copy link
Contributor Author

eefriedman commented Oct 19, 2015

Came up with a different solution for ignoring function arguments: using a nested visitor. This is a bit more convenient for a couple reasons: it makes it easier to ensure the lint only sees patterns which actually represent variables, and it handles nested function definitions more correctly.

@Manishearth
Copy link
Member

Manishearth commented Oct 19, 2015

Note that this might affect compile times. The regular lint is implemented as a visitor which runs threaded together with the other lints. A separate visitor might make things slower. But we're not doing any crazy computations here so we should be fine.

@Ms2ger
Copy link
Contributor

Ms2ger commented Oct 20, 2015

How is JS<T> in function arguments safe?

@Manishearth
Copy link
Member

Manishearth commented Oct 20, 2015

@Ms2ger It's not, but we need to ignore it for new_*() functions

@jdm
Copy link
Member

jdm commented Oct 20, 2015

@Manishearth I thought the goal was to suppress the error for return values for such functions; I don't recall any discussion about the function arguments.

@Manishearth
Copy link
Member

Manishearth commented Oct 20, 2015

Okay, we can turn on warnings for the argument list then.

@eefriedman
Copy link
Contributor Author

eefriedman commented Oct 20, 2015

I'm not exactly sure how the argument list is any worse than the return type? Conceptually, functions should always return a rooted value.

Anyway, I'll change it.

@eefriedman eefriedman force-pushed the eefriedman:root-lint branch from b1210f9 to 81701a5 Oct 20, 2015
@eefriedman
Copy link
Contributor Author

eefriedman commented Oct 20, 2015

Updated.

@jdm
Copy link
Member

jdm commented Oct 20, 2015

@eefriedman The exception for the return value for new_inherited methods is for constructing the base types for derived interfaces, which are stored as Foo instead of JS<Foo>.

@eefriedman
Copy link
Contributor Author

eefriedman commented Oct 23, 2015

@Manishearth Ping.

@bors-servo
Copy link
Contributor

bors-servo commented Oct 23, 2015

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

eefriedman added 2 commits Oct 18, 2015
Basically, instead of trying to check for specific kinds of statements,
just check the types of all local variables.

Also included are some commented-out proposals for some slightly more
aggressive lints which might be useful (but trigger a little too
frequently at the moment).
@eefriedman eefriedman force-pushed the eefriedman:root-lint branch from 81701a5 to a9ef40c Oct 23, 2015
@eefriedman
Copy link
Contributor Author

eefriedman commented Oct 23, 2015

Rebased.

@Manishearth
Copy link
Member

Manishearth commented Oct 24, 2015

Reviewed 4 of 8 files at r1, 4 of 4 files at r2, 5 of 5 files at r3.
Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


components/plugins/lints/unrooted_must_root.rs, line 40 [r2] (raw file):
Should be false by default?


Comments from the review on Reviewable.io

@eefriedman
Copy link
Contributor Author

eefriedman commented Oct 24, 2015

Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


components/plugins/lints/unrooted_must_root.rs, line 40 [r2] (raw file):
What should be false by default? This code doesn't exist with my patch. My current approach doesn't try to check code outside of a function definition; it generally can't contain any relevant code.


Comments from the review on Reviewable.io

@Manishearth
Copy link
Member

Manishearth commented Oct 24, 2015

@bors-servo retry

It's asking for a license fix. Tried to ssh and fix it, but it seems like the admin password was updated.

@bors-servo
Copy link
Contributor

bors-servo commented Oct 24, 2015

Testing commit a9ef40c with merge 77dee47...

bors-servo added a commit that referenced this pull request Oct 24, 2015
Make unrooted_must_root a bit more aggressive.

Basically, instead of trying to check for specific kinds of statements,
just check the types of all local variables.

Also included are some commented-out proposals for some slightly more
aggressive lints which might be useful (but trigger a little too
frequently at the moment).

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 24, 2015

💔 Test failed - mac-rel-wpt

@Manishearth
Copy link
Member

Manishearth commented Oct 24, 2015

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Oct 24, 2015

Testing commit a9ef40c with merge 49d5245...

bors-servo added a commit that referenced this pull request Oct 24, 2015
Make unrooted_must_root a bit more aggressive.

Basically, instead of trying to check for specific kinds of statements,
just check the types of all local variables.

Also included are some commented-out proposals for some slightly more
aggressive lints which might be useful (but trigger a little too
frequently at the moment).

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 24, 2015

💔 Test failed - mac-rel-css

@Manishearth
Copy link
Member

Manishearth commented Oct 24, 2015

@bors-servo
Copy link
Contributor

bors-servo commented Oct 24, 2015

Testing commit a9ef40c with merge e66825e...

bors-servo added a commit that referenced this pull request Oct 24, 2015
Make unrooted_must_root a bit more aggressive.

Basically, instead of trying to check for specific kinds of statements,
just check the types of all local variables.

Also included are some commented-out proposals for some slightly more
aggressive lints which might be useful (but trigger a little too
frequently at the moment).

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073)
<!-- Reviewable:end -->
@frewsxcv frewsxcv closed this Oct 24, 2015
@frewsxcv frewsxcv reopened this Oct 24, 2015
@Manishearth
Copy link
Member

Manishearth commented Oct 24, 2015

@frewsxcv Nothing's going to work till the builders come back

@bors-servo
Copy link
Contributor

bors-servo commented Oct 25, 2015

Testing commit a9ef40c with merge bb88832...

bors-servo added a commit that referenced this pull request Oct 25, 2015
Make unrooted_must_root a bit more aggressive.

Basically, instead of trying to check for specific kinds of statements,
just check the types of all local variables.

Also included are some commented-out proposals for some slightly more
aggressive lints which might be useful (but trigger a little too
frequently at the moment).

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 25, 2015

@bors-servo bors-servo merged commit a9ef40c into servo:master Oct 25, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.