Exemple #1
0
    def _setup_handle_updates(self):
        """
        This method creates update code for handle objects modified by each op.
        Must be called once after all user-specified queries have been added.
        """
        for op in self.op_specs:
            handles = reachable_handles_at_method(self.spec, op)
            # print("-"*60)
            for t, bag in handles.items():
                # print("  {} : {}".format(pprint(t), pprint(bag)))
                h = fresh_var(t)
                delta = inc.delta_form(
                    self.spec.statevars + op.args + [(h.id, h.type)], op)
                lval = EGetField(h, "val").with_type(t.value_type)
                new_val = simplify(subst(lval, delta))

                # get set of modified handles
                modified_handles = Query(
                    fresh_name("modified_handles"), Visibility.Internal, [],
                    op.assumptions,
                    EFilter(
                        EUnaryOp(UOp.Distinct, bag).with_type(bag.type),
                        ELambda(h, ENot(EEq(lval,
                                            new_val)))).with_type(bag.type),
                    "[{}] modified handles of type {}".format(
                        op.name, pprint(t)))
                query_vars = [
                    v for v in free_vars(modified_handles)
                    if v not in self.abstract_state
                ]
                modified_handles.args = [(arg.id, arg.type)
                                         for arg in query_vars]

                # modify each one
                (state_update_stm, subqueries) = inc.sketch_update(
                    lval, lval, new_val, self.abstract_state,
                    list(op.assumptions) +
                    [EDeepIn(h, bag),
                     EIn(h, modified_handles.ret)])
                # print("  got {} subqueries".format(len(subqueries)))
                # print("  to update {} in {}, use\n{}".format(pprint(t), op.name, pprint(state_update_stm)))
                for sub_q in subqueries:
                    sub_q.docstring = "[{}] {}".format(op.name,
                                                       sub_q.docstring)
                    state_update_stm = self._add_subquery(
                        sub_q=sub_q, used_by=state_update_stm)
                if state_update_stm != SNoOp():
                    state_update_stm = SForEach(
                        h,
                        ECall(modified_handles.name,
                              query_vars).with_type(bag.type),
                        state_update_stm)
                    state_update_stm = self._add_subquery(
                        sub_q=modified_handles, used_by=state_update_stm)
                self.handle_updates[(t, op.name)] = state_update_stm
 def test_mapget(self):
     t = THandle("T", INT)
     xs = EVar("xs").with_type(TBag(t))
     x = EVar("x").with_type(t)
     y = EVar("y").with_type(t)
     mt = TTuple((INT, INT))
     e = EMapGet(
         EMakeMap2(xs, ELambda(x,
             ETuple((EGetField(x, "val").with_type(INT), EGetField(y, "val").with_type(INT))).with_type(mt)
             )).with_type(TMap(t, mt)),
         y).with_type(mt)
     assert simplify(e, validate=True, debug=True) is not e
Exemple #3
0
 def test_simple_mapget(self):
     t = INT
     xs = EVar("xs").with_type(TBag(t))
     x = EVar("x").with_type(t)
     y = EVar("y").with_type(t)
     mt = TTuple((INT, INT))
     e = EMapGet(
         EMakeMap2(xs, ELambda(x,
             ETuple((x, y)).with_type(mt)
             )).with_type(TMap(t, mt)),
         y).with_type(mt)
     assert simplify(e, validate=True, debug=True) is not e
Exemple #4
0
 def test_mapget(self):
     t = THandle("elem_type", INT)
     xs = EVar("xs").with_type(TBag(t))
     x = EVar("x").with_type(t)
     y = EVar("y").with_type(t)
     mt = TTuple((INT, INT))
     e = EMapGet(
         EMakeMap2(xs, ELambda(x,
             ETuple((EGetField(x, "val").with_type(INT), EGetField(y, "val").with_type(INT))).with_type(mt)
             )).with_type(TMap(t, mt)),
         y).with_type(mt)
     assert simplify(e, validate=True, debug=True) is not e
 def test_simple_mapget(self):
     t = INT
     xs = EVar("xs").with_type(TBag(t))
     x = EVar("x").with_type(t)
     y = EVar("y").with_type(t)
     mt = TTuple((INT, INT))
     e = EMapGet(
         EMakeMap2(xs, ELambda(x,
             ETuple((x, y)).with_type(mt)
             )).with_type(TMap(t, mt)),
         y).with_type(mt)
     assert simplify(e, validate=True, debug=True) is not e
