-
Notifications
You must be signed in to change notification settings - Fork 107
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
Don't include self-references in dependency graph #458
Comments
I'm not sure... I opened 440 and 441 as separate issues to reflect two somewhat different behaviors, and because I wasn't sure if they'd necessarily be susceptible to the same solution. 441 reflects Validate correctly identifying a cyclic dependency/self reference - in coalesce(.,${foo}) - but which is actually legitimate (ie doesnt represent infinite recursion). Whereas 440 reflects Validate incorrectly identifying a cyclic dependency when in fact, due to the actual context in which the XPath expression will be evaluated - namely a specific indexed nodeset of a repeat group - it is not in fact cyclic. I think excluding self- references may well address 441, but I'm not sure in the general case it will solve XPath expressions referencing into indexed repeat groups? (I still need to wrap my head around what it'll do in this case...) |
How about we close 441 in favor of this one, and wait and see if it fixes 440 too? |
Sounds good to me! I'm pretty sure that with repeats, the unqualified (no predicates) path is used as the node in the dependency graph. In fact, I'm not sure that there's an alternative because predicates could include complex expressions. That means that for node N in a repeat, any expression including a reference to node N looks like a DAG cycle no matter what the predicate. |
Does this 'fix' mean that something like [I'm guessing probably 90% of the 'cyclic dependency' errors that Validate picks up are when the form writer inadvertently includes a self-reference in a relevant or calculate... So its actually nice if Validate could still flag these somehow, even as warnings] |
Yes, following the W3C algorithm, all self-references are allowed. I agree completely that it's rare for users to truly want self-references. In fact, I wouldn't be surprised if you're the first one! Of course that would change if |
Sorry to be the fly in the Validate ointment... ;-) So if Validate will no longer detect these self-references at all - because DAG will start allowing them - and it is quite possible that Validate's current type static checking will also have to be backed off somewhat |
Note, I think @yanokwa may have added this (ie Validate) as possible agenda topic for upcoming convening. So if we cant "sort it out amongst ourselves" here, we perhaps we can all have a, umm, 'healthy disputation' about Validate in person (over a beer, of course...) :-) My preference: Validate throws a specific warning when it detects self references (ala status quo) because these may well be indicative of a user/form design error that could potentially result in re-calculations that will never quiesce... [but strictly speaking its :-\ |
[not sure how to tap @MartijnR in github, but I'd like his view on all this...] |
So the W3C spec is pretty cut-n-dry on this... :-| So do you think its still productive to discuss this change further here, or is it really just time to raise it to TSC level for discussion as to wider impacts, and how we might mitigate them? I do feel this it the 'right' way forward - and 2 wrongs (precluding self references + once) dont make a right - and we should instead think of perhaps how we might better warn users of potentially 'bad' (eg non-aquiescing) calculations. But should we push on, or wait on making any change before having an reasonable alternative? I also dont know what additional testing might now be necessary to ensure Collect behaves nicely should it get loaded with a self-referencing, non-aquiescing form. I believe Enketo forgoes DAG in favor of re-running calculations a limited number of times (3?) before giving up if they haven't aquiesced yet... That may become necessary to do in Collect? |
In Enketo Validate we chose to completely remove self-referencing checks as well, after realizing we couldn't do them well enough and that it was therefore better not to do them at all.
It's actually browsers themselves (at least Chrome for sure) that terminate infinite loops. There is no code in Enketo that keeps track of this. |
Just a refresher on latest work on this front: We have improved the test suite around the DAG, which includes specific cases of cycles in the DAG due to self-references and chains of dependencies between vertices in the DAG (triggerables). We had to come up with specific scenarios to describe the DAGs behavior, which surfaced some inconsistencies that we should discuss:
|
All expressions that include references to form nodes are included in a dependency graph. This makes it possible to only recompute expressions when their dependencies are updated which is an important performance measure for forms with a lot of dependent logic. See the W3C XForms documentation,
IDag
andTriggerable
.Currently, when a calculation in a particular node refers to that same node, that relationship is captured by the dependency graph. This blocks usage of self-referencing expressions because the dependency graph then has a cycle in it.
The W3C XForms spec says the following:
See #440 and #441 for examples of useful self-referencing expressions.
I'm not exactly sure whether all expressions (
calculate
,relevant
, etc) on a particular node are already recomputed when that node changes so that will be something to explore.Related to #440, I believe that when expressions are in repeats or depend on values in repeats, the repeat path without any predicates is used in the dependency graph. So a change to any repeat instance will trigger recomputation. This is why computations in repeats are slow.
The text was updated successfully, but these errors were encountered: