|
17 | 17 | Goal, |
18 | 18 | GoalState, |
19 | 19 | Site, |
| 20 | + Subsumption, |
20 | 21 | Tactic, |
21 | 22 | TacticHave, |
22 | 23 | TacticLet, |
@@ -342,6 +343,50 @@ async def goal_resume_async(self, state: GoalState, goals: list[Goal]) -> GoalSt |
342 | 343 | return GoalState.parse(result, [], self.to_remove_goal_states) |
343 | 344 | goal_resume = to_sync(goal_resume_async) |
344 | 345 |
|
| 346 | + async def goal_subsume_async( |
| 347 | + self, |
| 348 | + state: GoalState, |
| 349 | + goal: Goal, |
| 350 | + candidates: list[Goal], |
| 351 | + src_state: Optional[GoalState]=None |
| 352 | + ) -> (Subsumption, Optional[GoalState], Optional[Goal]): |
| 353 | + """ |
| 354 | + Detect subsumption by candidate goals |
| 355 | +
|
| 356 | + The candidate goals must all exist in `src_state`. If `src_state` is not |
| 357 | + provided, they must exist in `state`. Returns a new goal state if a |
| 358 | + subsumption does not lead to a cycle, and the subsumptor if there is any |
| 359 | + subsumption happening. |
| 360 | + """ |
| 361 | + args = { |
| 362 | + "stateId": state.state_id, |
| 363 | + "goal": goal.id, |
| 364 | + "candidates": [g.id for g in candidates], |
| 365 | + } |
| 366 | + if src_state: |
| 367 | + args["srcStateId"] = src_state.state_id |
| 368 | + result = await self.run_async('goal.subsume', args) |
| 369 | + if "error" in result: |
| 370 | + raise ServerError(result) |
| 371 | + nextState = None |
| 372 | + if state_id := result.get("stateId"): |
| 373 | + nextState = GoalState( |
| 374 | + state_id=state_id, |
| 375 | + goals=[g for g in state.goals if g.id != goal.id], |
| 376 | + messages=[], |
| 377 | + _sentinel=self.to_remove_goal_states, |
| 378 | + ) |
| 379 | + sub = Subsumption[result["result"].upper()] |
| 380 | + subsumptor = None |
| 381 | + if subsumptor := result.get("subsumptor"): |
| 382 | + gen = (g for g in candidates if g.id == subsumptor) |
| 383 | + subsumptor = next(gen) |
| 384 | + if subsumptor is None: |
| 385 | + raise ServerError("Subsumptor should not be none") |
| 386 | + return (sub, nextState, subsumptor) |
| 387 | + |
| 388 | + goal_subsume = to_sync(goal_subsume_async) |
| 389 | + |
345 | 390 | async def env_add_async( |
346 | 391 | self, name: str, levels: list[str], |
347 | 392 | t: Expr, v: Expr, is_theorem: bool = True): |
|
0 commit comments