Exemple #6
0
    def _add_subquery(self, sub_q : Query, used_by : Stm) -> Stm:
        with task("adding query", query=sub_q.name):
            sub_q = shallow_copy(sub_q)
            with task("checking whether we need more handle assumptions"):
                new_a = implicit_handle_assumptions_for_method(
                    reachable_handles_at_method(self.spec, sub_q),
                    sub_q)
                if not valid(EImplies(EAll(sub_q.assumptions), EAll(new_a))):
                    event("we do!")
                    sub_q.assumptions = list(itertools.chain(sub_q.assumptions, new_a))

            with task("simplifying"):
                orig_a = sub_q.assumptions
                orig_a_size = sum(a.size() for a in sub_q.assumptions)
                orig_ret_size = sub_q.ret.size()
                sub_q.assumptions = tuple(simplify_or_ignore(a) for a in sub_q.assumptions)
                sub_q.ret = simplify(sub_q.ret)
                a_size = sum(a.size() for a in sub_q.assumptions)
                ret_size = sub_q.ret.size()
                event("|assumptions|: {} -> {}".format(orig_a_size, a_size))
                event("|ret|: {} -> {}".format(orig_ret_size, ret_size))

                if a_size > orig_a_size:
                    print("NO, BAD SIMPLIFICATION")
                    print("original")
                    for a in orig_a:
                        print(" - {}".format(pprint(a)))
                    print("simplified")
                    for a in sub_q.assumptions:
                        print(" - {}".format(pprint(a)))
                    assert False

            state_vars = self.abstract_state
            funcs = self.extern_funcs
            qq = find_one(self.query_specs, lambda qq: dedup_queries.value and queries_equivalent(qq, sub_q, state_vars=state_vars, extern_funcs=funcs))
            if qq is not None:
                event("subgoal {} is equivalent to {}".format(sub_q.name, qq.name))
                arg_reorder = [[x[0] for x in sub_q.args].index(a) for (a, t) in qq.args]
                class Repl(BottomUpRewriter):
                    def visit_ECall(self, e):
                        args = tuple(self.visit(a) for a in e.args)
                        if e.func == sub_q.name:
                            args = tuple(args[idx] for idx in arg_reorder)
                            return ECall(qq.name, args).with_type(e.type)
                        else:
                            return ECall(e.func, args).with_type(e.type)
                used_by = Repl().visit(used_by)
            else:
                self.add_query(sub_q)
            return used_by
Exemple #7
0
def _fix_map(m: target_syntax.EMap) -> syntax.Exp:
    return m
    from cozy.simplification import simplify
    m = simplify(m)
    if not isinstance(m, target_syntax.EMap):
        return m
    elem_type = m.e.type.t
    assert m.f.body.type == elem_type
    changed = target_syntax.EFilter(
        m.e,
        mk_lambda(
            elem_type, lambda x: syntax.ENot(
                syntax.EBinOp(x, "===", m.f.apply_to(x)).with_type(syntax.BOOL)
            ))).with_type(m.e.type)
    e = syntax.EBinOp(
        syntax.EBinOp(m.e, "-", changed).with_type(m.e.type), "+",
        target_syntax.EMap(changed,
                           m.f).with_type(m.e.type)).with_type(m.e.type)
    if not valid(syntax.EEq(m, e)):
        print("WARNING: rewrite failed")
        print("_fix_map({!r})".format(m))
        return m
    return e
Exemple #8
0
    def _add_subquery(self, sub_q: Query, used_by: Stm) -> Stm:
        print("Adding new query {}...".format(sub_q.name))
        # orig_ret = sub_q.ret
        # print("rewritng ret for {}".format(pprint(orig_ret)))
        sub_q = shallow_copy(sub_q)
        sub_q.assumptions += tuple(
            implicit_handle_assumptions_for_method(
                reachable_handles_at_method(self.spec, sub_q), sub_q))
        sub_q.ret = simplify(sub_q.ret)
        # sub_q = rewrite_ret(sub_q, simplify)
        # if sub_q.ret != orig_ret:
        #     print("rewrote ret")
        #     print(" --> {}".format(pprint(sub_q.ret)))

        qq = find_one(
            self.query_specs,
            lambda qq: dedup_queries.value and queries_equivalent(qq, sub_q))
        if qq is not None:
            print("########### subgoal {} is equivalent to {}".format(
                sub_q.name, qq.name))
            arg_reorder = [[x[0] for x in sub_q.args].index(a)
                           for (a, t) in qq.args]

            class Repl(BottomUpRewriter):
                def visit_ECall(self, e):
                    args = tuple(self.visit(a) for a in e.args)
                    if e.func == sub_q.name:
                        args = tuple(args[idx] for idx in arg_reorder)
                        return ECall(qq.name, args).with_type(e.type)
                    else:
                        return ECall(e.func, args).with_type(e.type)

            used_by = Repl().visit(used_by)
        else:
            self.add_query(sub_q)
        return used_by
Exemple #9
0
def simplify_or_ignore(e):
    ee = simplify(e)
    return ee if ee.size() < e.size() else e
Exemple #10
0
 def test_regression06(self):
     simplify(EFilter(EMapKeys(EMakeMap2(EMap(EVar('xs').with_type(TBag(THandle('H', TNative('Value')))), ELambda(EVar('_var11125').with_type(THandle('H', TNative('Value'))), EGetField(EVar('_var11125').with_type(THandle('H', TNative('Value'))), 'val').with_type(TNative('Value')))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var11120').with_type(TNative('Value')), EUnaryOp('len', EFilter(EMap(EVar('xs').with_type(TBag(THandle('H', TNative('Value')))), ELambda(EVar('_var11125').with_type(THandle('H', TNative('Value'))), EGetField(EVar('_var11125').with_type(THandle('H', TNative('Value'))), 'val').with_type(TNative('Value')))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var11121').with_type(TNative('Value')), EBinOp(EVar('_var11120').with_type(TNative('Value')), '==', EVar('_var11121').with_type(TNative('Value'))).with_type(TBool()))).with_type(TBag(TNative('Value')))).with_type(TInt()))).with_type(TMap(TNative('Value'), TInt()))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var665135').with_type(TNative('Value')), EUnaryOp('not', EBinOp(EVar('_var665135').with_type(TNative('Value')), 'in', EMapKeys(EMakeMap2(EMap(EBinOp(EVar('xs').with_type(TBag(THandle('H', TNative('Value')))), '+', ESingleton(EVar('x').with_type(THandle('H', TNative('Value')))).with_type(TBag(THandle('H', TNative('Value'))))).with_type(TBag(THandle('H', TNative('Value')))), ELambda(EVar('_var11125').with_type(THandle('H', TNative('Value'))), EGetField(EVar('_var11125').with_type(THandle('H', TNative('Value'))), 'val').with_type(TNative('Value')))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var11120').with_type(TNative('Value')), EUnaryOp('len', EFilter(EMap(EBinOp(EVar('xs').with_type(TBag(THandle('H', TNative('Value')))), '+', ESingleton(EVar('x').with_type(THandle('H', TNative('Value')))).with_type(TBag(THandle('H', TNative('Value'))))).with_type(TBag(THandle('H', TNative('Value')))), ELambda(EVar('_var11125').with_type(THandle('H', TNative('Value'))), EGetField(EVar('_var11125').with_type(THandle('H', TNative('Value'))), 'val').with_type(TNative('Value')))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var11121').with_type(TNative('Value')), EBinOp(EVar('_var11120').with_type(TNative('Value')), '==', EVar('_var11121').with_type(TNative('Value'))).with_type(TBool()))).with_type(TBag(TNative('Value')))).with_type(TInt()))).with_type(TMap(TNative('Value'), TInt()))).with_type(TBag(TNative('Value')))).with_type(TBool())).with_type(TBool()))).with_type(TBag(TNative('Value'))))
 def test_regression11(self):
     simplify(ECond(EBool(False).with_type(TBool()), EBinOp(EMap(EListSlice(EVar('xs').with_type(TList(TFloat())), EVar('swapped').with_type(TInt()), EUnaryOp('len', EVar('xs').with_type(TList(TFloat()))).with_type(TInt())).with_type(TList(TFloat())), ELambda(EVar('x').with_type(TFloat()), EBinOp(ECall('log', (EBinOp(ENum(1.0).with_type(TFloat()), '+', EVar('x').with_type(TFloat())).with_type(TFloat()),)).with_type(TFloat()), '+', ECall('log', (ENum(1.5).with_type(TFloat()),)).with_type(TFloat())).with_type(TFloat()))).with_type(TBag(TFloat())), '+', EMap(EListSlice(EVar('xs').with_type(TList(TFloat())), ENum(0).with_type(TInt()), EVar('swapped').with_type(TInt())).with_type(TList(TFloat())), ELambda(EVar('x').with_type(TFloat()), EBinOp(ECall('log', (EBinOp(ENum(1.0).with_type(TFloat()), '+', EVar('x').with_type(TFloat())).with_type(TFloat()),)).with_type(TFloat()), '+', ECall('log', (ENum(1.5).with_type(TFloat()),)).with_type(TFloat())).with_type(TFloat()))).with_type(TBag(TFloat()))).with_type(TList(TFloat())), EMap(EVar('xs').with_type(TList(TFloat())), ELambda(EVar('x').with_type(TFloat()), EBinOp(ECall('log', (EBinOp(ENum(1.0).with_type(TFloat()), '+', EVar('x').with_type(TFloat())).with_type(TFloat()),)).with_type(TFloat()), '+', ECall('log', (ENum(1.5).with_type(TFloat()),)).with_type(TFloat())).with_type(TFloat()))).with_type(TBag(TFloat()))).with_type(TList(TFloat())), validate=True)
 def test_regression07(self):
     e = EGetField(EGetField(EArgMin(EBinOp(EVar('reqs').with_type(TBag(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))))), '+', ESingleton(EVar('r').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))))).with_type(TBag(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))))).with_type(TBag(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))))), ELambda(EVar('_var19096610').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), EGetField(EGetField(EVar('_var19096610').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), 'val').with_type(TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))), 'rq_expiration').with_type(TNative('Date_t')))).with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), 'val').with_type(TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))), 'rq_host').with_type(TNative('HostAndPort'))
     print(pprint(e))
     simplify(e, validate=True)
