Skip to content

Conversation

afs
Copy link
Contributor

@afs afs commented Aug 25, 2025

This PR extracts proposed scoping changes for EXISTS/NOT EXISTS.

The only content changes are in the grammar notes (9 and new note 15), and in a new entry in the table in 18.3.1 Variable Scope. This can be seen in the diff. The rest is HTML changes that make no appearance changes.


Preview | Diff

@afs afs force-pushed the exists-scoping-restrictions branch 3 times, most recently from 99d07fc to e87de02 Compare August 25, 2025 17:44
@afs afs force-pushed the exists-scoping-restrictions branch from e87de02 to b983250 Compare August 25, 2025 17:48
@afs
Copy link
Contributor Author

afs commented Aug 25, 2025

@kasei - you had some comments about text for scoping beyond just EXISTS.

This could be a good place to discuss those.

@afs afs requested a review from kasei August 25, 2025 17:52
<td>Group <code>{ P1 P2 ... }</code></td>
<td><code>v</code> is in-scope if it is in-scope in one or more of P1, P2, ...</td>
<td>Group `{ P1 P2 ... }`</td>
<td>`v` is in-scope if it is in-scope in one or more of P1, P2, ...</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<td>`v` is in-scope if it is in-scope in one or more of P1, P2, ...</td>
<td>`v` is in-scope if it is in-scope in one or more of `P1`, `P2`, ...</td>

<td><code>GRAPH term { P }</code></td>
<td><code>v</code> is <code>term</code> or <code>v</code> is in-scope in P</td>
<td>`GRAPH term { P }`</td>
<td>`v` is `term` or `v` is in-scope in P</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<td>`v` is `term` or `v` is in-scope in P</td>
<td>`v` is `term` or `v` is in-scope in `P`</td>

<td><code>{ P1 } UNION { P2 }</code></td>
<td><code>v</code> is in-scope in P1 or in-scope in P2</td>
<td>`{ P1 } UNION { P2 }`</td>
<td>`v` is in-scope in P1 or in-scope in P2</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<td>`v` is in-scope in P1 or in-scope in P2</td>
<td>`v` is in-scope in `P1` or in-scope in `P2`</td>

<td><code>OPTIONAL {P}</code></td>
<td><code>v</code> is in-scope in P</td>
<td>`OPTIONAL {P}`</td>
<td>`v` is in-scope in P</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<td>`v` is in-scope in P</td>
<td>`v` is in-scope in `P`</td>

<td><code>SERVICE term {P}</code></td>
<td><code>v</code> is <code>term</code> or <code>v</code> is in-scope in P</td>
<td>`SERVICE term {P}`</td>
<td>`v` is `term` or `v` is in-scope in P</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<td>`v` is `term` or `v` is in-scope in P</td>
<td>`v` is `term` or `v` is in-scope in `P`</td>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not part of this PR, but "v is term" here seems really strange? Am I not meant to read "term" as indicating the use of the SERVICE IRI form (which is the only one that has evaluation semantics)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the word "term" is misleading here. This part of the table should better be:

| SERVICE x { P } | v is x or v is in-scope in P |

Same issue for the case of GRAPH a bit earlier in the table.

Comment on lines +11001 to +11002
There are two entry points into the grammar: `QueryUnit` for the SPARQL query language
and `UpdateUnit` for the SPARQL update language.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There are two entry points into the grammar: `QueryUnit` for the SPARQL query language
and `UpdateUnit` for the SPARQL update language.
There are two entry points into the grammar: `QueryUnit` for the SPARQL Query language
and `UpdateUnit` for the SPARQL Update language.

@kasei
Copy link
Contributor

kasei commented Aug 26, 2025

@kasei - you had some comments about text for scoping beyond just EXISTS.

This could be a good place to discuss those.

I find this change to be VERY confusing. The existing scoping rules are all based on syntax, and can be determined statically. The new rule is:

v is in-scope if it is in-scope for the solution mapping where the expression containing EXISTS or NOT EXISTS is applied.

If I'm reading this correctly (?), this is based on runtime information about the solution mapping being used in the FILTER (or BIND, etc.) expression evaluation, which would make this rule very different from all the others.

I think what we actually want is to say that v is in-scope anywhere inside of an EXISTS AST, with the understanding that this will be true because of the translation that injects the solution mapping by way of the initial empty BGP inside of GGPs. This would be very different than all the other scoping rules which are all bottom-up, but… 🤷‍♂️

Either way, the "EXISTS and NOT EXISTS" in the "Syntax Form" column of the scoping rules table probably needs expansion to provide the details that this isn't about causing v to be in-scope for patterns that use EXISTS P but instead for patterns inside of P.

<tr>
<td>`EXISTS` and `NOT EXISTS`</td>
<td>
`v` is in-scope if it is in-scope for the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formulation is a bit weird to me because it's not defining the set of in-scope variable in the pattern like the other cases but the variable in scopes inside of any sub-pattern of the pattern.

I would rephase the sentence to something like v is in-scope of all graph pattern contained in P if v is in-cope for a solution mapping where the expression containing EXISTS P or NOT EXISTS P is applied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that weird as well. I would not include such a row in this table because the intended way to read this particular row would be very different from the way all the other rows are meant to be read.

`(expr AS v)` form. The scoping for `(expr AS v)`
applies immediately in `SELECT` expressions.
</p>
<p>In `BIND (expr AS v)` requires that the variable `v` is not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p>In `BIND (expr AS v)` requires that the variable `v` is not
<p>`BIND (expr AS v)` requires that the variable `v` is not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

Suggested change
<p>In `BIND (expr AS v)` requires that the variable `v` is not
<p>In `BIND (expr AS v)`, the variable `v` is required to not be

Comment on lines +10986 to +10989
Keywords are matched in a case-insensitive manner with the exception of
the keyword '`a`' which, in line with Turtle and N3, is used
in place of the IRI `rdf:type` (in full,
<code><a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#type">http://www.w3.org/1999/02/22-rdf-syntax-ns#type</a></code>).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The boolean sugars -- true and false -- are also case sensitive.

(I hate that these exist. We're well and truly stuck with a, which I hate almost as much, but I truly wish that true and false were treated just like any other untyped literal -- and just like any other capitalization of those words would be. Talk about a foot-gun...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants