-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add reference consistency checks #77
Comments
On Fri, Feb 2, 2018 at 10:56 PM, Robin Palotai ***@***.***> wrote:
For currently indexed module (easy): somehow report a list of missing
decls, that were targeted by refs.
Globally: less trivial. Maybe given a set of packages, only report missing
decls among these packages?
Can Kythe do any of these for us in some way (maybe in the verifier
mode?). @creachadair <https://github.com/creachadair>
In general, the graph has enough data to answer those queries provided a
semantic node can be associated with the module that defines it. For
languages that use nominal types and explicit declarations that's generally
straightforward: A typical strategy is to put the module name in the vname
path for the node, since that allows you to distinguish
structurally-similar declarations in different modules.
Note, though, that both of these queries are global: When you are indexing
module M, you do not know what refs will target definitions in M. That is
only known once you have the indexes of all the modules in the system
(e.g., your whole corpus or family of corpora, depending what you are
indexing). Once that's complete, the first query is essentially a scan
over all the entries in the forward graph, for edges like @1—ref/*—X where
X belongs to M, but there is no @2—defines/*—X located in the source text
of M. The ref edge certifies that some module refers to X, and the absence
of a source definition for X in M indicates that its declaration is
"missing".
Once you have that, constraining it to a particular set of packages is an
additional filtering step. Either way, though, you're on the hook for the
(global) scan.
None of the existing tools implements these queries, though in principle it
would not be too hard to do so. (Efficiency, of course, is a separate
matter)
It's worth pointing out, though, that this query is only well-defined if
the language supports some kind of separate compilation. In Java, for
example, you can depend on a class file which gives you sufficient
information to utter the name of (say) a method you depend on, even if you
never see a source definition of that method. That's a case where the scan
I described above would report a "missing definition". On the other hand,
Python and JavaScript do not have meaningful intermediate forms—static
analyses typically treat dependencies in source form.* In that case, it
isn't possible to utter the name of an entity without seeing a source
definition of it, and thus a missing declaration also means a missing
reference. Only languages where there's enough static information to
identify reference targets separately from their specification can really
surface this query.
So, in short: Sure, Kythe could answer those queries, but we don't have a
packaged tool for doing so at the moment.
–M
* Inventing intermediate representations for static analysis purposes is
something of a cottage industry among dynamic languages, grown ever more
popular as their proponents hit the scalability limits of what can run on
one developer's box in a large codebase.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For currently indexed module (easy): somehow report a list of missing decls, that were targeted by refs.
Globally: less trivial. Maybe given a set of packages, only report missing decls among these packages?
Can Kythe do any of these for us in some way (maybe in the verifier mode?). @creachadair
The text was updated successfully, but these errors were encountered: