A few changes, all bundled together: - We were getting a lot of magic applied to the predicates in the `ImportStar` module, and this was causing needless re-evaluation. To address this, the easiest solution was to simply cache the entire module. - In order to separate this from the dataflow analysis and make it dependent only on control flow, `potentialImportStarBase` was changed to return a `ControlFlowNode`. - `isDefinedLocally` was defined on control flow nodes, which meant we were duplicating a lot of tuples due to control flow splitting, to no actual benefit. Finally, there was a really bad join in `isDefinedLocally` that was fixed by separating out a helper predicate. This is a case where we could use a three-way join, since the join between the `Scope`, the `name` string and the `Name` is big no matter what. If we join `scope_defines_name` with `n.getId()`, we'll get `Name`s belonging to irrelevant scopes. If we join `scope_defines_name` with the enclosing scope of the `Name` `n`, then we'll get this also for `Name`s that don't share their `getId` with the local variable defined in the scope. If we join `n.getId()` with `n.getScope()...` then we'll get all enclosing scopes for each `Name`. The last of these is what we currently have. It's not terrible, but not great either. (Though thankfully it's rare to have lots of enclosing scopes.)
CodeQL
This open source repository contains the standard CodeQL libraries and queries that power LGTM and the other CodeQL products that GitHub makes available to its customers worldwide. For the queries, libraries, and extractor that power Go analysis, visit the CodeQL for Go repository.
How do I learn CodeQL and run queries?
There is extensive documentation on getting started with writing CodeQL. You can use the interactive query console on LGTM.com or the CodeQL for Visual Studio Code extension to try out your queries on any open source project that's currently being analyzed.
Contributing
We welcome contributions to our standard library and standard checks. Do you have an idea for a new check, or how to improve an existing query? Then please go ahead and open a pull request! Before you do, though, please take the time to read our contributing guidelines. You can also consult our style guides to learn how to format your code for consistency and clarity, how to write query metadata, and how to write query help documentation for your query.
License
The code in this repository is licensed under the MIT License by GitHub.
Visual Studio Code integration
If you use Visual Studio Code to work in this repository, there are a few integration features to make development easier.
CodeQL for Visual Studio Code
You can install the CodeQL for Visual Studio Code extension to get syntax highlighting, IntelliSense, and code navigation for the QL language, as well as unit test support for testing CodeQL libraries and queries.
Tasks
The .vscode/tasks.json file defines custom tasks specific to working in this repository. To invoke one of these tasks, select the Terminal | Run Task... menu option, and then select the desired task from the dropdown. You can also invoke the Tasks: Run Task command from the command palette.