Exemple #13
0
 def test_regression01(self):
     simplify(EGetField(EMapGet(EMakeMap2(ECond(EUnaryOp('not', EBinOp(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'in', EVar('conns').with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))))).with_type(TBool())).with_type(TBool()), EBinOp(ESingleton(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))).with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))), '+', EVar('conns').with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))))).with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))), EVar('conns').with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))))).with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))), ELambda(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), EMakeRecord((('conn_state', EEnumEntry('CHECKED_OUT').with_type(TEnum(('READY', 'PROCESSING', 'CHECKED_OUT')))), ('conn_host', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort'))), ('conn_iface', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_iface').with_type(TNative('ConnectionPool::ConnectionInterface*'))), ('conn_next_refresh', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_next_refresh').with_type(TNative('Date_t'))), ('conn_returned', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_returned').with_type(TNative('Date_t'))), ('conn_dropped', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_dropped').with_type(TBool())))).with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))).with_type(TMap(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), EVar('_var1220993').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))).with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort')), validate=True, debug=True)
Exemple #14
0
 def test_regression11(self):
     simplify(ECond(EBool(False).with_type(TBool()), EBinOp(EMap(EListSlice(EVar('xs').with_type(TList(TFloat())), EVar('swapped').with_type(TInt()), EUnaryOp('len', EVar('xs').with_type(TList(TFloat()))).with_type(TInt())).with_type(TList(TFloat())), ELambda(EVar('x').with_type(TFloat()), EBinOp(ECall('log', (EBinOp(ENum(1.0).with_type(TFloat()), '+', EVar('x').with_type(TFloat())).with_type(TFloat()),)).with_type(TFloat()), '+', ECall('log', (ENum(1.5).with_type(TFloat()),)).with_type(TFloat())).with_type(TFloat()))).with_type(TBag(TFloat())), '+', EMap(EListSlice(EVar('xs').with_type(TList(TFloat())), ENum(0).with_type(TInt()), EVar('swapped').with_type(TInt())).with_type(TList(TFloat())), ELambda(EVar('x').with_type(TFloat()), EBinOp(ECall('log', (EBinOp(ENum(1.0).with_type(TFloat()), '+', EVar('x').with_type(TFloat())).with_type(TFloat()),)).with_type(TFloat()), '+', ECall('log', (ENum(1.5).with_type(TFloat()),)).with_type(TFloat())).with_type(TFloat()))).with_type(TBag(TFloat()))).with_type(TList(TFloat())), EMap(EVar('xs').with_type(TList(TFloat())), ELambda(EVar('x').with_type(TFloat()), EBinOp(ECall('log', (EBinOp(ENum(1.0).with_type(TFloat()), '+', EVar('x').with_type(TFloat())).with_type(TFloat()),)).with_type(TFloat()), '+', ECall('log', (ENum(1.5).with_type(TFloat()),)).with_type(TFloat())).with_type(TFloat()))).with_type(TBag(TFloat()))).with_type(TList(TFloat())), validate=True)
