-
Notifications
You must be signed in to change notification settings - Fork 77
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
Comparisons on source locations yield incorrect results #1203
Comments
The comparison operators on source locations are a bit confusing. We have discussed changing the semantics, but haven't found a good general solution. To summarize how they currently work:
Personally the second case is confusing, as what happens when the are in the same file, but not in the same set of lines? For most cases, I've ended up manually implementing the right comparison. |
@DavyLandman thanks summary / status report. Regarding 2: containment of offset/length is quite useful e.g. when reasoning over M3 models. Say I'd like to find function calls within a function body, I can query (somewhat simplified) Regarding 1: this issue is about "difference uri" not working. |
regarding 2: yup, it's useful, but if you want to see if a location occurs before another location it doesn't work. regarding 1: it does a textual comparison of the uri part of the string. so the same as |
Pardon the interjection. The underlying problem is that If it were me, I'd use |
Plus one on the |
I like that idea as well |
I think there is confusion here:
I have been thinking about a library module for source locations that has function like:
Would this not lead to more precise and more easily understandable operations on locations? |
I think that’s fine as well. I know that the operator syntax for location comparisons was added later, and I’m fine with this being supported by a library instead. That may be better, since it prevents users from importing their own view of what “less than” means (for instance). Regardless, the current semantics are confusing, so I think it would even be an improvement to just fix that in the short term. |
I fully agree that the current situation needs improvement. |
We should definitely be a lot more clear about the Semantics of < in the documentation. It is only total on numbers and strings, or tuples and lists which can reach eventually only numbers and strings and lists and tuples. For the other datatypes < is partial. We had to adapt the sort function to properly deal with partial orderings. What a "natural ordering" for source locations is, is debatable. The URI part can be totally ordered lexicographically, which makes sense. The offset-length thing will always be a point of discussion. as they can be considered to be "ranges" it makes sense to order them via an inclusion lattice just like we did with sets. However, other applications want to strictly know that something started before something else and that is not the Semantics of range inclusion. Since this has generated so much confusion over the years I'm inclined to propose a complete lexicographic ordering where the numbers of offsets and lengths are simple ordered pairwise like numbers and from left to right: offset first, then length. This is pretty meaningless but consistent. For more Semantics when sorting, one can project the offset and length fields and create one's own ordering function to pass to sort. |
According to the documentation
<
on source locations is assumed to exhibit the following behaviour (although it doesn't on Rascal Version: 0.11.1-SNAPSHOT):The text was updated successfully, but these errors were encountered: