Пример #1
0
    def test_consistent_hashing(self) -> None:
        with open(lockserv_path) as f:
            prog1 = mypyvy.parse_program(f.read())
        with open(lockserv_path) as f:
            prog2 = mypyvy.parse_program(f.read())

        typechecker.typecheck_program(prog1)
        typechecker.typecheck_program(prog2)
        for d1, d2 in zip(prog1.decls_containing_exprs(), prog2.decls_containing_exprs()):
            e1 = d1.expr
            e2 = d2.expr
            with self.subTest(msg='expr hash/eq', e1=e1, e2=e2):
                self.assertEqual(e1, e2)
                self.assertEqual(hash(e1), hash(e2))
Пример #2
0
    def test_consistent_hashing(self) -> None:
        with open(PROJECT_ROOT / 'examples' / 'lockserv.pyv') as f:
            prog1 = mypyvy.parse_program(f.read())
        with open(PROJECT_ROOT / 'examples' / 'lockserv.pyv') as f:
            prog2 = mypyvy.parse_program(f.read())

        prog1.resolve()
        prog2.resolve()
        for d1, d2 in zip(prog1.decls_containing_exprs(), prog2.decls_containing_exprs()):
            e1 = d1.expr
            e2 = d2.expr
            with self.subTest(msg='expr hash/eq', e1=e1, e2=e2):
                self.assertEqual(e1, e2)
                self.assertEqual(hash(e1), hash(e2))
Пример #3
0
    def test_relativize_quantifiers(self) -> None:
        minipaxos = '''
            sort node
            sort quorum
            immutable relation member(node, quorum)
            mutable relation active_node(node)
            mutable relation active_quorum(quorum)
        '''
        prog = mypyvy.parse_program(minipaxos)
        typechecker.typecheck_program(prog)
        node = prog.scope.get_sort('node')
        assert node is not None
        quorum = prog.scope.get_sort('quorum')
        assert quorum is not None
        active_node = prog.scope.get('active_node')
        assert isinstance(active_node, syntax.RelationDecl)
        active_quorum = prog.scope.get('active_quorum')
        assert isinstance(active_quorum, syntax.RelationDecl)
        guards = {node: active_node, quorum: active_quorum}

        e = parser.parse_expr('forall Q1, Q2. exists N. member(N, Q1) & member(N, Q2)')
        typechecker.typecheck_expr(prog.scope, e, None)

        expected = parser.parse_expr('forall Q1, Q2. active_quorum(Q1) & active_quorum(Q2) -> '
                                     'exists N. active_node(N) & (member(N, Q1) & member(N, Q2))')
        with prog.scope.n_states(1):
            typechecker.typecheck_expr(prog.scope, expected, None)

        self.assertEqual(syntax.relativize_quantifiers(guards, e), expected)
Пример #4
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)
Пример #5
0
 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)
Пример #6
0
def main():
    filename = sys.argv[1]

    utils.args = mypyvy.parse_args(['typecheck', filename])

    with open(filename) as f:
        contents = f.read()
    prog = mypyvy.parse_program(contents, filename)
    prog.resolve()
    #typechecker.typecheck_program(prog)

    actions = get_actions(prog)

    print(
        json.dumps({
            "sorts": get_sorts(prog),
            "functions": get_functions(prog),
            "axioms": get_axioms(prog),
            "inits": get_inits(prog),
            "conjectures": get_conjs(prog),
            "templates": [],
            "actions": get_actions(prog),
        }))