示例#1
0
 def test_as_clauses_lockserv(self) -> None:
     with open(lockserv_path) as f:
         prog = mypyvy.parse_program(f.read())
     typechecker.typecheck_program(prog)
     for inv in prog.invs():
         expr = inv.expr
         with self.subTest(expr=expr):
             syntax.as_clauses(expr)
示例#2
0
文件: test.py 项目: guywaldman/mypyvy
 def test_as_clauses_lockserv(self) -> None:
     with open(PROJECT_ROOT / 'examples' / 'lockserv.pyv') as f:
         prog = mypyvy.parse_program(f.read())
     prog.resolve()
     for inv in prog.invs():
         expr = inv.expr
         with self.subTest(expr=expr):
             syntax.as_clauses(expr)
示例#3
0
文件: test.py 项目: guywaldman/mypyvy
 def test_as_clauses_basic(self) -> None:
     ios = [
         ('true', ['true | false']),
         ('foo', ['foo | false']),
         ('forall N1,N2. grant_msg(N1) & grant_msg(N2) -> N1 = N2',
          ['forall N1, N2. !grant_msg(N1) | !grant_msg(N2) | N1 = N2']),
         ('forall N1,N2. !(holds_lock(N1) & grant_msg(N2))',
          ['forall N1, N2. !holds_lock(N1) | !grant_msg(N2)']),
         ('forall N. !(unlock_msg(N) & server_holds_lock)',
          ['forall N. !unlock_msg(N) | !server_holds_lock']),
         ('!(exists N. holds_lock(N) & server_holds_lock)',
          ['forall N. !holds_lock(N) | !server_holds_lock']),
         ('!!(forall X. !(exists Y. (r(X) & s(Y)) & (q(X) & p(Y))))',
          ['forall X, Y. !r(X) | !s(Y) | !q(X) | !p(Y)']),
         ('forall X. r(X) & s(X)',
          ['forall X. r(X) | false', 'forall X. s(X) | false']),
         ('forall X. (r(X) | s(X)) & (q(X) | p(X))',
          ['forall X. r(X) | s(X)', 'forall X. q(X) | p(X)']),
     ]
     for expr, expected in ios:
         with self.subTest(expr=expr):
             clauses = syntax.as_clauses(parser.parse_expr(expr))
             # print(clause)
             self.assertEqual(clauses, [
                 parser.parse_expr(expected_clause)
                 for expected_clause in expected
             ])
示例#4
0
    def __init__(self, solver: Solver) -> None:
        self.solver = solver
        self.fs: List[Frame] = []
        self.predicates: List[Expr] = []
        self.safeties = []
        self.backwards_reachable_states: List[BackwardReachableState] = []
        self.currently_blocking: Optional[BackwardReachableState] = None

        for inv in syntax.the_program.safeties():
            try:
                cs = syntax.as_clauses(inv.expr)
                utils.logger.info(f'converted safety {inv.expr} in to clauses:')
                for c in cs:
                    d = negate_clause(c)
                    utils.logger.info(str(d))
                    self.record_backwards_reachable_state(
                        BackwardReachableState(
                            len(self.backwards_reachable_states),
                            d,
                            0
                        )
                    )
            except Exception:
                self.safeties.append(inv.expr)

        self._first_frame()
示例#5
0
 def test_as_clauses_fail(self) -> None:
     egs = [
         'exists X. X = X',
     ]
     for expr in egs:
         with self.subTest(expr=expr):
             with self.assertRaises(Exception):
                 print(syntax.as_clauses(parser.parse_expr(expr)))
示例#6
0
文件: updr.py 项目: aatxe/mypyvy
    def __init__(self, solver: Solver) -> None:
        self.solver = solver
        prog = syntax.the_program

        if utils.args.automaton:
            automaton = prog.the_automaton()
            if automaton is None:
                utils.print_error_and_exit(
                    None, 'updr --automaton requires the file to '
                    'declare an automaton')
        else:
            the_phase = 'the_phase'
            pcs: List[syntax.PhaseComponent] = []
            for t in prog.transitions():
                pcs.append(
                    syntax.PhaseTransitionDecl(None, t.name, None, the_phase))
            for inv in prog.safeties():
                pcs.append(inv)

            automaton = AutomatonDecl(None, [
                syntax.InitPhaseDecl(None, the_phase),
                syntax.PhaseDecl(None, the_phase, pcs)
            ])

            automaton.resolve(prog.scope)

        self.automaton = PhaseAutomaton(automaton)
        self.fs: List[Frame] = []
        self.push_cache: List[Dict[Phase, Set[Expr]]] = []
        self.counter = 0
        self.predicates: List[Expr] = []
        self.state_count = 0

        self.inductive_invariant: Set[int] = set(
        )  # indices into predicates of currently inductive predicates
        self.human_invariant = tuple(
            itertools.chain(*(syntax.as_clauses(inv.expr)
                              for inv in prog.invs()
                              if not inv.is_safety)))  # convert to CNF
        self.human_invariant_to_predicate: Dict[int, int] = dict(
        )  # dict mapping index of human_invariant to index of predicates
        self.human_invariant_proved: Set[int] = set(
        )  # indices into human_invariant that are implied by the current inductive_invariant
        self.human_invariant_implies: Set[int] = set(
        )  # indices into predicates of predicates that are implied by the human invariant

        self._first_frame()