Skip to content

check for unused bindings #255

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

Merged
merged 15 commits into from
Mar 21, 2021
Merged

check for unused bindings #255

merged 15 commits into from
Mar 21, 2021

Conversation

ZacLN
Copy link
Contributor

@ZacLN ZacLN commented Feb 1, 2021

Needs some finessing:

  • special handling for loops
  • do backwards/forward looks for overwritten bindings

@ZacLN ZacLN added this to the Next Minor milestone Feb 1, 2021
@ZacLN ZacLN self-assigned this Feb 1, 2021
function is_overwritten_in_loop(x)
# Cuts out false positives for check_unused_binding - the linear nature of our
# semantic passes mean a variable declared at the end of a loop's block but used at
# the start won't appear to be referenced.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, but isn't that in line with how Julia's loops work?

julia> for i in 1:3
         if i > 2
           println(x)
         end
         x = i
       end
ERROR: UndefVarError: x not defined

So we only need to check if the variable being assigned is used in a enclosing scope, as you mention below?

Copy link
Contributor Author

@ZacLN ZacLN Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that i did not know!

EDIT: Though thankfully the it doesn't actually check this. For info, these checks don't run on the toplevel scope so you need to wrap the above example in a function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter whether it's in a top-level scope or not, afaict:

julia> function f()
         for i in 1:3
           if i > 2
             println(x)
           end
           x=i
         end
       end
f (generic function with 1 method)

julia> f()
ERROR: UndefVarError: x not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant for the StaticLint checks

@ZacLN ZacLN merged commit 0a5cbbd into master Mar 21, 2021
@ZacLN ZacLN deleted the unused-binding branch March 21, 2021 11:10
@oppo-source oppo-source removed the request for review from a team April 16, 2021 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants