Named state sets, so a spec can refer to a whole set (e.g. old(phase(this)))

未關閉
#435 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
48/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java
領域
backend, devtools

研究方向

Start by locating @StateSet handling and AuxStateHandler.getMissingStates, then trace how state predicates are translated and how refinement errors and hints are produced. Check the existing state set and refinement tests first. Done means named sets can be referenced in predicates, including old(set(this)), unnamed sets retain current behavior, and messages and hints use the set names as described.

由索引模型根據 Issue 內容生成。

描述

enhancement error messages study

Motivation

Each @StateSet becomes an anonymous ghost function (state1, state2, ...). After a call, AuxStateHandler.getMissingStates adds stateN(this) == stateN(old(this)) for every set the to predicate does not mention, so unmentioned sets keep their value. That works, but the spec author cannot name a set, which causes three problems.

Running example: an UndoManager spec with three orthogonal sets. The phase decides addEdit/setLimit; whether there is something to undo or redo decides undo()/redo(), and canUndo()/canRedo() are guards.

@StateSet({"start", "canEdit", "end"})
@StateSet({"undoable", "notUndoable"})
@StateSet({"redoable", "notRedoable"})
...
@StateRefinement(from="undoable(this)", to="notUndoable(this) && redoable(this)")
void undo();

@StateRefinement(from="undoable(this)", to="return && undoable(this)")
@StateRefinement(to="return ? undoable(this) : notUndoable(this)")
boolean canUndo();
1. A set mentioned in one branch is dropped in the other

A set counts as "mentioned" if any of its states appears anywhere in to. With to="return ? undoable(this) : true", the undo set is not carried over in the false branch: it becomes unconstrained instead of keeping its previous value. Verified with verifier 0.0.36 (addEdit; boolean b = um.canUndo(); um.undo();). The found predicate carries state1(um⁸⁵) == state1(um⁸³) && state3(um⁸⁵) == state3(um⁸³) but has no equality for state2. There is no way to write "in this branch, keep the set as it was".

2. Error messages leak the internal names
State Refinement Error: found canEdit(um⁸³) && undoable(um⁸³) && notRedoable(um⁸³) && (canUndo⁸⁴ ? undoable(um⁸⁵) : notUndoable(um⁸⁵)) && state1(um⁸⁵) == state1(um⁸³) && state3(um⁸⁵) == state3(um⁸³) but expected undoable(um⁸⁵)

state1 and state3 appear nowhere in the spec.

3. Hints multiply all sets together

For an unknown receiver (a field or a getter result), the hint lists the cross product of all sets, although the failing call only needs one:

The state of undoManager is unknown here. To get it to start and undoable and redoable or start and notUndoable and redoable or canEdit and undoable and redoable or canEdit and notUndoable and redoable or end and undoable and redoable or end and notUndoable and redoable, use: undoManager.undo() (from start and undoable and notRedoable or canEdit and undoable and notRedoable or end and undoable and notRedoable)

redo() only needs redoable. A hint per named set could say "undoManager is not known to be redoable; check canRedo()". The guard canRedo() is missing from the hint entirely, because it is a from-less refinement whose result decides the state (related: liquid-java/liquidjava-fsm#14).

Proposal

Allow an optional name on a state set, which can be used as a function in predicates:

@StateSet(name="phase", value={"start", "canEdit", "end"})
@StateSet(name="undo",  value={"undoable", "notUndoable"})
@StateSet(name="redo",  value={"redoable", "notRedoable"})

@StateRefinement(to="return ? undoable(this) : undo(this) == old(undo(this))")
boolean canUndo();
  • undo(this) == old(undo(this)) keeps a set explicitly, per branch (fixes 1).
  • Messages print phase(um) / undo(um) instead of state1(um) (fixes 2).
  • Hints can name only the set the failing precondition needs (helps 3).
  • liquid-java/liquidjava-fsm#8 ("one machine per @StateSet") could use the names as machine titles.

Unnamed sets would keep working as today, with the generated name.

Context: found while writing UndoManager specs for LiquidJava study exercises (JabRef's EditAction, where undo()/redo() on a manager from a getter must be guarded by canUndo()/canRedo()).

主要語言
Java
星號
73
分支
38
平均合併
12 小時 32 分鐘
30 天內合併 PR
45

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。