Segfault with cyclic requirements in self-provided goods
Potential added complexity: If a ruleset author wants goods that are already mutually exclusive due to other requirements (so the infinite recursion can never happen), but also wants importing one of them to disable the other, e.g.
[goods_wetness] name = _("Wetness") reqs = { "type", "name", "range", "present" "TerrainClass", "Oceanic", "Adjacent", TRUE "Good", "Dryness", "City", FALSE } flags = "Self-Provided" [goods_dryness] name = _("Dryness") reqs = { "type", "name", "range", "present" "TerrainClass", "Oceanic", "Adjacent", FALSE "Good", "Wetness", "City", FALSE } flags = "Self-Provided"i.e. a city can only export authentic Wetness when it's next to the ocean and doesn't import Dryness, and it can only export authentic Dryness when it's landlocked and doesn't import Wetness.
Allowing this would make load-time sanity checks more complicated.
Yup, I'm quite annoyed with myself. Multiple time I've been looking in to need of Self-Provided goods, to then realize that it would cause recursion problems and reject the idea. Forget that in a couple of months and start from the beginning...
One possible solution still is that we simple revert Self-Provided goods. We need at least to make a decision about that before S3_2 d3f.
This is not the first recursive requirement (though I don't remember the other one(s) from the top of my head). The sanity check should be generic enough to catch any complex infinite recursion over different requirement types (Good 1 requirement -> Type B requirement -> Good 2 requirement -> Type C requirement -> Good 1 requirement)
Reply To cazfi
This is not the first recursive requirement (though I don't remember the other one(s) from the top of my head). The sanity check should be generic enough to catch any complex infinite recursion over different requirement types (Good 1 requirement -> Type B requirement -> Good 2 requirement -> Type C requirement -> Good 1 requirement)
Even if it is generic enough, that only really works fine for the case where at every step along that chain, the relevant requirement (whether present or not) can only be fulfilled in one specific way – in more general cases (like the example above) the sanity check would have to realize, based on the contradictory terrain class requirements, that infinite recursion isn't possible... until we evaluate against something where the terrain class requirements become TRI_MAYBE and we have to recurse into the goods requirement anyway. Hm.
Point is, if we want to make this sanity check without being overly restrictive, it'd have to explore a (possibly very large) tree of ways that certain requirements (particularly negated ones) could be fulfilled, while keeping in mind all the facts that already have to be given to even reach that test. I'm not sure that's such a sensible thing to do.
So really, the two options we have (as far as I can tell) are
The latter would also mean we'd have to decide on what to do in case of infinite recursion – in particular, when something negatively depends on itself.
Created a meta-ticket about the infinite-recursion with requirements cases we have -> #45974
S3_2 d3f approaches, and we have to make a decision about this. Assuming nobody will suddenly come up with a proper solution, we must either revert Self-Provided goods, or to accept that there might be an infinite recursion. Latter option could be justified by the fact that this is not the only such infinite recursion case we have, and we have accepted those other ones.
Reply To cazfi
Assuming nobody will suddenly come up with a proper solution
Whether it qualifies as "proper" shall be for posterity to judge, but with https://redmine.freeciv.org/issues/554 (runtime recursion check) I don't think there's any reason to revert Self-Provided goods now.
Reply To alienvalkyrie
Reply To cazfi
Assuming nobody will suddenly come up with a proper solution
Whether it qualifies as "proper" shall be for posterity to judge, but with https://redmine.freeciv.org/issues/554 (runtime recursion check) I don't think there's any reason to revert Self-Provided goods now.
We believe we get https://redmine.freeciv.org/issues/554 to work. If we don't, then we can live with the fact that there's possibility for the users to create rulesets with infinite recursion -> I'm inclined to take the risk, and close this ticket from blocking d3f.
With the self-provided goods introduced in #43532, infinite recursion is possible via is_req_active -> is_goods_type_in_range -> goods_can_be_provided -> are_reqs_active -> is_req_active if ruleset authors include cyclic dependencies between self-provided goods. This should probably be caught with sanity checks when loading the ruleset rather than crashing.