チケット #43724

Segfault with cyclic requirements in self-provided goods

登録: 2022-01-28 23:33 最終更新: 2024-07-27 08:59

報告者:
担当者:
チケットの種類:
状況:
完了
コンポーネント:
マイルストーン:
優先度:
5 - 中
重要度:
5 - 中
解決法:
重複
ファイル:
なし

詳細

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.

チケットの履歴 (9 件中 3 件表示)

2022-01-28 23:33 更新者: alienvalkyrie
  • 新しいチケット "Segfault with cyclic requirements in self-provided goods" が作成されました
2022-01-28 23:48 更新者: alienvalkyrie
コメント

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.

2022-01-29 17:16 更新者: cazfi
コメント

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)

2022-02-04 09:30 更新者: alienvalkyrie
コメント

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

  • making recursive requirements statically impossible (in particular, reverting Self-Provided goods and replacing them with some other solution), or
  • adding infinite-recursion-detection to the requirement checker (e.g. building a list of everything that's currently being evaluated in is_req_active)

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.

2022-10-26 11:07 更新者: cazfi
コメント

Created a meta-ticket about the infinite-recursion with requirements cases we have -> #45974

2024-05-04 12:39 更新者: cazfi
コメント

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.

2024-05-05 05:29 更新者: 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.

2024-06-30 15:52 更新者: cazfi
コメント

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.

2024-07-27 08:59 更新者: cazfi
  • 状況オープン から 完了 に更新されました
  • 担当者(未割り当て) から cazfi に更新されました
  • 解決法なし から 重複 に更新されました

添付ファイルリスト

添付ファイルはありません

編集

ログインしていません。ログインしていない状態では、コメントに記載者の記録が残りません。 » ログインする