예제 #1
0
파일: mypyvy.py 프로젝트: jrkoenig/mypyvy
def parse_args(args: List[str]) -> utils.MypyvyArgs:
    argparser = argparse.ArgumentParser()

    subparsers = argparser.add_subparsers(title='subcommands',
                                          dest='subcommand')
    all_subparsers = []

    verify_subparser = subparsers.add_parser(
        'verify', help='verify that the invariants are inductive')
    verify_subparser.set_defaults(main=verify)
    all_subparsers.append(verify_subparser)

    updr_subparser = subparsers.add_parser(
        'updr',
        help=
        'search for a strengthening that proves the invariant named by the --safety=NAME flag'
    )
    updr_subparser.set_defaults(main=do_updr)
    all_subparsers.append(updr_subparser)

    bmc_subparser = subparsers.add_parser(
        'bmc',
        help=
        'bounded model check to depth given by the --depth=DEPTH flag for property given by the --safety=NAME flag'
    )
    bmc_subparser.set_defaults(main=bmc)
    all_subparsers.append(bmc_subparser)

    theorem_subparser = subparsers.add_parser(
        'theorem',
        help=
        'check state-independent theorems about the background axioms of a model'
    )
    theorem_subparser.set_defaults(main=theorem)
    all_subparsers.append(theorem_subparser)

    trace_subparser = subparsers.add_parser(
        'trace',
        help=
        'search for concrete executions that satisfy query described by the file\'s trace declaration'
    )
    trace_subparser.set_defaults(main=trace)
    all_subparsers.append(trace_subparser)

    generate_parser_subparser = subparsers.add_parser(
        'generate-parser',
        help=
        'internal command used by benchmarking infrastructure to avoid certain race conditions'
    )
    generate_parser_subparser.set_defaults(
        main=nop
    )  # parser is generated implicitly by main when it parses the program
    all_subparsers.append(generate_parser_subparser)

    typecheck_subparser = subparsers.add_parser(
        'typecheck', help='typecheck the file, report any errors, and exit')
    typecheck_subparser.set_defaults(
        main=nop)  # program is always typechecked; no further action required
    all_subparsers.append(typecheck_subparser)

    relax_subparser = subparsers.add_parser(
        'relax',
        help=
        'produce a version of the file that is "relaxed", in a way that is indistinguishable for universal invariants'
    )
    relax_subparser.set_defaults(main=relax)
    all_subparsers.append(relax_subparser)

    all_subparsers += pd.add_argparsers(subparsers)

    for s in all_subparsers:
        s.add_argument(
            '--forbid-parser-rebuild',
            action=utils.YesNoAction,
            default=False,
            help=
            'force loading parser from disk (helps when running mypyvy from multiple processes)'
        )
        s.add_argument('--log',
                       default='warning',
                       choices=['error', 'warning', 'info', 'debug'],
                       help='logging level')
        s.add_argument('--log-time',
                       action=utils.YesNoAction,
                       default=False,
                       help='make each log message include current time')
        s.add_argument('--log-xml',
                       action=utils.YesNoAction,
                       default=False,
                       help='log in XML format')
        s.add_argument('--seed',
                       type=int,
                       default=0,
                       help="value for z3's smt.random_seed")
        s.add_argument(
            '--print-program-repr',
            action=utils.YesNoAction,
            default=False,
            help=
            'print a machine-readable representation of the program after parsing'
        )
        s.add_argument('--print-program',
                       action=utils.YesNoAction,
                       default=False,
                       help='print the program after parsing')
        s.add_argument(
            '--key-prefix',
            help='additional string to use in front of names sent to z3')
        s.add_argument('--minimize-models',
                       action=utils.YesNoAction,
                       default=True,
                       help='search for models with minimal cardinality')
        s.add_argument('--timeout',
                       type=int,
                       default=None,
                       help='z3 timeout (milliseconds)')
        s.add_argument('--exit-on-error',
                       action=utils.YesNoAction,
                       default=False,
                       help='exit after reporting first error')
        s.add_argument('--ipython',
                       action=utils.YesNoAction,
                       default=False,
                       help='run IPython with s and prog at the end')
        s.add_argument(
            '--error-filename-basename',
            action=utils.YesNoAction,
            default=False,
            help='print only the basename of the input file in error messages')
        s.add_argument('--query-time',
                       action=utils.YesNoAction,
                       default=True,
                       help='report how long various z3 queries take')
        s.add_argument('--print-counterexample',
                       action=utils.YesNoAction,
                       default=True,
                       help='print counterexamples')
        s.add_argument('--print-cmdline',
                       action=utils.YesNoAction,
                       default=True,
                       help='print the command line passed to mypyvy')
        s.add_argument(
            '--clear-cache',
            action=utils.YesNoAction,
            default=False,
            help=
            'do not load from cache, but dump to cache as usual (effectively clearing the cache before starting)'
        )
        s.add_argument(
            '--clear-cache-memo',
            action=utils.YesNoAction,
            default=False,
            help=
            'load only discovered states from the cache, but dump to cache as usual (effectively clearing the memoization cache before starting, while keeping discovered states and transitions)'
        )
        s.add_argument(
            '--cache-only',
            action=utils.YesNoAction,
            default=False,
            help='assert that the caches already contain all the answers')
        s.add_argument(
            '--cache-only-discovered',
            action=utils.YesNoAction,
            default=False,
            help=
            'assert that the discovered states already contain all the answers'
        )

        # for diagrams:
        s.add_argument(
            '--simplify-diagram',
            action=utils.YesNoAction,
            default=(s is updr_subparser),
            default_description='yes for updr, else no',
            help=
            'in diagram generation, substitute existentially quantified variables that are equal to constants'
        )
        s.add_argument(
            '--diagrams-subclause-complete',
            action=utils.YesNoAction,
            default=False,
            help=
            'in diagram generation, "complete" the diagram so that every stronger '
            'clause is a subclause')

    updr_subparser.add_argument(
        '--use-z3-unsat-cores',
        action=utils.YesNoAction,
        default=True,
        help='generalize diagrams using brute force instead of unsat cores')
    updr_subparser.add_argument(
        '--smoke-test',
        action=utils.YesNoAction,
        default=False,
        help=
        '(for debugging mypyvy itself) run bmc to confirm every conjunct added to a frame'
    )
    updr_subparser.add_argument(
        '--assert-inductive-trace',
        action=utils.YesNoAction,
        default=False,
        help=
        '(for debugging mypyvy itself) check that frames are always inductive')

    updr_subparser.add_argument(
        '--sketch',
        action=utils.YesNoAction,
        default=False,
        help=
        'use sketched invariants as additional safety (currently only in automaton)'
    )

    updr_subparser.add_argument(
        '--automaton',
        action=utils.YesNoAction,
        default=False,
        help='whether to run vanilla UPDR or phase UPDR')
    updr_subparser.add_argument(
        '--block-may-cexs',
        action=utils.YesNoAction,
        default=False,
        help="treat failures to push as additional proof obligations")
    updr_subparser.add_argument(
        '--push-frame-zero',
        default='if_trivial',
        choices=['if_trivial', 'always', 'never'],
        help=
        "push lemmas from the initial frame: always/never/if_trivial, the latter is when there is more than one phase"
    )

    verify_subparser.add_argument(
        '--automaton',
        default='yes',
        choices=['yes', 'no', 'only'],
        help=
        "whether to use phase automata during verification. by default ('yes'), both non-automaton "
        "and automaton proofs are checked. 'no' means ignore automaton proofs. "
        "'only' means ignore non-automaton proofs.")
    verify_subparser.add_argument(
        '--check-transition',
        default=None,
        nargs='+',
        help="when verifying inductiveness, check only these transitions")
    verify_subparser.add_argument(
        '--check-invariant',
        default=None,
        nargs='+',
        help="when verifying inductiveness, check only these invariants")
    verify_subparser.add_argument(
        '--json',
        action='store_true',
        help="output machine-parseable verification results in JSON format")

    bmc_subparser.add_argument('--safety', help='property to check')
    bmc_subparser.add_argument('--depth',
                               type=int,
                               default=3,
                               metavar='N',
                               help='number of steps to check')

    argparser.add_argument('filename')

    return cast(utils.MypyvyArgs, argparser.parse_args(args))
예제 #2
0
def parse_args(args: List[str]) -> utils.MypyvyArgs:
    argparser = argparse.ArgumentParser()

    subparsers = argparser.add_subparsers(title='subcommands',
                                          dest='subcommand')
    all_subparsers = []

    verify_subparser = subparsers.add_parser(
        'verify', help='verify that the invariants are inductive')
    verify_subparser.set_defaults(main=verify)
    all_subparsers.append(verify_subparser)

    updr_subparser = subparsers.add_parser(
        'updr',
        help=
        'search for a strengthening that proves the invariant named by the --safety=NAME flag'
    )
    updr_subparser.set_defaults(main=do_updr)
    all_subparsers.append(updr_subparser)

    bmc_subparser = subparsers.add_parser(
        'bmc',
        help='bounded model check to depth given by the --depth=DEPTH flag '
        'for property given by the --safety=NAME flag')
    bmc_subparser.set_defaults(main=bmc)
    all_subparsers.append(bmc_subparser)

    theorem_subparser = subparsers.add_parser(
        'theorem',
        help=
        'check state-independent theorems about the background axioms of a model'
    )
    theorem_subparser.set_defaults(main=theorem)
    all_subparsers.append(theorem_subparser)

    trace_subparser = subparsers.add_parser(
        'trace',
        help=
        'search for concrete executions that satisfy query described by the file\'s trace declaration'
    )
    trace_subparser.set_defaults(main=trace)
    all_subparsers.append(trace_subparser)

    generate_parser_subparser = subparsers.add_parser(
        'generate-parser',
        help=
        'internal command used by benchmarking infrastructure to avoid certain race conditions'
    )
    # parser is generated implicitly by main when it parses the program, so we can just nop here
    generate_parser_subparser.set_defaults(main=nop)
    all_subparsers.append(generate_parser_subparser)

    typecheck_subparser = subparsers.add_parser(
        'typecheck', help='typecheck the file, report any errors, and exit')
    typecheck_subparser.set_defaults(
        main=nop)  # program is always typechecked; no further action required
    all_subparsers.append(typecheck_subparser)

    relax_subparser = subparsers.add_parser(
        'relax',
        help='produce a version of the file that is "relaxed", '
        'in a way that is indistinguishable for universal invariants')
    relax_subparser.set_defaults(main=relax)
    all_subparsers.append(relax_subparser)

    check_one_bounded_width_invariant_parser = subparsers.add_parser(
        'check-one-bounded-width-invariant', help='popl')
    check_one_bounded_width_invariant_parser.set_defaults(
        main=check_one_bounded_width_invariant)
    all_subparsers.append(check_one_bounded_width_invariant_parser)

    all_subparsers += pd.add_argparsers(subparsers)

    all_subparsers += rethink.add_argparsers(subparsers)

    all_subparsers += sep.add_argparsers(subparsers)

    for s in all_subparsers:
        s.add_argument(
            '--forbid-parser-rebuild',
            action=utils.YesNoAction,
            default=False,
            help=
            'force loading parser from disk (helps when running mypyvy from multiple processes)'
        )
        s.add_argument('--log',
                       default='warning',
                       choices=['error', 'warning', 'info', 'debug'],
                       help='logging level')
        s.add_argument('--log-time',
                       action=utils.YesNoAction,
                       default=False,
                       help='make each log message include current time')
        s.add_argument('--log-xml',
                       action=utils.YesNoAction,
                       default=False,
                       help='log in XML format')
        s.add_argument('--seed',
                       type=int,
                       default=0,
                       help="value for z3's smt.random_seed")
        s.add_argument(
            '--print-program',
            choices=['str', 'repr', 'faithful', 'without-invariants'],
            help='print program after parsing using given strategy')
        s.add_argument(
            '--key-prefix',
            help='additional string to use in front of names sent to z3')
        s.add_argument('--minimize-models',
                       action=utils.YesNoAction,
                       default=True,
                       help='search for models with minimal cardinality')
        s.add_argument('--timeout',
                       type=int,
                       default=None,
                       help='z3 timeout (milliseconds)')
        s.add_argument('--exit-on-error',
                       action=utils.YesNoAction,
                       default=False,
                       help='exit after reporting first error')
        s.add_argument('--ipython',
                       action=utils.YesNoAction,
                       default=False,
                       help='run IPython with s and prog at the end')
        s.add_argument(
            '--error-filename-basename',
            action=utils.YesNoAction,
            default=False,
            help='print only the basename of the input file in error messages')
        s.add_argument('--query-time',
                       action=utils.YesNoAction,
                       default=True,
                       help='report how long various z3 queries take')
        s.add_argument('--print-counterexample',
                       action=utils.YesNoAction,
                       default=True,
                       help='print counterexamples')
        s.add_argument('--print-negative-tuples',
                       action=utils.YesNoAction,
                       default=False,
                       help='print negative counterexamples')
        s.add_argument('--print-cmdline',
                       action=utils.YesNoAction,
                       default=True,
                       help='print the command line passed to mypyvy')
        s.add_argument(
            '--clear-cache',
            action=utils.YesNoAction,
            default=False,
            help='do not load from cache, but dump to cache as usual '
            '(effectively clearing the cache before starting)')
        s.add_argument(
            '--clear-cache-memo',
            action=utils.YesNoAction,
            default=False,
            help=
            'load only discovered states from the cache, but dump to cache as usual '
            '(effectively clearing the memoization cache before starting, '
            'while keeping discovered states and transitions)')
        s.add_argument(
            '--cache-only',
            action=utils.YesNoAction,
            default=False,
            help='assert that the caches already contain all the answers')
        s.add_argument(
            '--cache-only-discovered',
            action=utils.YesNoAction,
            default=False,
            help=
            'assert that the discovered states already contain all the answers'
        )
        s.add_argument(
            '--print-exit-code',
            action=utils.YesNoAction,
            default=False,
            help=
            'print the exit code before exiting (good for regression testing)')
        s.add_argument('--exit-0',
                       action=utils.YesNoAction,
                       default=False,
                       help='always exit with status 0 (good for testing)')

        s.add_argument(
            '--cvc4',
            action='store_true',
            help=
            'use CVC4 as the backend solver. this is not very well supported.')

        s.add_argument(
            '--smoke-test-solver',
            action=utils.YesNoAction,
            default=False,
            help=
            '(for debugging mypyvy itself) double check countermodels by evaluation'
        )

        # for diagrams:
        s.add_argument(
            '--simplify-diagram',
            action=utils.YesNoAction,
            default=(s is updr_subparser),
            default_description='yes for updr, else no',
            help=
            'in diagram generation, substitute existentially quantified variables '
            'that are equal to constants')

    updr_subparser.add_argument(
        '--use-z3-unsat-cores',
        action=utils.YesNoAction,
        default=True,
        help='generalize using unsat cores rather than brute force')
    updr_subparser.add_argument(
        '--assert-inductive-trace',
        action=utils.YesNoAction,
        default=False,
        help=
        '(for debugging mypyvy itself) check that frames are always inductive')

    verify_subparser.add_argument(
        '--check-transition',
        default=None,
        nargs='+',
        help="when verifying inductiveness, check only these transitions")
    verify_subparser.add_argument(
        '--check-invariant',
        default=None,
        nargs='+',
        help="when verifying inductiveness, check only these invariants")
    verify_subparser.add_argument(
        '--json',
        action='store_true',
        help="output machine-parseable verification results in JSON format")

    updr_subparser.add_argument(
        '--checkpoint-in',
        help='start from internal state as stored in given file')
    updr_subparser.add_argument(
        '--checkpoint-out',
        help='store internal state to given file')  # TODO: say when

    bmc_subparser.add_argument('--safety', help='property to check')
    bmc_subparser.add_argument('--depth',
                               type=int,
                               default=3,
                               metavar='N',
                               help='number of steps to check')
    bmc_subparser.add_argument('--relax',
                               action=utils.YesNoAction,
                               default=False,
                               help='relaxed semantics (domain can decrease)')

    argparser.add_argument('filename')

    return cast(utils.MypyvyArgs, argparser.parse_args(args))