Exemple #15
0
 def test_regression10(self):
     simplify(EMapGet(EStateVar(EMakeMap2(EMap(EVar('reqs').with_type(TBag(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))))), ELambda(EVar('_var1780').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), EGetField(EGetField(EVar('_var1780').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), 'val').with_type(TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))), 'rq_host').with_type(TNative('HostAndPort')))).with_type(TBag(TNative('HostAndPort'))), ELambda(EVar('_var1778').with_type(TNative('HostAndPort')), EUnaryOp('the', EMap(EFilter(EVar('conns').with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))), ELambda(EVar('_var5980').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), EBinOp(EGetField(EGetField(EVar('_var5980').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort')), '==', EVar('_var1778').with_type(TNative('HostAndPort'))).with_type(TBool()))).with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))), ELambda(EVar('_var5981').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), EFilter(EVar('conns').with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))), ELambda(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), EBinOp(EBinOp(EGetField(EGetField(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort')), '==', EGetField(EGetField(EVar('_var5981').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort'))).with_type(TBool()), 'and', EBinOp(EGetField(EGetField(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))), 'conn_state').with_type(TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), '==', EEnumEntry('READY').with_type(TEnum(('READY', 'PROCESSING', 'CHECKED_OUT')))).with_type(TBool())).with_type(TBool()))).with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))))).with_type(TBag(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))))).with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))))).with_type(TMap(TNative('HostAndPort'), TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))))).with_type(TMap(TNative('HostAndPort'), TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))))), EVar('p').with_type(TNative('HostAndPort'))).with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))), validate=True)
Exemple #16
0
 def test_regression09(self):
     simplify(EMap(EVar('exclude').with_type(TSet(TNative('String'))), ELambda(EVar('_var132121').with_type(TNative('String')), EVar('_var132121').with_type(TNative('String')))).with_type(TBag(TNative('String'))), validate=True)
Exemple #17
0
 def test_regression08(self):
     simplify(EUnaryOp('sum', EEmptyList().with_type(TBag(TFloat()))).with_type(TFloat()), validate=True, debug=True)
 def test_regression04(self):
     e = EBinOp(ECond(EBinOp(EUnaryOp('len', EFilter(EBinOp(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), '+', ESingleton(ETuple((EUnaryOp('len', EMap(EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), EMakeRecord((('score', EVar('score').with_type(TFloat())), ('startOffset', EVar('startOffset').with_type(TNative('int /* st */'))), ('endOffset', EVar('endOffset').with_type(TNative('int /* ed */'))), ('important', EBinOp(EBinOp(EUnaryOp('empty', EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBool()), 'or', EBinOp(EVar('score').with_type(TFloat()), '>', ECall('floatZero', ()).with_type(TFloat())).with_type(TBool())).with_type(TBool()), 'and', EBinOp(EUnaryOp('len', EMap(EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), '<', ECall('MAX_TOKENS', ()).with_type(TInt())).with_type(TBool())).with_type(TBool())))).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))).with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('_var71527').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('_var71527').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), '<', ECall('MAX_TOKENS', ()).with_type(TInt())).with_type(TBool()), EMap(EBinOp(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), '+', ESingleton(ETuple((EUnaryOp('len', EMap(EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), EMakeRecord((('score', EVar('score').with_type(TFloat())), ('startOffset', EVar('startOffset').with_type(TNative('int /* st */'))), ('endOffset', EVar('endOffset').with_type(TNative('int /* ed */'))), ('important', EBinOp(EBinOp(EUnaryOp('empty', EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBool()), 'or', EBinOp(EVar('score').with_type(TFloat()), '>', ECall('floatZero', ()).with_type(TFloat())).with_type(TBool())).with_type(TBool()), 'and', EBinOp(EUnaryOp('len', EMap(EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), '<', ECall('MAX_TOKENS', ()).with_type(TInt())).with_type(TBool())).with_type(TBool())))).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))).with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('_var71528').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), ETuple((ENum(0).with_type(TInt()), EMakeRecord((('score', ENum(0).with_type(TFloat())), ('startOffset', ENative(ENum(0).with_type(TInt())).with_type(TNative('int /* st */'))), ('endOffset', ENative(ENum(0).with_type(TInt())).with_type(TNative('int /* ed */'))), ('important', EBool(False).with_type(TBool())))).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))).with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), EEmptyList().with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), '-', ECond(EBinOp(EUnaryOp('len', EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('_var71527').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('_var71527').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), '<', ECall('MAX_TOKENS', ()).with_type(TInt())).with_type(TBool()), EMap(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('_var71528').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), ETuple((ENum(0).with_type(TInt()), EMakeRecord((('score', ENum(0).with_type(TFloat())), ('startOffset', ENative(ENum(0).with_type(TInt())).with_type(TNative('int /* st */'))), ('endOffset', ENative(ENum(0).with_type(TInt())).with_type(TNative('int /* ed */'))), ('important', EBool(False).with_type(TBool())))).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))).with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), EEmptyList().with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))
     for ee in sorted(list(all_exps(e)), key=lambda x: x.size()):
         if isinstance(ee, ELambda):
             continue
         simplify(ee, validate=True)
 def test_regression06(self):
     simplify(EFilter(EMapKeys(EMakeMap2(EMap(EVar('xs').with_type(TBag(THandle('H', TNative('Value')))), ELambda(EVar('_var11125').with_type(THandle('H', TNative('Value'))), EGetField(EVar('_var11125').with_type(THandle('H', TNative('Value'))), 'val').with_type(TNative('Value')))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var11120').with_type(TNative('Value')), EUnaryOp('len', EFilter(EMap(EVar('xs').with_type(TBag(THandle('H', TNative('Value')))), ELambda(EVar('_var11125').with_type(THandle('H', TNative('Value'))), EGetField(EVar('_var11125').with_type(THandle('H', TNative('Value'))), 'val').with_type(TNative('Value')))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var11121').with_type(TNative('Value')), EBinOp(EVar('_var11120').with_type(TNative('Value')), '==', EVar('_var11121').with_type(TNative('Value'))).with_type(TBool()))).with_type(TBag(TNative('Value')))).with_type(TInt()))).with_type(TMap(TNative('Value'), TInt()))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var665135').with_type(TNative('Value')), EUnaryOp('not', EBinOp(EVar('_var665135').with_type(TNative('Value')), 'in', EMapKeys(EMakeMap2(EMap(EBinOp(EVar('xs').with_type(TBag(THandle('H', TNative('Value')))), '+', ESingleton(EVar('x').with_type(THandle('H', TNative('Value')))).with_type(TBag(THandle('H', TNative('Value'))))).with_type(TBag(THandle('H', TNative('Value')))), ELambda(EVar('_var11125').with_type(THandle('H', TNative('Value'))), EGetField(EVar('_var11125').with_type(THandle('H', TNative('Value'))), 'val').with_type(TNative('Value')))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var11120').with_type(TNative('Value')), EUnaryOp('len', EFilter(EMap(EBinOp(EVar('xs').with_type(TBag(THandle('H', TNative('Value')))), '+', ESingleton(EVar('x').with_type(THandle('H', TNative('Value')))).with_type(TBag(THandle('H', TNative('Value'))))).with_type(TBag(THandle('H', TNative('Value')))), ELambda(EVar('_var11125').with_type(THandle('H', TNative('Value'))), EGetField(EVar('_var11125').with_type(THandle('H', TNative('Value'))), 'val').with_type(TNative('Value')))).with_type(TBag(TNative('Value'))), ELambda(EVar('_var11121').with_type(TNative('Value')), EBinOp(EVar('_var11120').with_type(TNative('Value')), '==', EVar('_var11121').with_type(TNative('Value'))).with_type(TBool()))).with_type(TBag(TNative('Value')))).with_type(TInt()))).with_type(TMap(TNative('Value'), TInt()))).with_type(TBag(TNative('Value')))).with_type(TBool())).with_type(TBool()))).with_type(TBag(TNative('Value'))))
 def test_regression09(self):
     simplify(EMap(EVar('exclude').with_type(TSet(TNative('String'))), ELambda(EVar('_var132121').with_type(TNative('String')), EVar('_var132121').with_type(TNative('String')))).with_type(TBag(TNative('String'))), validate=True)
Exemple #21
0
    def _add_subquery(self, sub_q: Query, used_by: Stm) -> Stm:
        """Add a query that helps maintain some other state.

        Parameters:
            sub_q - the specification of the helper query
            used_by - the statement that calls `sub_q`

        If a query already exists that is equivalent to `sub_q`, this method
        returns `used_by` rewritten to use the existing query and does not add
        the query to the implementation.  Otherwise it returns `used_by`
        unchanged.
        """

        with task("adding query", query=sub_q.name):
            sub_q = shallow_copy(sub_q)
            with task("checking whether we need more handle assumptions"):
                new_a = implicit_handle_assumptions(
                    reachable_handles_at_method(self.spec, sub_q))
                if not valid(EImplies(EAll(sub_q.assumptions), EAll(new_a))):
                    event("we do!")
                    sub_q.assumptions = list(
                        itertools.chain(sub_q.assumptions, new_a))

            with task("repairing state var boundaries"):
                extra_available_state = [
                    e for v, e in self._concretization_functions
                ]
                sub_q.ret = repair_well_formedness(
                    strip_EStateVar(sub_q.ret), self.context_for_method(sub_q),
                    extra_available_state)

            with task("simplifying"):
                orig_a = sub_q.assumptions
                orig_a_size = sum(a.size() for a in sub_q.assumptions)
                orig_ret_size = sub_q.ret.size()
                sub_q.assumptions = tuple(
                    simplify_or_ignore(a) for a in sub_q.assumptions)
                sub_q.ret = simplify(sub_q.ret)
                a_size = sum(a.size() for a in sub_q.assumptions)
                ret_size = sub_q.ret.size()
                event("|assumptions|: {} -> {}".format(orig_a_size, a_size))
                event("|ret|: {} -> {}".format(orig_ret_size, ret_size))

                if a_size > orig_a_size:
                    print("NO, BAD SIMPLIFICATION")
                    print("original")
                    for a in orig_a:
                        print(" - {}".format(pprint(a)))
                    print("simplified")
                    for a in sub_q.assumptions:
                        print(" - {}".format(pprint(a)))
                    assert False

            state_vars = self.abstract_state
            funcs = self.extern_funcs
            qq = find_one(
                self.query_specs, lambda qq: dedup_queries.value and
                queries_equivalent(qq,
                                   sub_q,
                                   state_vars=state_vars,
                                   extern_funcs=funcs,
                                   assumptions=EAll(self.abstract_invariants)))
            if qq is not None:
                event("subgoal {} is equivalent to {}".format(
                    sub_q.name, qq.name))
                arg_reorder = [[x[0] for x in sub_q.args].index(a)
                               for (a, t) in qq.args]

                class Repl(BottomUpRewriter):
                    def visit_ECall(self, e):
                        args = tuple(self.visit(a) for a in e.args)
                        if e.func == sub_q.name:
                            args = tuple(args[idx] for idx in arg_reorder)
                            return ECall(qq.name, args).with_type(e.type)
                        else:
                            return ECall(e.func, args).with_type(e.type)

                used_by = Repl().visit(used_by)
            else:
                self.add_query(sub_q)
            return used_by
Exemple #22
0
 def test_regression07(self):
     e = EGetField(EGetField(EArgMin(EBinOp(EVar('reqs').with_type(TBag(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))))), '+', ESingleton(EVar('r').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))))).with_type(TBag(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))))).with_type(TBag(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))))), ELambda(EVar('_var19096610').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), EGetField(EGetField(EVar('_var19096610').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), 'val').with_type(TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))), 'rq_expiration').with_type(TNative('Date_t')))).with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), 'val').with_type(TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))), 'rq_host').with_type(TNative('HostAndPort'))
     print(pprint(e))
     simplify(e, validate=True)
 def test_regression08(self):
     simplify(EUnaryOp('sum', EEmptyList().with_type(TBag(TFloat()))).with_type(TFloat()), validate=True, debug=True)
