def diagram_trace_to_explicitly_relaxed_trace_decl(
        trace: RelaxedTrace, ending_property: Expr) -> syntax.TraceDecl:
    trace = list(reversed(trace))

    components: List[syntax.TraceComponent] = []
    assert len(trace) > 1
    _, first_diag = trace[0]
    components.append(relativized_assert_decl(first_diag))

    for pre, post in zip(trace, trace[1:]):
        t, pre_diag = pre
        assert t is not None
        _, post_diag = post

        assert isinstance(pre_diag, Diagram)
        assert isinstance(post_diag, Diagram)

        actual_transition = transition_decl_from_name(t.name)
        components.append(actual_transition)

        assert len(pre_diag.get_vs()) >= len(post_diag.get_vs())
        if len(pre_diag.get_vs()) != len(post_diag.get_vs()):
            components.append(transition_decl_from_name(
                'decrease_domain'))  # TODO: make non-hardcoded

    # _, last_diag = trace[-1]
    components.append(relativized_assert_decl(ending_property))

    return syntax.TraceDecl(components, True)
def load_relaxed_trace_from_updr_cex(prog: Program, s: Solver) -> logic.Trace:
    import xml.dom.minidom  # type: ignore
    collection = xml.dom.minidom.parse(
        "paxos_derived_trace.xml").documentElement

    components: List[syntax.TraceComponent] = []

    xml_decls = reversed(collection.childNodes)
    seen_first = False

    for elm in xml_decls:
        if isinstance(elm, xml.dom.minidom.Text):  # type: ignore
            continue
        if elm.tagName == 'state':
            diagram = parser.parse_expr(elm.childNodes[0].data)
            typechecker.typecheck_expr(prog.scope, diagram, syntax.BoolSort)
            assert isinstance(
                diagram, syntax.QuantifierExpr) and diagram.quant == 'EXISTS'
            active_clauses = [
                relaxed_traces.active_var(v.name, str(v.sort))
                for v in diagram.get_vs()
            ]

            if not seen_first:
                # restrict the domain to be subdomain of the diagram's existentials
                seen_first = True
                import itertools  # type: ignore
                for sort, vars in itertools.groupby(
                        diagram.get_vs(),
                        lambda v: v.sort):  # TODO; need to sort first
                    free_var = syntax.SortedVar(
                        syntax.the_program.scope.fresh("v_%s" % str(sort)),
                        None)

                    # TODO: diagram simplification omits them from the exists somewhere
                    consts = list(
                        filter(lambda c: c.sort == sort, prog.constants()))
                    els: Sequence[Union[syntax.SortedVar, syntax.ConstantDecl]]
                    els = list(vars)
                    els += consts
                    restrict_domain = syntax.Forall(
                        (free_var, ),
                        syntax.Or(*(syntax.Eq(syntax.Id(free_var.name),
                                              syntax.Id(v.name))
                                    for v in els)))
                    active_clauses += [restrict_domain]

            diagram_active = syntax.Exists(
                diagram.get_vs(), syntax.And(diagram.body, *active_clauses))
            typechecker.typecheck_expr(prog.scope, diagram_active,
                                       syntax.BoolSort)

            components.append(syntax.AssertDecl(expr=diagram_active))
        elif elm.tagName == 'action':
            action_name = elm.childNodes[0].data.split()[0]
            tcall = syntax.TransitionCalls(
                calls=[syntax.TransitionCall(target=action_name, args=None)])
            components.append(syntax.TraceTransitionDecl(transition=tcall))
        else:
            assert False, "unknown xml tagName"

    trace_decl = syntax.TraceDecl(components=components, sat=True)
    migrated_trace = bmc_trace(
        prog,
        trace_decl,
        s,
        lambda s, ks: logic.check_solver(s, ks, minimize=True),
        log=False)

    assert migrated_trace is not None
    import pickle
    pickle.dump(migrated_trace, open("migrated_trace.p", "wb"))
    return migrated_trace
Exemple #3
0
def p_decl_trace(p: Any) -> None:
    'decl : satunsat TRACE LBRACE trace_components RBRACE'
    p[0] = syntax.TraceDecl(p.slice[2], p[4], sat=p[1] == 'sat')
Exemple #4
0
def p_decl_trace(p: Any) -> None:
    'decl : satunsat TRACE LBRACE trace_components RBRACE'
    satunsat_tok = p[1]
    p[0] = syntax.TraceDecl(p[4], sat=satunsat_tok.value == 'sat', span=loc_join(satunsat_tok, p.slice[5]))