-
Notifications
You must be signed in to change notification settings - Fork 16
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
getInputs(..., recursive = TRUE, envir = parent.frame()) #19
Comments
Oops, I forgot to write the actual desired result the first time. Please see the " |
+1 This would be useful for me. |
Well, global variables such as my_var are far from ideal. So not best practice for writing code. |
I agree that global non-function global variables are bad practice. Unfortunately, though, I have seen it in code. Personally, I do not mind that some dependencies are conditional, and I would be okay if they mixed with unconditional dependencies. It would seem difficult to detect the distinction in static code analysis. |
In my mind there is a big distinction between static code analysis and looking at 'live' code. @wlandau-lilly wrote:
This could essentially be done statically by only recursing into functions defined in the Regarding conditional dependencies, the conservative thing is to explore all the branches (perhaps with the exclusion of a literal
Here is a recursive version based on |
It would also be useful to dig deeper for dependencies inside a package environment. |
Hi, so apologies not weighing in on this at the time. I'm basically in complete agreement with @clarkfitzg here. Static analysis means not requiring the resolution of symbols (which can only be done completely correctly by loading all the correct packages and making all the relevant actual calls). Now there are corner cases when we already break the static code analysis shouldn't even require an evaluation engine to be present rule. The one that comes to mind is the stuff I put in for calls to data(), in order to determine the outputs of such calls and thus get the dependency chain right we do have to actually perform the data calls. I don't think want to be in this business in the general case though. That said, I also agree that as a new (quite major) feature, we could add reasoning about nesting of user/script defined functions. We could prototype something like this as a second pass with what we have now:
Now there are places where I'm pretty sure this going to get things wrong, ie situations which look like global variables but are actually defined in a higher (or is it lower, I can never remember) call frame so won't need to go all the way to the user environment to resolve.
Also, we have a bit of a problem defining things as inputs during function definition. It's really the only thing we can do right, but they aren't actually inputs until the function is called, so them not existing when it is defined isn't the problem CodeDepends is likely to think it is when looking at expression dependency. We could get better at handling this but the way I can see for doing that off the top of my head would require a new piece of information, something like a funcBodyGlobals slot. We could then add these as inputs to the function call expression which would be more correct for dependency detection. That said I have to admit this doesn't seem like a huge priority given what @duncantl pointed out in this thread initially: generally globals-using functions shouldn't occur and so perhaps surfacing such problems, rather than enabling them, is sufficient for now? |
Sounds like a reasonable consequence of being static.
That would cover the overwhelming majority of my own use cases.
Absolutely. There is no rush on any of this, and just understanding the constraints of |
It would be really handy to dig deeper for dependencies. I think it would be enough to limit recursion to the user's environment. Desired behavior:
The text was updated successfully, but these errors were encountered: