def relevant_definitions(symbols): dfn_map = dict((ldf.formula.defines(), ldf.formula.args[1]) for ldf in module.definitions) rch = set( iu.reachable( symbols, lambda sym: lu.symbols_ast(dfn_map[sym]) if sym in dfn_map else [])) return [ldf for ldf in module.definitions if ldf.formula.defines() in rch]
def relevant_definitions(symbols): dfn_map = dict((ldf.formula.defines(),ldf.formula.args[1]) for ldf in module.definitions) rch = set(iu.reachable(symbols,lambda sym: lu.symbols_ast(dfn_map[sym]) if sym in dfn_map else [])) return [ldf for ldf in module.definitions if ldf.formula.defines() in rch]
def summarize_isolate(mod): global check_lineno check_lineno = act.checked_assert.get() if check_lineno == "": check_lineno = None # print 'check_lineno: {}'.format(check_lineno) check = not opt_summary.get() subgoalmap = dict((x.id, y) for x, y in im.module.subgoals) axioms = [m for m in mod.labeled_axioms if m.id not in subgoalmap] schema_instances = [m for m in mod.labeled_axioms if m.id in subgoalmap] if axioms: print "\n The following properties are assumed as axioms:" for lf in axioms: print pretty_lf(lf) if mod.definitions: print "\n The following definitions are used:" for lf in mod.definitions: print pretty_lf(lf) if (mod.labeled_props or schema_instances) and not checked_action.get(): print "\n The following properties are to be checked:" if check: for lf in schema_instances: print pretty_lf(lf) + " [proved by axiom schema]" ag = ivy_art.AnalysisGraph() clauses1 = lut.true_clauses(annot=act.EmptyAnnotation()) pre = itp.State(value=clauses1) props = [x for x in im.module.labeled_props if not x.temporal] fcs = ([ (ConjAssumer if prop.id in subgoalmap else ConjChecker)(prop) for prop in props ]) check_fcs_in_state(mod, ag, pre, fcs) else: for lf in schema_instances + mod.labeled_props: print pretty_lf(lf) # after checking properties, make them axioms im.module.labeled_axioms.extend(im.module.labeled_props) im.module.update_theory() if mod.labeled_inits: print "\n The following properties are assumed initially:" for lf in mod.labeled_inits: print pretty_lf(lf) if mod.labeled_conjs: print "\n The inductive invariant consists of the following conjectures:" for lf in mod.labeled_conjs: print pretty_lf(lf) apply_conj_proofs(mod) if mod.isolate_info.implementations: print "\n The following action implementations are present:" for mixer, mixee, action in sorted(mod.isolate_info.implementations, key=lambda x: x[0]): print " {}implementation of {}".format( pretty_lineno(action), mixee) if mod.isolate_info.monitors: print "\n The following action monitors are present:" for mixer, mixee, action in sorted(mod.isolate_info.monitors, key=lambda x: x[0]): print " {}monitor of {}".format(pretty_lineno(action), mixee) # if mod.actions: # print "\n The following actions are present:" # for actname,action in sorted(mod.actions.iteritems()): # print " {}{}".format(pretty_lineno(action),actname) if mod.initializers: print "\n The following initializers are present:" for actname, action in sorted(mod.initializers, key=lambda x: x[0]): print " {}{}".format(pretty_lineno(action), actname) if mod.labeled_conjs and not checked_action.get(): print "\n Initialization must establish the invariant" if check: with itp.EvalContext(check=False): ag = ivy_art.AnalysisGraph(initializer=lambda x: None) check_conjs_in_state(mod, ag, ag.states[0]) else: print '' if mod.initializers: print "\n Any assertions in initializers must be checked", if check: ag = ivy_art.AnalysisGraph(initializer=lambda x: None) fail = itp.State(expr=itp.fail_expr(ag.states[0].expr)) check_safety_in_state(mod, ag, fail) checked_actions = get_checked_actions() if checked_actions and mod.labeled_conjs: print "\n The following set of external actions must preserve the invariant:" for actname in sorted(checked_actions): action = act.env_action(actname) print " {}{}".format(pretty_lineno(action), actname) if check: ag = ivy_art.AnalysisGraph() pre = itp.State() pre.clauses = get_conjs(mod) with itp.EvalContext(check=False): # don't check safety # post = ag.execute(action, pre, None, actname) post = ag.execute(action, pre) check_conjs_in_state(mod, ag, post, indent=12) else: print '' callgraph = defaultdict(list) for actname, action in mod.actions.iteritems(): for called_name in action.iter_calls(): callgraph[called_name].append(actname) some_assumps = False for actname, action in mod.actions.iteritems(): assumptions = [ sub for sub in action.iter_subactions() if isinstance(sub, act.AssumeAction) ] if assumptions: if not some_assumps: print "\n The following program assertions are treated as assumptions:" some_assumps = True callers = callgraph[actname] if actname in mod.public_actions: callers.append("the environment") prettyname = actname[4:] if actname.startswith('ext:') else actname prettycallers = [ c[4:] if c.startswith('ext:') else c for c in callers ] print " in action {} when called from {}:".format( prettyname, ','.join(prettycallers)) for sub in assumptions: print " {}assumption".format(pretty_lineno(sub)) tried = set() some_guarants = False for actname, action in mod.actions.iteritems(): guarantees = [ sub for sub in action.iter_subactions() if isinstance(sub, (act.AssertAction, act.Ranking)) ] if check_lineno is not None: guarantees = [ sub for sub in guarantees if sub.lineno == check_lineno ] if guarantees: if not some_guarants: print "\n The following program assertions are treated as guarantees:" some_guarants = True callers = callgraph[actname] if actname in mod.public_actions: callers.append("the environment") prettyname = actname[4:] if actname.startswith('ext:') else actname prettycallers = [ c[4:] if c.startswith('ext:') else c for c in callers ] print " in action {} when called from {}:".format( prettyname, ','.join(prettycallers)) roots = set(iu.reachable([actname], lambda x: callgraph[x])) for sub in guarantees: print " {}guarantee".format(pretty_lineno(sub)), if check and any(r in roots and (r, sub.lineno) not in tried for r in checked_actions): print_dots() old_checked_assert = act.checked_assert.get() act.checked_assert.value = sub.lineno some_failed = False for root in checked_actions: if root in roots: tried.add((root, sub.lineno)) action = act.env_action(root) ag = ivy_art.AnalysisGraph() pre = itp.State() pre.clauses = get_conjs(mod) with itp.EvalContext(check=False): post = ag.execute(action, prestate=pre) fail = itp.State(expr=itp.fail_expr(post.expr)) if not check_safety_in_state( mod, ag, fail, report_pass=False): some_failed = True break if not some_failed: print 'PASS' act.checked_assert.value = old_checked_assert else: print ""
def module_to_cpp_class(classname): global is_derived is_derived = set() for df in im.module.concepts: is_derived.add(df.defines()) # remove the actions not reachable from exported ra = iu.reachable(im.module.public_actions,lambda name: im.module.actions[name].iter_calls()) im.module.actions = dict((name,act) for name,act in im.module.actions.iteritems() if name in ra) header = [] if target.get() == "gen": header.append('extern void ivy_assert(bool);\n') header.append('extern void ivy_assume(bool);\n') header.append('extern void ivy_check_progress(int,int);\n') header.append('extern int choose(int,int);\n') header.append('struct ivy_gen {virtual int choose(int rng,const char *name) = 0;};\n') header.append('#include <vector>\n') header.append('class ' + classname + ' {\n public:\n') header.append(' std::vector<int> ___ivy_stack;\n') if target.get() == "gen": header.append(' ivy_gen *___ivy_gen;\n') header.append(' int ___ivy_choose(int rng,const char *name,int id);\n') if target.get() != "gen": header.append(' virtual void ivy_assert(bool){}\n') header.append(' virtual void ivy_assume(bool){}\n') header.append(' virtual void ivy_check_progress(int,int){}\n') impl = ['#include "' + classname + '.h"\n\n'] impl.append("#include <sstream>\n") impl.append("#include <algorithm>\n") impl.append("int " + classname) if target.get() == "gen": impl.append( """::___ivy_choose(int rng,const char *name,int id) { std::ostringstream ss; ss << name << ':' << id;; for (unsigned i = 0; i < ___ivy_stack.size(); i++) ss << ':' << ___ivy_stack[i]; return ___ivy_gen->choose(rng,ss.str().c_str()); } """) else: impl.append( """::___ivy_choose(int rng,const char *name,int id) { return 0; } """) for sym in all_state_symbols(): if sym not in is_derived: declare_symbol(header,sym) for sym in il.sig.constructors: declare_symbol(header,sym) for sname in il.sig.interp: header.append(' int __CARD__' + varname(sname) + ';\n') for df in im.module.concepts: emit_derived(header,impl,df) # declare one counter for each progress obligation # TRICKY: these symbols are boolean but we create a C++ int for df in im.module.progress: declare_symbol(header,df.args[0].rep,c_type = 'int') header.append(' ' + classname + '();\n'); im.module.actions['.init'] = init_method() for a in im.module.actions: emit_action(header,impl,a,classname) emit_tick(header,impl,classname) header.append('};\n') impl.append(classname + '::' + classname + '(){\n') enums = set(sym.sort.name for sym in il.sig.constructors) for sortname in enums: for i,n in enumerate(il.sig.sorts[sortname].extension): impl.append(' {} = {};\n'.format(varname(n),i)) for sortname in il.sig.interp: if sortname in il.sig.sorts: impl.append(' __CARD__{} = {};\n'.format(varname(sortname),sort_card(il.sig.sorts[sortname]))) if target.get() != "gen": emit_one_initial_state(impl) impl.append('}\n') if target.get() == "gen": emit_boilerplate1(header,impl) emit_init_gen(header,impl,classname) for name,action in im.module.actions.iteritems(): if name in im.module.public_actions: emit_action_gen(header,impl,name,action) return ''.join(header) , ''.join(impl)