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

feat(schema): add narrows edge #5773

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions kythe/docs/schema/schema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,62 @@ though the edge A' *generates* B were produced. This edge is useful in cases
where it isn't otherwise possible to produce the VName for A' and where the
span A in source text can uniquely identify A' by the *defines/binding* edge.

[[narrows]]
narrows
~~~~~~~

Brief description::
A *narrows* B if A identifies the same target language object as B but is
subject to additional constraints.
Commonly arises from::
type refinement
Points from::
variables
Points toward::
variables
Ordinals are used::
never
See also::
<<generates>>, <<typed>>

Some languages allow the types of variables to change over the course of a
program. For example, a type test can be used to narrow the type of a variable:

[source,java]
----
Object x; // x : Object
if (x instanceof String) {
x; // x : String
}
----

In this example, every `x` refers to the same variable `x`, but the `x` in
the body of the conditional has a different static type than both the `x`
in the conditional expression and the `x` declared at the top. This program
is represented in the following way:

[source,java]
----
//- @x defines/binding XObject
//- XObject typed Object
Object x;
//- @x ref XObject
if (x instanceof String) {
//- @x ref XString
//- XString narrows XObject
//- XString typed String
x;
}
----

The `x` with type `String` has no `defines/binding` edge, but is associated
with the `x` with type `Object` with the `narrows` edge. Clients should
interpret these variables as the same (in the way that nodes associated with
the `generates` edge are the same), but should prefer facts and edges from the
particular `x` being identified. In particular, `documents` edges and `code`
facts should be chosen from the particular node that is the target of a `ref`
when that node is in a `narrows` relationship.

[[named]]
named
~~~~~
Expand Down