def make_check_state(original_contents, verbose_base=0, **kwargs): expected_output, orig_cmds, orig_retcode = diagnose_error.get_coq_output( kwargs['coqc'], kwargs['coqc_args'], original_contents, kwargs['timeout'], verbose_base=2, **kwargs) @memoize def check_contents(contents): output, cmds, retcode = diagnose_error.get_coq_output( kwargs['coqc'], kwargs['coqc_args'], contents, kwargs['timeout'], verbose_base=2, **kwargs) # TODO: Should we be checking the error message and the retcode and the output, or just the retcode? retval = (diagnose_error.has_error(output) or output != expected_output or retcode != orig_retcode) if retval: if kwargs['verbose'] + verbose_base >= 3: kwargs['log']('Failed change. Error when running "%s":\n%s' % ('" "'.join(cmds), output)) elif kwargs['verbose'] + verbose_base >= 4: kwargs['log']('Successful change') if kwargs['verbose'] + verbose_base >= 5: kwargs['log']('New contents:\n"""\n%s\n"""' % contents) return not retval def check_state(state): return check_contents(state_to_contents(state)) return check_state
def get_ltac_support_snippet(coqc, **kwargs): if coqc in LTAC_SUPPORT_SNIPPET.keys(): return LTAC_SUPPORT_SNIPPET[coqc] test = r'''Inductive False := . Axiom proof_admitted : False. Tactic Notation "admit" := abstract case proof_admitted.''' errinfo = {} for before, after in (('', 'Declare ML Module "ltac_plugin".\n'), ('Require Coq.Init.Notations.\n', 'Import Coq.Init.Notations.\n')): contents = '%s\n%s\n%s' % (before, after, test) output, cmds, retcode = get_coq_output( coqc, ('-q', '-nois'), contents, timeout_val=None, verbose_base=3, is_coqtop=kwargs['coqc_is_coqtop'], **kwargs) if retcode == 0: LTAC_SUPPORT_SNIPPET[coqc] = (before, after) return (before, after) else: errinfo[contents] = { 'output': output, 'cmds': cmds, 'retcode': retcode } raise Exception( 'No valid ltac support snipped found. Debugging info: %s' % repr(errinfo))
def get_proof_term_works_with_time(coqc_prog, **kwargs): contents = r"""Lemma foo : forall _ : Type, Type. Proof (fun x => x).""" output, cmds, retcode = get_coq_output(coqc_prog, ('-time', '-q'), contents, 1, verbose_base=3, **kwargs) return 'Error: Attempt to save an incomplete proof' not in output
def check_contents(contents): output, cmds = diagnose_error.get_coq_output(kwargs['coqc'], kwargs['coqc_args'], contents, kwargs['timeout'], verbose_base=2, **kwargs) retval = (diagnose_error.has_error(output) or output != expected_output) if retval: if kwargs['verbose'] + verbose_base >= 3: kwargs['log']('Failed change. Error when running "%s":\n%s' % ('" "'.join(cmds), output)) elif kwargs['verbose'] + verbose_base >= 4: kwargs['log']('Successful change') if kwargs['verbose'] + verbose_base >= 5: kwargs['log']('New contents:\n"""\n%s\n"""' % contents) return not retval
if env['verbose'] >= 1: env['log']('Listing identifiers...') unknown = [] closed_idents = [] open_idents = [] errors = [] ignore_header = ('Welcome to Coq', '[Loading ML file') error_header = ('Toplevel input, characters',) for filename in sorted(env['_CoqProject_v_files']): if env['verbose'] >= 2: env['log']('Qualifying identifiers in %s...' % filename) if env['verbose'] == 1: env['log']('Printing assumptions in %s...' % filename) libname = lib_of_filename(filename, **env) require_statement = 'Require %s.\n' % libname search_code = r"""%s Set Search Output Name Only. SearchPattern _ inside %s.""" % (require_statement, libname) output, cmds, retcode = get_coq_output(env['coqc'], env['coqc_args'], search_code, 0, is_coqtop=env['coqc_is_coqtop'], verbose_base=3, **env) identifiers = sorted(fix_identifiers(set(i.strip() for i in output.split('\n') if i.strip()), libname)) print_assumptions_code = require_statement + '\n'.join('Locate %s.\nPrint Assumptions %s.' % (i, i) for i in identifiers) if env['verbose'] >= 2: env['log']('Printing assumptions...') output, cmds, retcode = get_coq_output(env['coqtop'], env['coqc_args'], print_assumptions_code, 0, is_coqtop=True, pass_on_stdin=True, verbose_base=3, **env) i = 0 statements = output.split('\nCoq <') while i < len(statements): if i+1 < len(statements) and ' Closed under the global context ' in statements[i+1].replace('\n', ' '): last, ctype = get_constant_name_from_locate(statements[i]) closed_idents.append((last, ctype)) if env['verbose'] >= 2: env['log']('Closed: %s (%s)' % (last, ctype)) i += 2 elif i+1 < len(statements) and 'Axioms:' in statements[i+1].replace('\n', ' '): last, ctype = get_constant_name_from_locate(statements[i]) open_idents.append((last, ctype, statements[i+1]))