Change .location, NewLocation, and Location to lazily compute location information#5482
Change .location, NewLocation, and Location to lazily compute location information#5482ashfordium wants to merge 12 commits intojoernio:masterfrom ashfordium:flanders/lazyloc
.location, NewLocation, and Location to lazily compute location information#5482Conversation
itsacoderepo
left a comment
There was a problem hiding this comment.
Sorry for the short comment. Please don't merge this, we need to discuss it first.
|
Why do we need to deprecate the |
fabsx00
left a comment
There was a problem hiding this comment.
I don't think we should deprecate .location in favour of .loc. Is it not possible to simply adapt the old implementation but keep the name? Also, can you motivate why this change is necessary in the first place?
@fabsx00, sorry, I did not see your earlier mesage. This is an attempt at a more efficient implementation of I had an internal issue assigned to me, IIUC deprecating instead of replacing the |
|
After some discussion: there are understandably some problems with the name |
|
It was decided that we will replace |
expected usage is to provide a new LocCreator and a new deriving class of LazyLoc
Make `.loc` also handle the case where node in NodeMethods is not StoredNode and returns an empty location info similar to `.location`.
Address review comments
|
Pushed some changes to make this nicer to use as a consumer of joern that extends the codepropertygraph / location types. It is nicer in that both the joern location types and any extended location types can both be wildcard imported, but the extended location types will be used by the implicits because of the way extending the location information uses subclassing. Say that you have a package, and everything works as expected even if node is an extended node type. Similarly, if you import both the location types in joern and the location types in the extending and consuming library, then the implicit location creator in the extending and consuming library will be chosen since it will be more specific with this design. So this works as expected: The location will be |
.loc and Loc over .location and {New}Location.location, NewLocation, and Location to lazily compute location information
| // Previously, the non-stored Location node generated | ||
| // from the CPG schema was named NewLocation. The | ||
| // addition of lazily computed location info in this | ||
| // file brought the deletion of these CPG nodes. This | ||
| // is not directly used in joern, but intended to not | ||
| // break usage in users of the API. Users directly | ||
| // importing NewLocation from the CPG package rather | ||
| // will still have a break. | ||
| @deprecated("NewLocation is deprecated, prefer LocationInfo") | ||
| type NewLocation = LocationInfo |
There was a problem hiding this comment.
So the scenario here is that people only have to adjust den import but not the other references to NewLocation in there code?
| override def location: NewLocation = | ||
| LocationCreator.defaultCreateLocation(node) | ||
| override def location: LocationInfo = { | ||
| node.location |
There was a problem hiding this comment.
This should be a recursive call to location, at least my IDE agrees with me.
Same applies to the other XXXMethods.scala files except for NodeMethods.scala.
I think we do not even need all those overrides anymore. It is enough to have location defined in NodeMethods.
| trait HasLocation extends Any { | ||
| def location: LocationInfo | ||
| } |
There was a problem hiding this comment.
Do we still need this? I have not seem a usage in Joern or CS repo outside of declarations.
Locclass as replacement forLocationCreatorand thelocationnode step.Locis a replacement that is meant to compute and store less up-front compared toLocationCreatorandlocation. IIUC, scala lazy values also take up space, so I eyeballed the operations that might take more steps to compute and made those lazy and those that are just lookups on the underlying node and made these methods.c2cpgtest files to useLocrather than replacing the other tests for now