Exemple #24
0
    def _add_subquery(self, sub_q : Query, used_by : Stm) -> Stm:
        """Add a query that helps maintain some other state.

        Parameters:
            sub_q - the specification of the helper query
            used_by - the statement that calls `sub_q`

        If a query already exists that is equivalent to `sub_q`, this method
        returns `used_by` rewritten to use the existing query and does not add
        the query to the implementation.  Otherwise it returns `used_by`
        unchanged.
        """

        with task("adding query", query=sub_q.name):
            sub_q = shallow_copy(sub_q)
            with task("checking whether we need more handle assumptions"):
                new_a = implicit_handle_assumptions(
                    reachable_handles_at_method(self.spec, sub_q))
                if not valid(EImplies(EAll(sub_q.assumptions), EAll(new_a))):
                    event("we do!")
                    sub_q.assumptions = list(itertools.chain(sub_q.assumptions, new_a))

            with task("repairing state var boundaries"):
                extra_available_state = [e for v, e in self._concretization_functions]
                sub_q.ret = repair_well_formedness(
                    strip_EStateVar(sub_q.ret),
                    self.context_for_method(sub_q),
                    extra_available_state)

            with task("simplifying"):
                orig_a = sub_q.assumptions
                orig_a_size = sum(a.size() for a in sub_q.assumptions)
                orig_ret_size = sub_q.ret.size()
                sub_q.assumptions = tuple(simplify_or_ignore(a) for a in sub_q.assumptions)
                sub_q.ret = simplify(sub_q.ret)
                a_size = sum(a.size() for a in sub_q.assumptions)
                ret_size = sub_q.ret.size()
                event("|assumptions|: {} -> {}".format(orig_a_size, a_size))
                event("|ret|: {} -> {}".format(orig_ret_size, ret_size))

                if a_size > orig_a_size:
                    print("NO, BAD SIMPLIFICATION")
                    print("original")
                    for a in orig_a:
                        print(" - {}".format(pprint(a)))
                    print("simplified")
                    for a in sub_q.assumptions:
                        print(" - {}".format(pprint(a)))
                    assert False

            state_vars = self.abstract_state
            funcs = self.extern_funcs
            qq = find_one(self.query_specs, lambda qq: dedup_queries.value and queries_equivalent(qq, sub_q, state_vars=state_vars, extern_funcs=funcs, assumptions=EAll(self.abstract_invariants)))
            if qq is not None:
                event("subgoal {} is equivalent to {}".format(sub_q.name, qq.name))
                arg_reorder = [[x[0] for x in sub_q.args].index(a) for (a, t) in qq.args]
                class Repl(BottomUpRewriter):
                    def visit_ECall(self, e):
                        args = tuple(self.visit(a) for a in e.args)
                        if e.func == sub_q.name:
                            args = tuple(args[idx] for idx in arg_reorder)
                            return ECall(qq.name, args).with_type(e.type)
                        else:
                            return ECall(e.func, args).with_type(e.type)
                used_by = Repl().visit(used_by)
            else:
                self.add_query(sub_q)
            return used_by
 def test_regression10(self):
     simplify(EMapGet(EStateVar(EMakeMap2(EMap(EVar('reqs').with_type(TBag(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))))), ELambda(EVar('_var1780').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), EGetField(EGetField(EVar('_var1780').with_type(THandle('Request', TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>')))))), 'val').with_type(TRecord((('rq_expiration', TNative('Date_t')), ('rq_host', TNative('HostAndPort')), ('rq_callback', TNative('std::unique_ptr<ConnectionPool::GetConnectionCallback>'))))), 'rq_host').with_type(TNative('HostAndPort')))).with_type(TBag(TNative('HostAndPort'))), ELambda(EVar('_var1778').with_type(TNative('HostAndPort')), EUnaryOp('the', EMap(EFilter(EVar('conns').with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))), ELambda(EVar('_var5980').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), EBinOp(EGetField(EGetField(EVar('_var5980').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort')), '==', EVar('_var1778').with_type(TNative('HostAndPort'))).with_type(TBool()))).with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))), ELambda(EVar('_var5981').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), EFilter(EVar('conns').with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))), ELambda(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), EBinOp(EBinOp(EGetField(EGetField(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort')), '==', EGetField(EGetField(EVar('_var5981').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort'))).with_type(TBool()), 'and', EBinOp(EGetField(EGetField(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))), 'conn_state').with_type(TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), '==', EEnumEntry('READY').with_type(TEnum(('READY', 'PROCESSING', 'CHECKED_OUT')))).with_type(TBool())).with_type(TBool()))).with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))))).with_type(TBag(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))))).with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))))).with_type(TMap(TNative('HostAndPort'), TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))))).with_type(TMap(TNative('HostAndPort'), TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool()))))))), EVar('p').with_type(TNative('HostAndPort'))).with_type(TBag(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_last_used', TInt()), ('conn_dropped', TBool())))))), validate=True)
Exemple #26
0
def simplify_or_ignore(e):
    ee = simplify(e)
    return ee if ee.size() < e.size() else e
 def test_regression01(self):
     simplify(EGetField(EMapGet(EMakeMap2(ECond(EUnaryOp('not', EBinOp(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'in', EVar('conns').with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))))).with_type(TBool())).with_type(TBool()), EBinOp(ESingleton(EVar('c').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))).with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))), '+', EVar('conns').with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))))).with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))), EVar('conns').with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))))).with_type(TList(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))), ELambda(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), EMakeRecord((('conn_state', EEnumEntry('CHECKED_OUT').with_type(TEnum(('READY', 'PROCESSING', 'CHECKED_OUT')))), ('conn_host', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort'))), ('conn_iface', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_iface').with_type(TNative('ConnectionPool::ConnectionInterface*'))), ('conn_next_refresh', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_next_refresh').with_type(TNative('Date_t'))), ('conn_returned', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_returned').with_type(TNative('Date_t'))), ('conn_dropped', EGetField(EGetField(EVar('_var248387').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), 'val').with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_dropped').with_type(TBool())))).with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))).with_type(TMap(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool()))))), EVar('_var1220993').with_type(THandle('Connection', TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))))).with_type(TRecord((('conn_state', TEnum(('READY', 'PROCESSING', 'CHECKED_OUT'))), ('conn_host', TNative('HostAndPort')), ('conn_iface', TNative('ConnectionPool::ConnectionInterface*')), ('conn_next_refresh', TNative('Date_t')), ('conn_returned', TNative('Date_t')), ('conn_dropped', TBool())))), 'conn_host').with_type(TNative('HostAndPort')), validate=True, debug=True)
Exemple #28
0
 def test_regression04(self):
     e = EBinOp(ECond(EBinOp(EUnaryOp('len', EFilter(EBinOp(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), '+', ESingleton(ETuple((EUnaryOp('len', EMap(EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), EMakeRecord((('score', EVar('score').with_type(TFloat())), ('startOffset', EVar('startOffset').with_type(TNative('int /* st */'))), ('endOffset', EVar('endOffset').with_type(TNative('int /* ed */'))), ('important', EBinOp(EBinOp(EUnaryOp('empty', EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBool()), 'or', EBinOp(EVar('score').with_type(TFloat()), '>', ECall('floatZero', ()).with_type(TFloat())).with_type(TBool())).with_type(TBool()), 'and', EBinOp(EUnaryOp('len', EMap(EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), '<', ECall('MAX_TOKENS', ()).with_type(TInt())).with_type(TBool())).with_type(TBool())))).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))).with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('_var71527').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('_var71527').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), '<', ECall('MAX_TOKENS', ()).with_type(TInt())).with_type(TBool()), EMap(EBinOp(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), '+', ESingleton(ETuple((EUnaryOp('len', EMap(EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), EMakeRecord((('score', EVar('score').with_type(TFloat())), ('startOffset', EVar('startOffset').with_type(TNative('int /* st */'))), ('endOffset', EVar('endOffset').with_type(TNative('int /* ed */'))), ('important', EBinOp(EBinOp(EUnaryOp('empty', EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBool()), 'or', EBinOp(EVar('score').with_type(TFloat()), '>', ECall('floatZero', ()).with_type(TFloat())).with_type(TBool())).with_type(TBool()), 'and', EBinOp(EUnaryOp('len', EMap(EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EVar('t').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), '<', ECall('MAX_TOKENS', ()).with_type(TInt())).with_type(TBool())).with_type(TBool())))).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))).with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('_var71528').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), ETuple((ENum(0).with_type(TInt()), EMakeRecord((('score', ENum(0).with_type(TFloat())), ('startOffset', ENative(ENum(0).with_type(TInt())).with_type(TNative('int /* st */'))), ('endOffset', ENative(ENum(0).with_type(TInt())).with_type(TNative('int /* ed */'))), ('important', EBool(False).with_type(TBool())))).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))).with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), EEmptyList().with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), '-', ECond(EBinOp(EUnaryOp('len', EFilter(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('_var71527').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), EGetField(ETupleGet(EVar('_var71527').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), 1).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))), 'important').with_type(TBool()))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TInt()), '<', ECall('MAX_TOKENS', ()).with_type(TInt())).with_type(TBool()), EMap(EVar('tokens').with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), ELambda(EVar('_var71528').with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))), ETuple((ENum(0).with_type(TInt()), EMakeRecord((('score', ENum(0).with_type(TFloat())), ('startOffset', ENative(ENum(0).with_type(TInt())).with_type(TNative('int /* st */'))), ('endOffset', ENative(ENum(0).with_type(TInt())).with_type(TNative('int /* ed */'))), ('important', EBool(False).with_type(TBool())))).with_type(TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))).with_type(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool()))))))), EEmptyList().with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))).with_type(TBag(TTuple((TInt(), TRecord((('score', TFloat()), ('startOffset', TNative('int /* st */')), ('endOffset', TNative('int /* ed */')), ('important', TBool())))))))
     for ee in sorted(list(all_exps(e)), key=lambda x: x.size()):
         if isinstance(ee, ELambda):
             continue
         simplify(ee, validate=True)