Beispiel #1
0
        public IEnumerable <ProofState> Search(ProofState state, ErrorReporterDelegate er)
        {
            Contract.Requires <ArgumentNullException>(state != null, "rootState");

            IEnumerable <ProofState> enumerable;

            switch (ActiveStrategy)
            {
            case Strategy.Bfs:
                enumerable = BreadthFirstSeach.Search(state, er);
                break;

            case Strategy.Dfs:
                enumerable = DepthFirstSeach.Search(state, er);
                break;

            case Strategy.Undefined:
                throw new tcce.UnreachableException();

            default:
                enumerable = DepthFirstSeach.Search(state, er);
                break;
            }
            return(enumerable);
        }
Beispiel #2
0
        protected override void Execute(IntPtr bridgeFunc, IProgressMonitor subMonitor)
        {
            using (subMonitor.BeginTask("Exploring " + File.Name, 100))
            {
                BoostTestExploreDelegate bridge =
                    (BoostTestExploreDelegate)Marshal.GetDelegateForFunctionPointer(
                        bridgeFunc,
                        typeof(BoostTestExploreDelegate)
                    );

                VisitorDelegate visitTestCase = new VisitorDelegate(VisitTestCase);
                VisitorDelegate beginVisitTestSuite = new VisitorDelegate(BeginVisitTestSuite);
                VisitorDelegate endVisitTestSuite = new VisitorDelegate(EndVisitTestSuite);

                ErrorReporterDelegate errorReporter =
                    new ErrorReporterDelegate((text) => Logger.Log(LogSeverity.Error, text));

                bridge(
                    File.FullName,

                    visitTestCase,
                    beginVisitTestSuite,
                    endVisitTestSuite,

                    errorReporter
                );

                TestModelSerializer.PublishTestModel(TestModel, MessageSink);
            }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="program"></param>
        /// <param name="target"></param>
        /// <param name="erd"></param>
        ///  only used this to report error, local errors which are genereaed during searching should not use this

        /// <param name="r"></param>
        /// <returns></returns>
        public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Resolver r = null)
        {
            Contract.Requires(program != null);
            Contract.Requires(target != null);
            Stopwatch watch = new Stopwatch();

            watch.Start();
            _i = new Interpreter(program);
            _errorReporterDelegate = erd;

            var result = _i.EvalTacticApplication(target, r);

            var p = new Printer(Console.Out);

            p.PrintMembers(new List <MemberDecl>()
            {
                result
            }, 0, "");

            watch.Stop();
            Console.WriteLine("Time Used: " + watch.Elapsed.TotalSeconds.ToString());

            _errorReporterDelegate = null;
            return(result);
        }
Beispiel #4
0
        public static MemberDecl ApplyTacticInMethod(Program program, MemberDecl target, ErrorReporterDelegate erd,
                                                     Resolver r = null, Program raw = null)
        {
            Contract.Requires(program != null);
            Contract.Requires(target != null);
            Stopwatch watch = new Stopwatch();

            watch.Start();

            _driver = new TacnyDriver(program, erd);
            // backup datatype info, as this will be reset by the internal resolving process in tacny.
            // this contains datatype obj instance for comparing types
            Type.BackupScopes();
            var result = _driver.InterpretAndUnfoldTactic(target, r);

            Type.RestoreScopes();
            var p = new Printer(Console.Out);

            p.PrintMembers(new List <MemberDecl>()
            {
                result
            }, 0, "");

            watch.Stop();
            Console.WriteLine("Time Used: " + watch.Elapsed.TotalSeconds);
            _errorReporterDelegate = null;
            return(result);
        }
Beispiel #5
0
        public T Parse(string[] arguments, ErrorReporterDelegate errorReporter)
        {
            HasErrors = false;

            _errorReporter = errorReporter;

            _argumentsFromOutside = arguments ?? throw new ArgumentNullException(nameof(arguments), "Parameter(s) must be provided!");


            _parsedArgumentPoco = Activator.CreateInstance <T>();

            if (arguments.Length == 0)
            {
                return(_parsedArgumentPoco);
            }

            DetectPossibleArguments();

            ParseArgumentList();

            MapArgumentListToObject();
            SetDefaultValuesForUnseenFields();

            CheckForErrors();

            return(_parsedArgumentPoco);
        }
Beispiel #6
0
 internal static VerifyResult VerifyState(ProofState state, ErrorReporterDelegate er) {
   if (_proofList == null)
     _proofList = new List<ProofState>();
   if (_proofList.Count + 1 < SolutionCounter) {
     _proofList.Add(state);
     return VerifyResult.Cached;
   } else {
     _proofList.Add(state);
     var bodyList = new Dictionary<ProofState, BlockStmt>();
     foreach (var proofState in _proofList) {
       bodyList.Add(proofState, Util.InsertCode(proofState,
         new Dictionary<UpdateStmt, List<Statement>>() {
           {proofState.TacticApplication, proofState.GetGeneratedCode()}
         }));
     }
     var memberList = Util.GenerateMembers(state, bodyList);
     var prog = Util.GenerateDafnyProgram(state, memberList.Values.ToList());
     var result = Util.ResolveAndVerify(prog, errorInfo => { er?.Invoke(new CompoundErrorInformation(errorInfo.Tok, errorInfo.Msg, errorInfo, state)); });
     if (result.Count == 0)
       return VerifyResult.Verified;
     else {
       //TODO: find which proof state verified (if any)
       //TODO: update verification results
       
       //  er();
       return VerifyResult.Failed;
     }
   }
 }
Beispiel #7
0
    public static VerifyResult VerifyState(ProofState state, ErrorReporterDelegate er) {
      // at the momemnt,we don't propagate errors from buanches to user, no need to use er, in the future this will
      // come to play when repair kicks in

      var prog =  Util.GenerateResolvedProg(state);
      if (prog == null)
        return VerifyResult.Unresolved;

   //   ErrorReporterDelegate tmp_er =
     //   errorInfo => { er?.Invoke(new CompoundErrorInformation(errorInfo.Tok, errorInfo.Msg, errorInfo, state)); };
      var result = Util.VerifyResolvedProg(prog, null);
/*
      ErrorReporterDelegate tmp_er =
        errorInfo => { er?.Invoke(new CompoundErrorInformation(errorInfo.Tok, errorInfo.Msg, errorInfo, state)); };
      var boogieProg = Util.Translate(prog, prog.Name, tmp_er);
      PipelineStatistics stats;
      List<ErrorInformation> errorList;

      //Console.WriteLine("call verifier in Tacny !!!");
      PipelineOutcome tmp = Util.BoogiePipeline(boogieProg,
        new List<string> { prog.Name }, prog.Name, tmp_er,
        out stats, out errorList, prog);
*/

      if(result)
        return VerifyResult.Verified;
      else {
        return VerifyResult.Failed;
      }
    }
Beispiel #8
0
 private TacnyDriver(Program program, ErrorReporterDelegate erd)
 {
     Contract.Requires(Tcce.NonNull(program));
     // initialize state
     GetTimer().Restart();
     _state = new ProofState(program);
     _errorReporterDelegate = erd;
     _branches    = new List <IEnumerable <ProofState> >();
     _tacticCalls = 0;
 }
Beispiel #9
0
 public static List<Statement> FindSingleTactic(Program program, MemberDecl target,
   UpdateStmt chosenTacticCall, ErrorReporterDelegate erd, Program unresolvedProgram)
 {
   Contract.Requires(program != null);
   Contract.Requires(target != null);
   var i = new Interpreter(program, unresolvedProgram);
   _errorReporterDelegate = erd;
   var list = i.FindSingleTacticApplication(target, chosenTacticCall);
   _errorReporterDelegate = null;
   return list;
 }
Beispiel #10
0
 public static bool Verify(Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er, Program unresolvedProgram)
 {
   var translator = new Translator(dafnyProgram.reporter, er)
   {
     InsertChecksums = true,
     UniqueIdPrefix = uniqueIdPrefix
   };
   var boogieProgram = translator.Translate(dafnyProgram, unresolvedProgram);
   resolver.ReInitializeVerificationErrors(requestId, boogieProgram.Implementations);
   var outcome = BoogiePipeline(boogieProgram, 1 < CommandLineOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, er);
   return outcome == PipelineOutcome.Done || outcome == PipelineOutcome.VerificationCompleted;
 }
Beispiel #11
0
        public static List <Statement> FindSingleTactic(Program program, MemberDecl target,
                                                        UpdateStmt chosenTacticCall, ErrorReporterDelegate erd, Program unresolvedProgram)
        {
            Contract.Requires(program != null);
            Contract.Requires(target != null);
            var i = new Interpreter(program, unresolvedProgram);

            _errorReporterDelegate = erd;
            var list = i.FindSingleTacticApplication(target, chosenTacticCall);

            _errorReporterDelegate = null;
            return(list);
        }
Beispiel #12
0
        public static void VerifyResolvedProg(ProofState state, Program program,
                                              List <TacnyInterpreter.VerifyResult> res, List <int> idx,
                                              ErrorReporterDelegate er)
        {
            Contract.Requires <ArgumentNullException>(program != null);

#if _TACTIC_DEBUG_L1
            var printer = new Printer(Console.Out);
            Console.WriteLine("*********************Verifying Tactic Generated Prog*****************");
            printer.PrintProgram(program, true);
            Console.WriteLine("\n*********************Prog END*****************");
#endif


            _verificationCount++;
            Console.WriteLine("Verfication Count: " + _verificationCount);

            IEnumerable <Tuple <string, Bpl.Program> > boogieProg;

            //   try {
            boogieProg = Translator.Translate(program, program.reporter, null);

            foreach (var prog in boogieProg)
            {
                PipelineStatistics      stats;
                List <ErrorInformation> errorList;
                PipelineOutcome         tmp = BoogiePipeline(prog.Item2,
                                                             new List <string> {
                    program.Name
                }, program.Name, er,
                                                             out stats, out errorList, program);

                var curIdx = -1;
                for (var i = 0; i < errorList.Count; i++)
                {
                    var err = errorList[i];
                    if (err.Tok.line < TacnyDriver.TacticCodeTokLine)
                    {
                        curIdx           = 0 - err.Tok.line - 2;
                        res[idx[curIdx]] = TacnyInterpreter.VerifyResult.Failed;
                    }
                }
            }

            /*  } catch {
             *  Console.WriteLine("execption: set verify result as failed.");
             *  for(var i = 0; i < res.Count; i++) {
             *      res[i] = TacnyInterpreter.VerifyResult.Failed;
             *    }
             *  }*/
        }
Beispiel #13
0
 public IEnumerable<ProofState> Search(ProofState state, ErrorReporterDelegate er) {
   Contract.Requires<ArgumentNullException>(state != null, "rootState");
   
   switch (ActiveStrategy) {
     case Strategy.Bfs:
       return BreadthFirstSeach.Search(state, er);
     case Strategy.Dfs:
       return DepthFirstSeach.Search(state);
     case Strategy.Undefined:
       throw new tcce.UnreachableException();
     default:
       return BreadthFirstSeach.Search(state, er);
   }
 }
Beispiel #14
0
 public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Program unresolvedProgram = null) {
   Contract.Requires(program != null);
   Contract.Requires(target != null);
   // TODO Re-Enable with more permanent solution
   // Currently, if the interpreter is the same, static across calls, each time the interpreter is
   //   needed, it will just re-use the previous proof states, frames etc. Which will likely cause
   //   problems in the extension, where it is called many times consecutively.
   //if (_i == null) {
     _i = new Interpreter(program, unresolvedProgram);
   //}
   _errorReporterDelegate = erd;
   var result = _i.FindTacticApplication(target);
   _errorReporterDelegate = null;
   return result;
 }
Beispiel #15
0
        public static bool VerifyResolvedProg(Program program, ErrorReporterDelegate er)
        {
            Contract.Requires <ArgumentNullException>(program != null);

            var boogieProg = Translate(program, program.Name, er);
            PipelineStatistics      stats;
            List <ErrorInformation> errorList;

            //Console.WriteLine("call verifier in Tacny !!!");
            PipelineOutcome tmp = BoogiePipeline(boogieProg,
                                                 new List <string> {
                program.Name
            }, program.Name, er,
                                                 out stats, out errorList, program);

            return(errorList.Count == 0);
        }
Beispiel #16
0
        public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Program unresolvedProgram = null)
        {
            Contract.Requires(program != null);
            Contract.Requires(target != null);
            // TODO Re-Enable with more permanent solution
            // Currently, if the interpreter is the same, static across calls, each time the interpreter is
            //   needed, it will just re-use the previous proof states, frames etc. Which will likely cause
            //   problems in the extension, where it is called many times consecutively.
            //if (_i == null) {
            _i = new Interpreter(program, unresolvedProgram);
            //}
            _errorReporterDelegate = erd;
            var result = _i.FindTacticApplication(target);

            _errorReporterDelegate = null;
            return(result);
        }
Beispiel #17
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="program"></param>
    /// <param name="target"></param>
    /// <param name="erd"></param>
    ///  only used this to report error, local errors which are genereaed during searching should not use this

    /// <param name="r"></param>
    /// <returns></returns>
    public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Resolver r = null) {
      Contract.Requires(program != null);
      Contract.Requires(target != null);
      Stopwatch watch = new Stopwatch();
      watch.Start();
      _i = new Interpreter(program);
      _errorReporterDelegate = erd;

      var result = _i.EvalTacticApplication(target, r);

      var p = new Printer(Console.Out);
      p.PrintMembers(new List<MemberDecl>() { result }, 0, "");

      watch.Stop();
      Console.WriteLine("Time Used: " + watch.Elapsed.TotalSeconds.ToString());

      _errorReporterDelegate = null;
      return result;
    }
Beispiel #18
0
        internal static VerifyResult VerifyState(ProofState state, ErrorReporterDelegate er)
        {
            if (_proofList == null)
            {
                _proofList = new List <ProofState>();
            }
            if (_proofList.Count + 1 < SolutionCounter)
            {
                _proofList.Add(state);
                return(VerifyResult.Cached);
            }
            else
            {
                _proofList.Add(state);
                var bodyList = new Dictionary <ProofState, BlockStmt>();
                foreach (var proofState in _proofList)
                {
                    bodyList.Add(proofState, Util.InsertCode(proofState,
                                                             new Dictionary <UpdateStmt, List <Statement> >()
                    {
                        { proofState.TacticApplication, proofState.GetGeneratedCode() }
                    }));
                }
                var memberList = Util.GenerateMembers(state, bodyList);
                var prog       = Util.GenerateDafnyProgram(state, memberList.Values.ToList());
                var result     = Util.ResolveAndVerify(prog, errorInfo => { er?.Invoke(new CompoundErrorInformation(errorInfo.Tok, errorInfo.Msg, errorInfo, state)); });
                if (result.Count == 0)
                {
                    return(VerifyResult.Verified);
                }
                else
                {
                    //TODO: find which proof state verified (if any)
                    //TODO: update verification results

                    //  er();
                    return(VerifyResult.Failed);
                }
            }
        }
Beispiel #19
0
        public static VerifyResult VerifyState(ProofState state, ErrorReporterDelegate er)
        {
            // at the momemnt,we don't propagate errors from buanches to user, no need to use er, in the future this will
            // come to play when repair kicks in

            var prog = Util.GenerateResolvedProg(state);

            if (prog == null)
            {
                return(VerifyResult.Unresolved);
            }

            //   ErrorReporterDelegate tmp_er =
            //   errorInfo => { er?.Invoke(new CompoundErrorInformation(errorInfo.Tok, errorInfo.Msg, errorInfo, state)); };
            var result = Util.VerifyResolvedProg(prog, null);

/*
 *    ErrorReporterDelegate tmp_er =
 *      errorInfo => { er?.Invoke(new CompoundErrorInformation(errorInfo.Tok, errorInfo.Msg, errorInfo, state)); };
 *    var boogieProg = Util.Translate(prog, prog.Name, tmp_er);
 *    PipelineStatistics stats;
 *    List<ErrorInformation> errorList;
 *
 *    //Console.WriteLine("call verifier in Tacny !!!");
 *    PipelineOutcome tmp = Util.BoogiePipeline(boogieProg,
 *      new List<string> { prog.Name }, prog.Name, tmp_er,
 *      out stats, out errorList, prog);
 */

            if (result)
            {
                return(VerifyResult.Verified);
            }
            else
            {
                return(VerifyResult.Failed);
            }
        }
Beispiel #20
0
        private static void ReportOutcome(VC.VCGen.Outcome outcome, ErrorReporterDelegate er, string implName, IToken implTok, string requestId, TextWriter tw, int timeLimit, List<Counterexample> errors)
        {
            ErrorInformation errorInfo = null;

              switch (outcome)
              {
            case VCGen.Outcome.ReachedBound:
              tw.WriteLine(string.Format("Stratified Inlining: Reached recursion bound of {0}", CommandLineOptions.Clo.RecursionBound));
              break;
            case VCGen.Outcome.TimedOut:
              if (implName != null && implTok != null)
              {
            errorInfo = errorInformationFactory.CreateErrorInformation(implTok, string.Format("Verification timed out after {0} seconds ({1})", timeLimit, implName), requestId);

            //  Report timed out assertions as auxiliary info.
            if (errors != null)
            {
              var cmpr = new CounterexampleComparer();
              var timedOutAssertions = errors.Where(e => e.IsAuxiliaryCexForDiagnosingTimeouts).Distinct(cmpr).ToList();
              timedOutAssertions.Sort(cmpr);
              int idx = 1;
              foreach (Counterexample error in timedOutAssertions)
              {
                var callError = error as CallCounterexample;
                var returnError = error as ReturnCounterexample;
                var assertError = error as AssertCounterexample;
                IToken tok = null;
                if (callError != null)
                {
                  tok = callError.FailingCall.tok;
                }
                else if (returnError != null)
                {
                  tok = returnError.FailingReturn.tok;
                }
                else
                {
                  tok = assertError.FailingAssert.tok;
                }
                errorInfo.AddAuxInfo(tok, string.Format("unverified assertion due to timeout ({0} of {1})", idx++, timedOutAssertions.Count));
              }
            }
              }
              break;
            case VCGen.Outcome.OutOfMemory:
              if (implName != null && implTok != null)
              {
            errorInfo = errorInformationFactory.CreateErrorInformation(implTok, "Verification out of memory (" + implName + ")", requestId);
              }
              break;
            case VCGen.Outcome.Inconclusive:
              if (implName != null && implTok != null)
              {
            errorInfo = errorInformationFactory.CreateErrorInformation(implTok, "Verification inconclusive (" + implName + ")", requestId);
              }
              break;
              }

              if (errorInfo != null)
              {
            errorInfo.ImplementationName = implName;
            if (er != null)
            {
              lock (er)
              {
            er(errorInfo);
              }
            }
              }
        }
Beispiel #21
0
        private static void ProcessErrors(List<Counterexample> errors, VC.VCGen.Outcome outcome, TextWriter tw, ErrorReporterDelegate er, Implementation impl = null)
        {
            var implName = impl != null ? impl.Name : null;

              if (errors != null)
              {
            errors.Sort(new CounterexampleComparer());
            foreach (Counterexample error in errors)
            {
              if (error.IsAuxiliaryCexForDiagnosingTimeouts)
              {
            continue;
              }
              var errorInfo = CreateErrorInformation(error, outcome);
              errorInfo.ImplementationName = implName;

              if (CommandLineOptions.Clo.XmlSink != null)
              {
            WriteErrorInformationToXmlSink(errorInfo, error.Trace);
              }

              if (CommandLineOptions.Clo.EnhancedErrorMessages == 1)
              {
            foreach (string info in error.relatedInformation)
            {
              Contract.Assert(info != null);
              errorInfo.Out.WriteLine("       " + info);
            }
              }
              if (CommandLineOptions.Clo.ErrorTrace > 0)
              {
            errorInfo.Out.WriteLine("Execution trace:");
            error.Print(4, errorInfo.Out, b => { errorInfo.AddAuxInfo(b.tok, b.Label, "Execution trace"); });
              }
              if (CommandLineOptions.Clo.ModelViewFile != null)
              {
            error.PrintModel(errorInfo.Model);
              }

              printer.WriteErrorInformation(errorInfo, tw);

              if (er != null)
              {
            lock (er)
            {
              er(errorInfo);
            }
              }
            }
              }
        }
Beispiel #22
0
 public IEnumerable<ProofState> Search(ProofState state, ErrorReporterDelegate er) {
   Contract.Requires(state != null);
   return default(IEnumerable<ProofState>);
 }
Beispiel #23
0
    internal new static IEnumerable<ProofState> Search(ProofState rootState, ErrorReporterDelegate er){

      var queue = new Queue<IEnumerator<ProofState>>();
      queue.Enqueue(Interpreter.EvalStep(rootState).GetEnumerator());


      IEnumerator<ProofState> enumerator = Enumerable.Empty<ProofState>().GetEnumerator();

      while (queue.Count > 0){
        // check if there is any more item in the enumerartor, if so, MoveNext will move to the next item
        if (!enumerator.MoveNext()){
          // if no item in the current enumerator, pop a new enumerator from the queie, 
          enumerator = queue.Dequeue();
          // set the start point for enumulator, if there is no valid start point, i.e. empty, skip this one
          if (!enumerator.MoveNext())
            continue;
        }
        var proofState = enumerator.Current;
        //check if any new added code reuqires to call the dafny to verity, or reach the last line of code
        if (proofState.IfVerify || proofState.IsEvaluated()) {
          proofState.IfVerify = false;
          switch (VerifyState(proofState, er)){
            case VerifyResult.Verified:
              proofState.MarkCurFrameAsTerminated(true);
              if (proofState.IsTerminated()){
                 yield return proofState;
                 yield break;
              }
              //queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
              break;
            case VerifyResult.Failed:
              if (proofState.IsEvaluated()){
                proofState.MarkCurFrameAsTerminated(false);
                if(proofState.IsTerminated()) {
                  yield return proofState;
                  yield break;
                }
              }
              break;
            case VerifyResult.Unresolved:
              //discharge current branch if fails to resolve
              continue;
            default:
              throw new ArgumentOutOfRangeException();
          }
        }
        /*
       * when failed, check if this mmethod is evaluated , i.e. all tstmt are evalauted,
       * if so, dischard this branch and continue with the next one
       * otherwise, continue to evaluate the next stmt
       */
        if(!proofState.IsEvaluated()) {
          queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
        }
      }
    }
Beispiel #24
0
        private static void ReportOutcome(VC.VCGen.Outcome outcome, ErrorReporterDelegate er, string implName, IToken implTok, string requestId, TextWriter tw, int timeLimit)
        {
            ErrorInformation errorInfo = null;

              switch (outcome)
              {
            case VCGen.Outcome.ReachedBound:
              tw.WriteLine(string.Format("Stratified Inlining: Reached recursion bound of {0}", CommandLineOptions.Clo.RecursionBound));
              break;
            case VCGen.Outcome.TimedOut:
              if (implName != null && implTok != null)
              {
            errorInfo = errorInformationFactory.CreateErrorInformation(implTok, string.Format("Verification timed out after {0} seconds ({1})", timeLimit, implName), requestId);
              }
              break;
            case VCGen.Outcome.OutOfMemory:
              if (implName != null && implTok != null)
              {
            errorInfo = errorInformationFactory.CreateErrorInformation(implTok, "Verification out of memory (" + implName + ")", requestId);
              }
              break;
            case VCGen.Outcome.Inconclusive:
              if (implName != null && implTok != null)
              {
            errorInfo = errorInformationFactory.CreateErrorInformation(implTok, "Verification inconclusive (" + implName + ")", requestId);
              }
              break;
              }

              if (errorInfo != null)
              {
            errorInfo.ImplementationName = implName;
            if (er != null)
            {
              lock (er)
              {
            er(errorInfo);
              }
            }
              }
        }
Beispiel #25
0
        private static PipelineOutcome RunStagedHoudini(Program program, PipelineStatistics stats, ErrorReporterDelegate er)
        {
            Houdini.HoudiniSession.HoudiniStatistics houdiniStats = new Houdini.HoudiniSession.HoudiniStatistics();
              Houdini.StagedHoudini stagedHoudini = new Houdini.StagedHoudini(program, houdiniStats, ProgramFromFile);
              Houdini.HoudiniOutcome outcome = stagedHoudini.PerformStagedHoudiniInference();

              if (CommandLineOptions.Clo.PrintAssignment)
              {
            Console.WriteLine("Assignment computed by Houdini:");
            foreach (var x in outcome.assignment)
            {
              Console.WriteLine(x.Key + " = " + x.Value);
            }
              }

              if (CommandLineOptions.Clo.Trace)
              {
            int numTrueAssigns = 0;
            foreach (var x in outcome.assignment)
            {
              if (x.Value)
            numTrueAssigns++;
            }
            Console.WriteLine("Number of true assignments = " + numTrueAssigns);
            Console.WriteLine("Number of false assignments = " + (outcome.assignment.Count - numTrueAssigns));
            Console.WriteLine("Prover time = " + houdiniStats.proverTime.ToString("F2"));
            Console.WriteLine("Unsat core prover time = " + houdiniStats.unsatCoreProverTime.ToString("F2"));
            Console.WriteLine("Number of prover queries = " + houdiniStats.numProverQueries);
            Console.WriteLine("Number of unsat core prover queries = " + houdiniStats.numUnsatCoreProverQueries);
            Console.WriteLine("Number of unsat core prunings = " + houdiniStats.numUnsatCorePrunings);
              }

              foreach (Houdini.VCGenOutcome x in outcome.implementationOutcomes.Values)
              {
            ProcessOutcome(x.outcome, x.errors, "", stats, Console.Out, CommandLineOptions.Clo.ProverKillTime, er);
            ProcessErrors(x.errors, x.outcome, Console.Out, er);
              }

              return PipelineOutcome.Done;
        }
Beispiel #26
0
    public static bool Verify(Dafny.Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er) {
      Dafny.Translator translator = new Dafny.Translator();
      translator.InsertChecksums = true;
      translator.UniqueIdPrefix = uniqueIdPrefix;
      Bpl.Program boogieProgram = translator.Translate(dafnyProgram);

      resolver.ReInitializeVerificationErrors(requestId, boogieProgram.Implementations);

      // TODO(wuestholz): Maybe we should use a fixed program ID to limit the memory overhead due to the program cache in Boogie.
      PipelineOutcome oc = BoogiePipeline(boogieProgram, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, er);
      switch (oc) {
        case PipelineOutcome.Done:
        case PipelineOutcome.VerificationCompleted:
          // TODO:  This would be the place to proceed to compile the program, if desired
          return true;
        case PipelineOutcome.FatalError:
        default:
          return false;
      }
    }
Beispiel #27
0
        public static bool Verify(Dafny.Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er)
        {
            Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter);
              var translatorFlags = new Dafny.Translator.TranslatorFlags() { InsertChecksums = true, UniqueIdPrefix = uniqueIdPrefix };

              var boogiePrograms = Dafny.Translator.Translate(dafnyProgram, dafnyProgram.reporter, translatorFlags);

              var impls = boogiePrograms.SelectMany(p => p.Item2.Implementations);
              resolver.ReInitializeVerificationErrors(requestId, impls);

              bool success = false;

              foreach (var kv in boogiePrograms) {
            var boogieProgram = kv.Item2;

            // TODO(wuestholz): Maybe we should use a fixed program ID to limit the memory overhead due to the program cache in Boogie.
            PipelineOutcome oc = BoogiePipeline(boogieProgram, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, er);
            switch (oc) {
              case PipelineOutcome.Done:
              case PipelineOutcome.VerificationCompleted:
            // TODO:  This would be the place to proceed to compile the program, if desired
            success = true;
            break;
              case PipelineOutcome.FatalError:
              default:
            return false;
            }
              }
              return success;
        }
Beispiel #28
0
        /// <summary>
        /// Resolve, type check, infer invariants for, and verify the given Boogie program.
        /// The intention is that this Boogie program has been produced by translation from something
        /// else.  Hence, any resolution errors and type checking errors are due to errors in
        /// the translation.
        /// </summary>
        static PipelineOutcome BoogiePipeline(Bpl.Program/*!*/ program, string programId, string requestId, ErrorReporterDelegate er)
        {
            Contract.Requires(program != null);

              PipelineOutcome oc = BoogieResolveAndTypecheck(program);
              if (oc == PipelineOutcome.ResolvedAndTypeChecked) {
            ExecutionEngine.EliminateDeadVariables(program);
            ExecutionEngine.CollectModSets(program);
            ExecutionEngine.CoalesceBlocks(program);
            ExecutionEngine.Inline(program);
            return ExecutionEngine.InferAndVerify(program, new PipelineStatistics(), programId, er, requestId);
              }
              return oc;
        }
Beispiel #29
0
        public static bool Verify(Dafny.Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er)
        {
            Dafny.Translator translator = new Dafny.Translator();
            translator.InsertChecksums = true;
            translator.UniqueIdPrefix  = uniqueIdPrefix;
            Bpl.Program boogieProgram = translator.Translate(dafnyProgram);

            resolver.ReInitializeVerificationErrors(requestId, boogieProgram.Implementations);

            // TODO(wuestholz): Maybe we should use a fixed program ID to limit the memory overhead due to the program cache in Boogie.
            PipelineOutcome oc = BoogiePipeline(boogieProgram, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, er);

            switch (oc)
            {
            case PipelineOutcome.Done:
            case PipelineOutcome.VerificationCompleted:
                // TODO:  This would be the place to proceed to compile the program, if desired
                return(true);

            case PipelineOutcome.FatalError:
            default:
                return(false);
            }
        }
Beispiel #30
0
    internal new static IEnumerable<ProofState> Search(ProofState rootState, ErrorReporterDelegate er) {

      var queue = new Queue<IEnumerator<ProofState>>();
      queue.Enqueue(Interpreter.EvalStep(rootState).GetEnumerator());
      while (queue.Count > 0) {
        // remove first enumerator on the queue
        var enumerator = queue.Dequeue();
        // if all the statements have been resolve skip
        if (!enumerator.MoveNext())
          continue;

        var proofState = enumerator.Current;
        queue.Enqueue(enumerator);

        if (Verify) {
          if (proofState.IsEvaluated() || proofState.IsPartiallyEvaluated()) {
            switch (VerifyState(proofState, er)) {
              case VerifyResult.Cached:
                if (proofState.IsPartiallyEvaluated()) {
                  yield return proofState;
                  queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                }
                continue;
              case VerifyResult.Verified:
                yield return proofState;
                yield break;
              case VerifyResult.Failed:
                /*
                * verification failed, but the evaluation is partial return
                * but continue evaluating the proofState
                */
                if (proofState.IsPartiallyEvaluated()) {
                  yield return proofState;
                  queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                }
                continue;
              default:
                throw new ArgumentOutOfRangeException();
            }
          }
          queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
        } else {
          if (!(proofState.IsEvaluated() || proofState.IsPartiallyEvaluated()))
            queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
          else {
            yield return proofState;
            if (proofState.IsPartiallyEvaluated()) {
              queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
            }
          }
        }
      }
    }
Beispiel #31
0
        /// <summary>
        /// Given a resolved and type checked Boogie program, infers invariants for the program
        /// and then attempts to verify it.  Returns:
        ///  - Done if command line specified no verification
        ///  - FatalError if a fatal error occurred, in which case an error has been printed to console
        ///  - VerificationCompleted if inference and verification completed, in which the out
        ///    parameters contain meaningful values
        /// </summary>
        public static PipelineOutcome InferAndVerify(Program program,
            PipelineStatistics stats,
            string programId = null,
            ErrorReporterDelegate er = null, string requestId = null)
        {
            Contract.Requires(program != null);
              Contract.Requires(stats != null);
              Contract.Ensures(0 <= Contract.ValueAtReturn(out stats.InconclusiveCount) && 0 <= Contract.ValueAtReturn(out stats.TimeoutCount));

              if (requestId == null)
              {
            requestId = FreshRequestId();
              }

              var start = DateTime.UtcNow;

              #region Do some pre-abstract-interpretation preprocessing on the program
              // Doing lambda expansion before abstract interpretation means that the abstract interpreter
              // never needs to see any lambda expressions.  (On the other hand, if it were useful for it
              // to see lambdas, then it would be better to more lambda expansion until after infererence.)
              if (CommandLineOptions.Clo.ExpandLambdas) {
            LambdaHelper.ExpandLambdas(program);
            //PrintBplFile ("-", program, true);
              }
              #endregion

              #region Infer invariants using Abstract Interpretation

              // Always use (at least) intervals, if not specified otherwise (e.g. with the "/noinfer" switch)
              if (CommandLineOptions.Clo.UseAbstractInterpretation)
              {
            if (!CommandLineOptions.Clo.Ai.J_Intervals && !CommandLineOptions.Clo.Ai.J_Trivial)
            {
              // use /infer:j as the default
              CommandLineOptions.Clo.Ai.J_Intervals = true;
            }
              }
              Microsoft.Boogie.AbstractInterpretation.NativeAbstractInterpretation.RunAbstractInterpretation(program);

              #endregion

              #region Do some post-abstract-interpretation preprocessing on the program (e.g., loop unrolling)

              if (CommandLineOptions.Clo.LoopUnrollCount != -1)
              {
            program.UnrollLoops(CommandLineOptions.Clo.LoopUnrollCount, CommandLineOptions.Clo.SoundLoopUnrolling);
              }

              Dictionary<string, Dictionary<string, Block>> extractLoopMappingInfo = null;
              if (CommandLineOptions.Clo.ExtractLoops)
              {
            extractLoopMappingInfo = program.ExtractLoops();
              }

              if (CommandLineOptions.Clo.PrintInstrumented)
              {
            program.Emit(new TokenTextWriter(Console.Out, CommandLineOptions.Clo.PrettyPrint));
              }
              #endregion

              if (!CommandLineOptions.Clo.Verify)
              {
            return PipelineOutcome.Done;
              }

              #region Run Houdini and verify
              if (CommandLineOptions.Clo.ContractInfer)
              {
            return RunHoudini(program, stats, er);
              }
              #endregion

              #region Select and prioritize implementations that should be verified

              var impls = program.Implementations.Where(
            impl => impl != null && CommandLineOptions.Clo.UserWantsToCheckRoutine(cce.NonNull(impl.Name)) && !impl.SkipVerification);

              // operate on a stable copy, in case it gets updated while we're running
              Implementation[] stablePrioritizedImpls = null;
              if (0 < CommandLineOptions.Clo.VerifySnapshots)
              {
            OtherDefinitionAxiomsCollector.Collect(program.Axioms);
            DependencyCollector.Collect(program);
            stablePrioritizedImpls = impls.OrderByDescending(
              impl => impl.Priority != 1 ? impl.Priority : Cache.VerificationPriority(impl)).ToArray();
              }
              else
              {
            stablePrioritizedImpls = impls.OrderByDescending(impl => impl.Priority).ToArray();
              }

              #endregion

              if (1 < CommandLineOptions.Clo.VerifySnapshots)
              {
            CachedVerificationResultInjector.Inject(program, stablePrioritizedImpls, requestId, programId, out stats.CachingActionCounts);
              }

              #region Verify each implementation

              var outputCollector = new OutputCollector(stablePrioritizedImpls);
              var outcome = PipelineOutcome.VerificationCompleted;

              try
              {
              var cts = new CancellationTokenSource();
              RequestIdToCancellationTokenSource.AddOrUpdate(requestId, cts, (k, ov) => cts);

              var tasks = new Task[stablePrioritizedImpls.Length];
              // We use this semaphore to limit the number of tasks that are currently executing.
              var semaphore = new SemaphoreSlim(CommandLineOptions.Clo.VcsCores);

              // Create a task per implementation.
              for (int i = 0; i < stablePrioritizedImpls.Length; i++)
              {
              var taskIndex = i;
              var id = stablePrioritizedImpls[taskIndex].Id;

              CancellationTokenSource old;
              if (ImplIdToCancellationTokenSource.TryGetValue(id, out old))
              {
                  old.Cancel();
              }
              ImplIdToCancellationTokenSource.AddOrUpdate(id, cts, (k, ov) => cts);

              var t = new Task((dummy) =>
                  {
                      try
                      {
                          if (outcome == PipelineOutcome.FatalError)
                          {
                              return;
                          }
                          if (cts.Token.IsCancellationRequested)
                          {
                              cts.Token.ThrowIfCancellationRequested();
                          }
                          VerifyImplementation(program, stats, er, requestId, extractLoopMappingInfo, stablePrioritizedImpls, taskIndex, outputCollector, Checkers, programId);
                          ImplIdToCancellationTokenSource.TryRemove(id, out old);
                      }
                      finally
                      {
                          semaphore.Release();
                      }
                  }, cts.Token, TaskCreationOptions.None);
              tasks[taskIndex] = t;
              }

              // Execute the tasks.
              int j = 0;
              for (; j < stablePrioritizedImpls.Length && outcome != PipelineOutcome.FatalError; j++)
              {
              try
              {
                  semaphore.Wait(cts.Token);
              }
              catch (OperationCanceledException)
              {
                  break;
              }
              tasks[j].Start(TaskScheduler.Default);
              }

              // Don't wait for tasks that haven't been started yet.
              tasks = tasks.Take(j).ToArray();
              Task.WaitAll(tasks);
              }
              catch (AggregateException ae)
              {
              ae.Handle(e =>
              {
              var pe = e as ProverException;
              if (pe != null)
              {
                  printer.ErrorWriteLine(Console.Out, "Fatal Error: ProverException: {0}", e);
                  outcome = PipelineOutcome.FatalError;
                  return true;
              }
              var oce = e as OperationCanceledException;
              if (oce != null)
              {
                  return true;
              }
              return false;
              });
              }
              finally
              {
            CleanupCheckers(requestId);
              }

              cce.NonNull(CommandLineOptions.Clo.TheProverFactory).Close();

              outputCollector.WriteMoreOutput();

              if (1 < CommandLineOptions.Clo.VerifySnapshots && programId != null)
              {
            program.FreezeTopLevelDeclarations();
            programCache.Set(programId, program, policy);
              }

              if (0 <= CommandLineOptions.Clo.VerifySnapshots && CommandLineOptions.Clo.TraceCachingForBenchmarking)
              {
            var end = DateTime.UtcNow;
            if (TimePerRequest.Count == 0)
            {
              FirstRequestStart = start;
            }
            TimePerRequest[requestId] = end.Subtract(start);
            StatisticsPerRequest[requestId] = stats;

            var printTimes = true;

            Console.Out.WriteLine(CachedVerificationResultInjector.Statistics.Output(printTimes));

            Console.Out.WriteLine("Statistics per request as CSV:");
            var actions = string.Join(", ", Enum.GetNames(typeof(VC.ConditionGeneration.CachingAction)));
            Console.Out.WriteLine("Request ID{0}, Error, E (C), Inconclusive, I (C), Out of Memory, OoM (C), Timeout, T (C), Verified, V (C), {1}", printTimes ? ", Time (ms)" : "", actions);
            foreach (var kv in TimePerRequest.OrderBy(kv => ExecutionEngine.AutoRequestId(kv.Key)))
            {
              var s = StatisticsPerRequest[kv.Key];
              var cacs = s.CachingActionCounts;
              var c = cacs != null ? ", " + cacs.Select(ac => string.Format("{0,3}", ac)).Concat(", ") : "";
              var t = printTimes ? string.Format(", {0,8:F0}", kv.Value.TotalMilliseconds) : "";
              Console.Out.WriteLine("{0,-19}{1}, {2,2}, {3,2}, {4,2}, {5,2}, {6,2}, {7,2}, {8,2}, {9,2}, {10,2}, {11,2}{12}", kv.Key, t, s.ErrorCount, s.CachedErrorCount, s.InconclusiveCount, s.CachedInconclusiveCount, s.OutOfMemoryCount, s.CachedOutOfMemoryCount, s.TimeoutCount, s.CachedTimeoutCount, s.VerifiedCount, s.CachedVerifiedCount, c);
            }

            if (printTimes)
            {
              Console.Out.WriteLine();
              Console.Out.WriteLine("Total time (ms) since first request: {0:F0}", end.Subtract(FirstRequestStart).TotalMilliseconds);
            }
              }

              #endregion

              if (SecureVCGen.outfile != null)
              SecureVCGen.outfile.Close();

              return outcome;
        }
Beispiel #32
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rootState"></param>
        /// <param name="errDelegate"></param> to report err back to GUI
        /// <returns></returns>
        internal static IEnumerable <ProofState> GenerateSolution(ProofState rootState, ErrorReporterDelegate errDelegate)
        {
            var               stack      = new Stack <IEnumerator <ProofState> >();
            ProofState        lastSucc   = null;                                           // the last verified state, for recovering over-backtracking
            var               discarded  = new List <Tuple <ProofState, VerifyResult> >(); // failed ps and its verified status
            List <ProofState> proofState = new List <ProofState> ()
            {
                rootState
            };
            var rootBranches = rootState.EvalStep();

            if (rootBranches == null)
            {
                yield break;
            }
            stack.Push(rootBranches.GetEnumerator());

            IEnumerator <ProofState> enumerator = null;

            List <int> backtrackList = null;

            while (stack.Count > 0)
            {
                bool wasNull = false;
                if (enumerator != null)
                {
                    try {
                        if (enumerator.Current == null)
                        {
                            wasNull = true;
                        }
                    } catch {
                        wasNull = true;
                    }
                }

                if (enumerator == null || !enumerator.MoveNext())
                {
                    // check if current is valid, and the enumerator is empty when current is invalid and MoveNext is null
                    if (enumerator != null && wasNull)
                    {
                        //Console.WriteLine("Null eval result is detected !");
                        foreach (var state in proofState)
                        {
                            discarded.Add(new Tuple <ProofState, VerifyResult>(state, VerifyResult.Unresolved));
                        }
                    }

                    enumerator = stack.Pop();
                    if (!enumerator.MoveNext())
                    {
                        continue;
                    }
                }

                var stateCount = 0;
                proofState.Clear();
                while (stateCount < VerifyNProofState)
                {
                    var current = enumerator.Current;
                    proofState.Add(current);
                    stateCount++;
                    if (backtrackList != null)
                    {
                        current.SetBackTrackCount(backtrackList);
                    }
                    if (current.NeedVerify && proofState[0].GetVerifyN() > 1)
                    {
                        current.DecreaseVerifyN();
                        current.NeedVerify = false;
                    }
                    if (!enumerator.MoveNext())
                    {
                        break;
                    }
                }

                //should at least one state in the list, use [0] as a typical state;
                var rep = proofState[0];
                backtrackList = rep.GetBackTrackCount();

                List <VerifyResult> ress     = null;
                List <bool>         returned = null;

                //check if any new added coded reuqires to call verifier, or reach the last line of code
                if ((rep.NeedVerify && rep.GetVerifyN() == 1) || rep.IsCurFrameEvaluated())
                {
                    foreach (var s in proofState)
                    {
                        s.ResetVerifyN();
                        s.NeedVerify = false;
                    }

                    bool backtracked = false;
                    ress     = VerifyState(proofState);
                    returned = new List <bool>();

                    for (var i = 0; i < ress.Count; i++)
                    {
                        var res = ress[i];
                        var ret = false;
                        switch (res)
                        {
                        case VerifyResult.Verified:
                            //check if the frame are evaluated, as well as requiests for backtraking
                            proofState[i].MarkCurFrameAsTerminated(true, out backtracked);
                            if (backtracked)
                            {
                                lastSucc = proofState[i];
                                discarded.Add(new Tuple <ProofState, VerifyResult>(proofState[i], VerifyResult.Backtracked));
                            }

                            if (proofState[i].IsTerminated())
                            {
                                ret = true;
                                yield return(proofState[i]);
                            }
                            returned.Add(ret);
                            break;

                        case VerifyResult.Failed:
                            if (proofState[i].IsCurFrameEvaluated())
                            {
                                proofState[i].MarkCurFrameAsTerminated(false, out backtracked);
                                if (backtracked)
                                {
                                    lastSucc = proofState[i];
                                    discarded.Add(new Tuple <ProofState, VerifyResult>(proofState[i], VerifyResult.Backtracked));
                                }
                                if (proofState[i].IsTerminated())
                                {
                                    ret = true;
                                    yield return(proofState[i]);
                                }
                            }
                            returned.Add(ret);
                            break;

                        case VerifyResult.Unresolved:
                            //Console.WriteLine("in unresolved");
                            discarded.Add(new Tuple <ProofState, VerifyResult>(proofState[i], VerifyResult.Unresolved));
                            //discard current branch if fails to resolve
                            returned.Add(false);
                            continue;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }

                /*
                 * when failed, check if this method is evaluated , i.e. all tstmt are evalauted,
                 * if so, do nothing will dischard this branch and continue with the next one
                 * otherwise, continue to evaluate the next stmt
                 */
                if (!rep.IsCurFrameEvaluated())
                {
                    //push the current one to the stack
                    stack.Push(enumerator);
                    //move to the next stmt
                    for (var i = 0; i < proofState.Count; i++)
                    {
                        if (returned == null || !returned[i])
                        {
                            stack.Push(proofState[i].EvalStep().GetEnumerator());
                        }
                    }
                    enumerator = stack.Pop();
                }
                else
                {
                    backtrackList = rep.GetBackTrackCount(); // update the current bc count to the list
                    for (var i = 0; i < proofState.Count; i++)
                    {
                        if (returned == null || !returned[i])
                        {
                            if (proofState[i].InAsserstion)
                            {
                                proofState[i].GetErrHandler().ErrType = TacticBasicErr.ErrorType.Assertion;
                                var patchRes = proofState[i].ApplyPatch();
                                if (patchRes != null)
                                {
                                    stack.Push(enumerator);
                                    enumerator = patchRes.GetEnumerator();
                                }
                            }
                            else
                            {
                                proofState[i].GetErrHandler().ErrType = TacticBasicErr.ErrorType.NotProved;
                            }
                            discarded.Add(new Tuple <ProofState, VerifyResult>(proofState[i], VerifyResult.Failed));
                        }
                    }
                }
            }
            //check if over-backchecked
            if (backtrackList != null && backtrackList.Exists(x => x > 0))
            {
                if (lastSucc == null)
                {
                    Console.WriteLine("!!! No more branch for the request of " + (backtrackList.Last() + 1) +
                                      "backtracking, and no branch.");
                }
                else
                {
                    Console.WriteLine("!!! No more branch for the request of " + lastSucc.GetOrignalTopBacktrack() +
                                      ", remaining " +
                                      (backtrackList.Last() + 1 > lastSucc.GetOrignalTopBacktrack()
                              ? lastSucc.GetOrignalTopBacktrack()
                              : backtrackList.Last() + 1) + " requests, return the last one.");
                    yield return(lastSucc);
                }
            }
            else
            {
                // no result is successful
                ProofState s0;
                if (discarded.Count > 0)
                {
                    s0 = discarded[discarded.Count - 1].Item1;
                    //s0.GetErrHandler().ExceptionReport();
                }
                else
                {
                    s0 = rootState;
                }
                s0.ReportTacticError(s0.TopLevelTacApp.Tok,
                                     "No solution is found. \n The error message from the last failed branch: ");
                var errs = CompoundErrorInformation.GenerateErrorInfoList(s0);
                if (errDelegate != null)
                {
                    foreach (var err in errs)
                    {
                        errDelegate(err);
                    }
                }
            }
        }
Beispiel #33
0
        public bool Verify(Dafny.Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er)
        {
            Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter);
            var translatorFlags         = new Dafny.Translator.TranslatorFlags()
            {
                InsertChecksums = true, UniqueIdPrefix = uniqueIdPrefix
            };


            var boogiePrograms = Dafny.Translator.Translate(dafnyProgram, dafnyProgram.reporter, translatorFlags);

            var impls = boogiePrograms.SelectMany(p => p.Item2.Implementations);

            resolver.ReInitializeVerificationErrors(requestId, impls);

            bool success   = false;
            var  errorSink = new ErrorSink(this);

            foreach (var kv in boogiePrograms)
            {
                var boogieProgram = kv.Item2;

                // TODO(wuestholz): Maybe we should use a fixed program ID to limit the memory overhead due to the program cache in Boogie.
                PipelineOutcome oc = BoogiePipeline(boogieProgram, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, errorSink, er);
                switch (oc)
                {
                case PipelineOutcome.Done:
                case PipelineOutcome.VerificationCompleted:
                    // TODO:  This would be the place to proceed to compile the program, if desired
                    success = true;
                    break;

                case PipelineOutcome.FatalError:
                default:
                    return(false);
                }
            }
            return(success);
        }
Beispiel #34
0
    internal new static IEnumerable<ProofState> Search(ProofState rootState, ErrorReporterDelegate er){
      var stack = new Stack<IEnumerator<ProofState>>();
      stack.Push(Interpreter.EvalStep(rootState).GetEnumerator());
      IEnumerator<ProofState> enumerator = Enumerable.Empty<ProofState>().GetEnumerator();

      while(stack.Count > 0) {
        if(!enumerator.MoveNext()) {
          enumerator = stack.Pop();
          if(!enumerator.MoveNext())
            continue;
        }
        var proofState = enumerator.Current;
        //check if any new added coded reuqires to call verifier, or reach the last line of code
        if(proofState.IfVerify || proofState.IsEvaluated()) {
          proofState.IfVerify = false;
          switch(VerifyState(proofState, er)) {
            case VerifyResult.Verified:
              proofState.MarkCurFrameAsTerminated(true);
              if(proofState.IsTerminated()) {
                yield return proofState;
                yield break;
             }
              //stack.Push(enumerator);
              //enumerator = (Interpreter.EvalStep(proofState).GetEnumerator());
              break;
            case VerifyResult.Failed:
              if(proofState.IsEvaluated()) {
                proofState.MarkCurFrameAsTerminated(false);
                if(proofState.IsTerminated()) {
                  yield return proofState;
                  yield break;
                }
              }
              break;
            case VerifyResult.Unresolved:
              //discharge current branch if fails to resolve
              continue;
            default:
              throw new ArgumentOutOfRangeException();
          }
        }
        /*
       * when failed, check if this mmethod is evaluated , i.e. all tstmt are evalauted,
       * if so, dischard this branch and continue with the next one
       * otherwise, continue to evaluate the next stmt
       */
        if(!proofState.IsEvaluated()) {
          //push the current one to the stack
          stack.Push(enumerator);
          //move to the next stmt
          enumerator = (Interpreter.EvalStep(proofState).GetEnumerator());
        }
      }
    }
Beispiel #35
0
        internal new static IEnumerable <ProofState> Search(ProofState rootState, ErrorReporterDelegate er)
        {
            var queue = new Queue <IEnumerator <ProofState> >();

            queue.Enqueue(Interpreter.EvalStep(rootState).GetEnumerator());
            while (queue.Count > 0)
            {
                // remove first enumerator on the queue
                var enumerator = queue.Dequeue();
                // if all the statements have been resolve skip
                if (!enumerator.MoveNext())
                {
                    continue;
                }

                var proofState = enumerator.Current;
                queue.Enqueue(enumerator);

                if (Verify)
                {
                    if (proofState.IsEvaluated() || proofState.IsPartiallyEvaluated())
                    {
                        switch (VerifyState(proofState, er))
                        {
                        case VerifyResult.Cached:
                            if (proofState.IsPartiallyEvaluated())
                            {
                                yield return(proofState);

                                queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                            }
                            continue;

                        case VerifyResult.Verified:
                            yield return(proofState);

                            yield break;

                        case VerifyResult.Failed:
                            /*
                             * verification failed, but the evaluation is partial return
                             * but continue evaluating the proofState
                             */
                            if (proofState.IsPartiallyEvaluated())
                            {
                                yield return(proofState);

                                queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                            }
                            continue;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                    queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                }
                else
                {
                    if (!(proofState.IsEvaluated() || proofState.IsPartiallyEvaluated()))
                    {
                        queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                    }
                    else
                    {
                        yield return(proofState);

                        if (proofState.IsPartiallyEvaluated())
                        {
                            queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                        }
                    }
                }
            }
        }
Beispiel #36
0
        public static IEnumerable <ProofState> EvalTopLevelTactic(ProofState state, Dictionary <IVariable, Type> variables,
                                                                  Statement tacticApplication, ApplySuffix aps, ErrorReporterDelegate errorDelegate, bool ifPartial)
        {
            Contract.Requires <ArgumentNullException>(Tcce.NonNull(variables));
            Contract.Requires <ArgumentNullException>(Tcce.NonNull(tacticApplication));
            Contract.Requires <ArgumentNullException>(state != null, "state");
            Contract.Requires(tacticApplication == null ||
                              tacticApplication is UpdateStmt || tacticApplication is InlineTacticBlockStmt);

            IEnumerable <ProofState> branches;

            if (state.InitState(tacticApplication, aps, variables, ifPartial) == false)
            {
                return(null);
            }

#if !TACNY_DEBUG
            try {
#endif
            if (state.GetErrHandler().Reporter.Count(ErrorLevel.Error) != 0)
            {
                var errs = CompoundErrorInformation.GenerateErrorInfoList(state);
                if (errorDelegate != null)
                {
                    foreach (var err in errs)
                    {
                        errorDelegate(err);
                    }
                }

                return(null);
            }
            branches = GenerateSolution(state, errorDelegate);

      #if !TACNY_DEBUG
        }

        catch (Exception e) {
            String msg;
            List <CompoundErrorInformation> errs;
            try {
                msg  = "Tactic unknown exception: " + e.Message;
                errs = CompoundErrorInformation.GenerateErrorInfoList(state, msg);
            } catch (Exception) {
                msg  = "Tactic exception";
                errs = new List <CompoundErrorInformation>();
            }

            if (errorDelegate != null)
            {
                foreach (var err in errs)
                {
                    errorDelegate(err);
                }
            }
            return(null);
        }
#endif

            return(branches);
        }
Beispiel #37
0
        /// <summary>
        /// Given a resolved and type checked Boogie program, infers invariants for the program
        /// and then attempts to verify it.  Returns:
        ///  - Done if command line specified no verification
        ///  - FatalError if a fatal error occurred, in which case an error has been printed to console
        ///  - VerificationCompleted if inference and verification completed, in which the out
        ///    parameters contain meaningful values
        /// </summary>
        public static PipelineOutcome InferAndVerify(Program program,
            PipelineStatistics stats, string filename,
            ErrorReporterDelegate er = null, string requestId = "unknown")
        {
            Contract.Requires(program != null);
              Contract.Requires(stats != null);
              Contract.Ensures(0 <= Contract.ValueAtReturn(out stats.InconclusiveCount) && 0 <= Contract.ValueAtReturn(out stats.TimeoutCount));

              if (requestId == null)
              {
            requestId = "unknown";
              }
              RequestIdToCancellationTokenSources[requestId] = new List<CancellationTokenSource>();

              #region Infer invariants using Abstract Interpretation

              // Always use (at least) intervals, if not specified otherwise (e.g. with the "/noinfer" switch)
              if (CommandLineOptions.Clo.UseAbstractInterpretation)
              {
            if (!CommandLineOptions.Clo.Ai.J_Intervals && !CommandLineOptions.Clo.Ai.J_Trivial)
            {
              // use /infer:j as the default
              CommandLineOptions.Clo.Ai.J_Intervals = true;
            }
              }
              Microsoft.Boogie.AbstractInterpretation.NativeAbstractInterpretation.RunAbstractInterpretation(program);

              #endregion

              #region Do some preprocessing on the program (e.g., loop unrolling, lambda expansion)

              if (CommandLineOptions.Clo.LoopUnrollCount != -1)
              {
            program.UnrollLoops(CommandLineOptions.Clo.LoopUnrollCount, CommandLineOptions.Clo.SoundLoopUnrolling);
              }

              Dictionary<string, Dictionary<string, Block>> extractLoopMappingInfo = null;
              if (CommandLineOptions.Clo.ExtractLoops)
              {
            extractLoopMappingInfo = program.ExtractLoops();
              }

              if (CommandLineOptions.Clo.PrintInstrumented)
              {
            program.Emit(new TokenTextWriter(Console.Out));
              }

              if (CommandLineOptions.Clo.ExpandLambdas)
              {
            LambdaHelper.ExpandLambdas(program);
            //PrintBplFile ("-", program, true);
              }

              #endregion

              if (!CommandLineOptions.Clo.Verify)
              {
            return PipelineOutcome.Done;
              }

              #region Run Houdini and verify
              if (CommandLineOptions.Clo.ContractInfer)
              {
            return RunHoudini(program, stats, er, filename);
              }
              #endregion

              #region Select and prioritize implementations that should be verified

              var impls = program.TopLevelDeclarations.OfType<Implementation>().Where(
            impl => impl != null && CommandLineOptions.Clo.UserWantsToCheckRoutine(cce.NonNull(impl.Name)) && !impl.SkipVerification);

              // operate on a stable copy, in case it gets updated while we're running
              Implementation[] stablePrioritizedImpls = null;
              if (CommandLineOptions.Clo.VerifySnapshots)
              {
            impls.Iter(impl => { impl.DependenciesChecksum = DependencyCollector.DependenciesChecksum(impl); });
            stablePrioritizedImpls = impls.OrderByDescending(
              impl => impl.Priority != 1 ? impl.Priority : Cache.VerificationPriority(impl)).ToArray();
              }
              else
              {
            stablePrioritizedImpls = impls.OrderByDescending(impl => impl.Priority).ToArray();
              }

              #endregion

              #region Verify each implementation

              var outputCollector = new OutputCollector(stablePrioritizedImpls);
              var outcome = PipelineOutcome.VerificationCompleted;
              var tasks = new Task[stablePrioritizedImpls.Length];
              for (int i = 0; i < stablePrioritizedImpls.Length && outcome != PipelineOutcome.FatalError; i++)
              {
            var taskIndex = i;
            var id = stablePrioritizedImpls[i].Id;
            CancellationTokenSource src;
            if (ImplIdToCancellationTokenSource.TryGetValue(id, out src))
            {
              src.Cancel();
            }
            src = new CancellationTokenSource();
            RequestIdToCancellationTokenSources[requestId].Add(src);
            ImplIdToCancellationTokenSource[id] = src;
            var t = Task.Factory.StartNew((dummy) =>
            {
              VerifyImplementation(program, stats, er, requestId, extractLoopMappingInfo, stablePrioritizedImpls, taskIndex, outputCollector, Checkers, src.Token);
              ImplIdToCancellationTokenSource.Remove(id);
            }, src.Token, TaskCreationOptions.LongRunning);
            tasks[taskIndex] = t;
              }
              try
              {
            Task.WaitAll(tasks);
              }
              catch (AggregateException ae)
              {
            ae.Handle(e =>
            {
              var pe = e as ProverException;
              if (pe != null)
              {
            printer.ErrorWriteLine(Console.Out, "Fatal Error: ProverException: {0}", e);
            outcome = PipelineOutcome.FatalError;
            return true;
              }
              var oce = e as OperationCanceledException;
              if (oce != null)
              {
            return true;
              }
              return false;
            });
              }
              finally
              {
            CleanupCheckers(requestId);
              }

              cce.NonNull(CommandLineOptions.Clo.TheProverFactory).Close();

              outputCollector.WriteMoreOutput();

              #endregion

              return outcome;
        }
Beispiel #38
0
        /*
         * public static bool ResolveAndVerify(Program program, ErrorReporterDelegate er) {
         * Contract.Requires<ArgumentNullException>(program != null);
         * var r = new Resolver(program);
         * //var start = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
         * r.ResolveProgram(program);
         * //TODO: get program.reporter to check resolving result before verifying
         * //var end = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds
         *
         * // check if resolution fails
         * if (program.reporter.Count(ErrorLevel.Error) != 0){
         *  Console.Write("Fail to resolve prog, skip verifier ! \n");
         *  return false;
         *
         * }
         * var boogieProg = Translate(program, program.Name, er);
         * PipelineStatistics stats;
         * List<ErrorInformation> errorList;
         *
         * //Console.WriteLine("call verifier in Tacny !!!");
         * PipelineOutcome tmp = BoogiePipeline(boogieProg,
         *  new List<string> {program.Name}, program.Name, er,
         *  out stats, out errorList, program);
         *
         * return errorList.Count == 0;
         * }
         */
        public static Bpl.Program Translate(Program dafnyProgram, string uniqueIdPrefix, ErrorReporterDelegate er)
        {
            Contract.Requires <ArgumentNullException>(dafnyProgram != null, "dafnyProgram");
            Contract.Requires <ArgumentNullException>(uniqueIdPrefix != null, "uniqueIdPrefix");
            Contract.Ensures(Contract.Result <Bpl.Program>() != null);
            var translator = new Translator(dafnyProgram.reporter, er)
            {
                InsertChecksums = true,
                UniqueIdPrefix  = uniqueIdPrefix
            };

            return(translator.Translate(dafnyProgram));
        }
Beispiel #39
0
        public static bool Verify(Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er, Program unresolvedProgram)
        {
            var translator = new Translator(dafnyProgram.reporter, er)
            {
                InsertChecksums = true,
                UniqueIdPrefix  = uniqueIdPrefix
            };
            var boogieProgram = translator.Translate(dafnyProgram, unresolvedProgram);

            resolver.ReInitializeVerificationErrors(requestId, boogieProgram.Implementations);
            var outcome = BoogiePipeline(boogieProgram, 1 < CommandLineOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, er);

            return(outcome == PipelineOutcome.Done || outcome == PipelineOutcome.VerificationCompleted);
        }
Beispiel #40
0
        private static void ProcessOutcome(VC.VCGen.Outcome outcome, List<Counterexample> errors, string timeIndication,
            PipelineStatistics stats, TextWriter tw, int timeLimit, ErrorReporterDelegate er = null, string implName = null, IToken implTok = null, string requestId = null, bool wasCached = false)
        {
            Contract.Requires(stats != null);

              UpdateStatistics(stats, outcome, errors, wasCached);

              printer.Inform(timeIndication + OutcomeIndication(outcome, errors), tw);

              ReportOutcome(outcome, er, implName, implTok, requestId, tw, timeLimit, errors);
        }
Beispiel #41
0
    private static void ReportOutcome(VC.VCGen.Outcome outcome, ErrorReporterDelegate er, string implName, IToken implTok, string requestId, TextWriter tw, int timeLimit, List<Counterexample> errors)
    {
      ErrorInformation errorInfo = null;

      switch (outcome)
      {
        case VCGen.Outcome.ReachedBound:
          tw.WriteLine(string.Format("Stratified Inlining: Reached recursion bound of {0}", CommandLineOptions.Clo.RecursionBound));
          break;
        case VCGen.Outcome.Errors:
        case VCGen.Outcome.TimedOut:
          if (implName != null && implTok != null)
          {
            if (outcome == ConditionGeneration.Outcome.TimedOut || (errors != null && errors.Any(e => e.IsAuxiliaryCexForDiagnosingTimeouts)))
            {
              errorInfo = errorInformationFactory.CreateErrorInformation(implTok, string.Format("Verification of '{1}' timed out after {0} seconds", timeLimit, implName), requestId);
            }

            //  Report timed out assertions as auxiliary info.
            if (errors != null)
            {
              var cmpr = new CounterexampleComparer();
              var timedOutAssertions = errors.Where(e => e.IsAuxiliaryCexForDiagnosingTimeouts).Distinct(cmpr).ToList();
              timedOutAssertions.Sort(cmpr);
              if (0 < timedOutAssertions.Count)
              {
                errorInfo.Msg += string.Format(" with {0} check(s) that timed out individually", timedOutAssertions.Count);
              }
              foreach (Counterexample error in timedOutAssertions)
              {
                var callError = error as CallCounterexample;
                var returnError = error as ReturnCounterexample;
                var assertError = error as AssertCounterexample;
                IToken tok = null;
                string msg = null;
                if (callError != null)
                {
                  tok = callError.FailingCall.tok;
                  msg = callError.FailingCall.ErrorData as string ?? "A precondition for this call might not hold.";
                }
                else if (returnError != null)
                {
                  tok = returnError.FailingReturn.tok;
                  msg = "A postcondition might not hold on this return path.";
                }
                else
                {
                  tok = assertError.FailingAssert.tok;
                  if (assertError.FailingAssert is LoopInitAssertCmd)
                  {
                    msg = "This loop invariant might not hold on entry.";
                  }
                  else if (assertError.FailingAssert is LoopInvMaintainedAssertCmd)
                  {
                    msg = "This loop invariant might not be maintained by the loop.";
                  }
                  else
                  {
                    msg = assertError.FailingAssert.ErrorData as string;
                    if (!CommandLineOptions.Clo.ForceBplErrors && assertError.FailingAssert.ErrorMessage != null)
                    {
                      msg = assertError.FailingAssert.ErrorMessage;
                    }
                    if (msg == null)
                    {
                      msg = "This assertion might not hold.";
                    }
                  }
                }
                errorInfo.AddAuxInfo(tok, msg, "Unverified check due to timeout");
              }
            }
          }
          break;
        case VCGen.Outcome.OutOfMemory:
          if (implName != null && implTok != null)
          {
            errorInfo = errorInformationFactory.CreateErrorInformation(implTok, "Verification out of memory (" + implName + ")", requestId);
          }
          break;
        case VCGen.Outcome.Inconclusive:
          if (implName != null && implTok != null)
          {
            errorInfo = errorInformationFactory.CreateErrorInformation(implTok, "Verification inconclusive (" + implName + ")", requestId);
          }
          break;
      }

      if (errorInfo != null)
      {
        errorInfo.ImplementationName = implName;
        if (er != null)
        {
          lock (er)
          {
            er(errorInfo);
          }
        }
        else
        {
          printer.WriteErrorInformation(errorInfo, tw);
        }
      }
    }
Beispiel #42
0
        private static PipelineOutcome RunAbstractHoudini(Program program, PipelineStatistics stats, ErrorReporterDelegate er)
        {
            Contract.Requires(stats != null);

              //CommandLineOptions.Clo.PrintErrorModel = 1;
              CommandLineOptions.Clo.UseProverEvaluate = true;
              CommandLineOptions.Clo.ModelViewFile = "z3model";
              CommandLineOptions.Clo.UseArrayTheory = true;
              CommandLineOptions.Clo.TypeEncodingMethod = CommandLineOptions.TypeEncoding.Monomorphic;
              Houdini.AbstractDomainFactory.Initialize(program);
              var domain = Houdini.AbstractDomainFactory.GetInstance(CommandLineOptions.Clo.AbstractHoudini);

              // Run Abstract Houdini
              var abs = new Houdini.AbsHoudini(program, domain);
              var absout = abs.ComputeSummaries();
              ProcessOutcome(absout.outcome, absout.errors, "", stats, Console.Out, CommandLineOptions.Clo.ProverKillTime, er);
              ProcessErrors(absout.errors, absout.outcome, Console.Out, er);

              //Houdini.PredicateAbs.Initialize(program);
              //var abs = new Houdini.AbstractHoudini(program);
              //abs.computeSummaries(new Houdini.PredicateAbs(program.TopLevelDeclarations.OfType<Implementation>().First().Name));

              return PipelineOutcome.Done;
        }
Beispiel #43
0
 private static extern void TfLiteInterpreterOptionsSetErrorReporter(
     TfLiteInterpreterOptions options,
     ErrorReporterDelegate errorReporter,
     IntPtr user_data);
Beispiel #44
0
        private static void VerifyImplementation(Program program, PipelineStatistics stats, ErrorReporterDelegate er, string requestId, Dictionary<string, Dictionary<string, Block>> extractLoopMappingInfo, Implementation[] stablePrioritizedImpls, int index, OutputCollector outputCollector, List<Checker> checkers, string programId)
        {
            Implementation impl = stablePrioritizedImpls[index];
              VerificationResult verificationResult = null;
              var output = new StringWriter();

              printer.Inform("", output);  // newline
              printer.Inform(string.Format("Verifying {0} ...", impl.Name), output);

              int priority = 0;
              var wasCached = false;
              if (0 < CommandLineOptions.Clo.VerifySnapshots) {
            var cachedResults = Cache.Lookup(impl, out priority);
            if (cachedResults != null && priority == Priority.SKIP) {
              if (CommandLineOptions.Clo.XmlSink != null) {
            CommandLineOptions.Clo.XmlSink.WriteStartMethod(impl.Name, cachedResults.Start);
              }

              printer.Inform(string.Format("Retrieving cached verification result for implementation {0}...", impl.Name), output);
              if (CommandLineOptions.Clo.VerifySnapshots < 3 || cachedResults.Outcome == ConditionGeneration.Outcome.Correct) {
            verificationResult = cachedResults;
            wasCached = true;
              }
            }
              }

              if (!wasCached)
              {
            #region Verify the implementation

            verificationResult = new VerificationResult(requestId, impl, programId);

            using (var vcgen = CreateVCGen(program, checkers))
            {
              vcgen.CachingActionCounts = stats.CachingActionCounts;
              verificationResult.ProofObligationCountBefore = vcgen.CumulativeAssertionCount;
              verificationResult.Start = DateTime.UtcNow;

              if (CommandLineOptions.Clo.XmlSink != null)
              {
            CommandLineOptions.Clo.XmlSink.WriteStartMethod(impl.Name, verificationResult.Start);
              }
              try
              {
            if (CommandLineOptions.Clo.inferLeastForUnsat != null)
            {
              var svcgen = vcgen as VC.StratifiedVCGen;
              Contract.Assert(svcgen != null);
              var ss = new HashSet<string>();
              foreach (var c in program.Constants)
              {
                if (!c.Name.StartsWith(CommandLineOptions.Clo.inferLeastForUnsat)) continue;
                ss.Add(c.Name);
              }
              verificationResult.Outcome = svcgen.FindLeastToVerify(impl, ref ss);
              verificationResult.Errors = new List<Counterexample>();
              output.WriteLine("Result: {0}", string.Join(" ", ss));
            }
            else
            {
              verificationResult.Outcome = vcgen.VerifyImplementation(impl, out verificationResult.Errors, requestId);
              if (CommandLineOptions.Clo.ExtractLoops && verificationResult.Errors != null)
              {
                var vcg = vcgen as VCGen;
                if (vcg != null)
                {
                  for (int i = 0; i < verificationResult.Errors.Count; i++)
                  {
                    verificationResult.Errors[i] = vcg.extractLoopTrace(verificationResult.Errors[i], impl.Name, program, extractLoopMappingInfo);
                  }
                }
              }
            }
              }
              catch (VCGenException e)
              {
            var errorInfo = errorInformationFactory.CreateErrorInformation(impl.tok, String.Format("{0} (encountered in implementation {1}).", e.Message, impl.Name), requestId, "Error");
            errorInfo.BoogieErrorCode = "BP5010";
            errorInfo.ImplementationName = impl.Name;
            printer.WriteErrorInformation(errorInfo, output);
            if (er != null)
            {
              lock (er)
              {
                er(errorInfo);
              }
            }
            verificationResult.Errors = null;
            verificationResult.Outcome = VCGen.Outcome.Inconclusive;
              }
              catch (UnexpectedProverOutputException upo)
              {
            printer.AdvisoryWriteLine("Advisory: {0} SKIPPED because of internal error: unexpected prover output: {1}", impl.Name, upo.Message);
            verificationResult.Errors = null;
            verificationResult.Outcome = VCGen.Outcome.Inconclusive;
              }

              verificationResult.ProofObligationCountAfter = vcgen.CumulativeAssertionCount;
              verificationResult.End = DateTime.UtcNow;
            }

            #endregion

            #region Cache the verification result

            if (0 < CommandLineOptions.Clo.VerifySnapshots && !string.IsNullOrEmpty(impl.Checksum))
            {
              Cache.Insert(impl, verificationResult);
            }

            #endregion
              }

              #region Process the verification results and statistics

              ProcessOutcome(verificationResult.Outcome, verificationResult.Errors, TimeIndication(verificationResult), stats, output, impl.TimeLimit, er, verificationResult.ImplementationName, verificationResult.ImplementationToken, verificationResult.RequestId, wasCached);

              ProcessErrors(verificationResult.Errors, verificationResult.Outcome, output, er, impl);

              if (CommandLineOptions.Clo.XmlSink != null)
              {
            CommandLineOptions.Clo.XmlSink.WriteEndMethod(verificationResult.Outcome.ToString().ToLowerInvariant(), verificationResult.End, verificationResult.End - verificationResult.Start);
              }

              outputCollector.Add(index, output);

              outputCollector.WriteMoreOutput();

              if (verificationResult.Outcome == VCGen.Outcome.Errors || CommandLineOptions.Clo.Trace)
              {
            Console.Out.Flush();
              }

              #endregion
        }
Beispiel #45
0
        internal new static IEnumerable <ProofState> Search(ProofState rootState, ErrorReporterDelegate er)
        {
            var queue = new Queue <IEnumerator <ProofState> >();

            queue.Enqueue(Interpreter.EvalStep(rootState).GetEnumerator());


            IEnumerator <ProofState> enumerator = Enumerable.Empty <ProofState>().GetEnumerator();

            while (queue.Count > 0)
            {
                // check if there is any more item in the enumerartor, if so, MoveNext will move to the next item
                if (!enumerator.MoveNext())
                {
                    // if no item in the current enumerator, pop a new enumerator from the queie,
                    enumerator = queue.Dequeue();
                    // set the start point for enumulator, if there is no valid start point, i.e. empty, skip this one
                    if (!enumerator.MoveNext())
                    {
                        continue;
                    }
                }
                var proofState = enumerator.Current;
                //check if any new added code reuqires to call the dafny to verity, or reach the last line of code
                if (proofState.IfVerify || proofState.IsEvaluated())
                {
                    proofState.IfVerify = false;
                    switch (VerifyState(proofState, er))
                    {
                    case VerifyResult.Verified:
                        proofState.MarkCurFrameAsTerminated(true);
                        if (proofState.IsTerminated())
                        {
                            yield return(proofState);

                            yield break;
                        }
                        //queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                        break;

                    case VerifyResult.Failed:
                        if (proofState.IsEvaluated())
                        {
                            proofState.MarkCurFrameAsTerminated(false);
                            if (proofState.IsTerminated())
                            {
                                yield return(proofState);

                                yield break;
                            }
                        }
                        break;

                    case VerifyResult.Unresolved:
                        //discharge current branch if fails to resolve
                        continue;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                /*
                 * when failed, check if this mmethod is evaluated , i.e. all tstmt are evalauted,
                 * if so, dischard this branch and continue with the next one
                 * otherwise, continue to evaluate the next stmt
                 */
                if (!proofState.IsEvaluated())
                {
                    queue.Enqueue(Interpreter.EvalStep(proofState).GetEnumerator());
                }
            }
        }
Beispiel #46
0
        protected override void Execute(IntPtr bridgeFunc, IProgressMonitor subMonitor)
        {
            subMonitor_ = subMonitor;
            taskStarted_ = false;

            BoostTestRunDelegate bridge =
                (BoostTestRunDelegate)Marshal.GetDelegateForFunctionPointer(
                    bridgeFunc,
                    typeof(BoostTestRunDelegate)
                );

            VisitorDelegate visitTestCase = new VisitorDelegate(VisitTestCase);
            VisitorDelegate beginVisitTestSuite = new VisitorDelegate(BeginVisitTestSuite);
            VisitorDelegate endVisitTestSuite = new VisitorDelegate(EndVisitTestSuite);
            VisitorDelegate shouldSkip = new VisitorDelegate(ShouldSkip);

            TestStartDelegate testStart = new TestStartDelegate(TestStart);
            TestDelegate testFinish = new TestDelegate(TestFinish);
            TestDelegate testAborted = new TestDelegate(TestAborted);
            TestUnitDelegate testUnitStart = new TestUnitDelegate(TestUnitStart);
            TestUnitFinishedDelegate testUnitFinish = new TestUnitFinishedDelegate(TestUnitFinish);
            TestUnitDelegate testUnitSkipped = new TestUnitDelegate(TestUnitSkipped);
            TestUnitDelegate testUnitAborted = new TestUnitDelegate(TestUnitAborted);
            AssertionResultDelegate assertionResult = new AssertionResultDelegate(AssertionResult);
            ExceptionCaughtDelegate exceptionCaught = new ExceptionCaughtDelegate(ExceptionCaught);

            ErrorReporterDelegate errorReporter =
                new ErrorReporterDelegate((text) => Logger.Log(LogSeverity.Error, text));

            bridge(
                File.FullName,

                visitTestCase,
                beginVisitTestSuite,
                endVisitTestSuite,
                shouldSkip,

                testStart,
                testFinish,
                testAborted,
                testUnitStart,
                testUnitFinish,
                testUnitSkipped,
                testUnitAborted,
                assertionResult,
                exceptionCaught,

                errorReporter
            );

            // Cancel all tests that were not completed, if any.
            while (testStepsStack_.Count > 0)
            {
                TestResult result = testResultsStack_.Pop();
                result.Outcome = TestOutcome.Canceled;

                MessageSink.Publish(
                    new TestStepFinishedMessage
                    {
                        StepId = testStepsStack_.Pop().Id,
                        Result = result
                    }
                );
            }

            if (taskStarted_) taskCookie_.Dispose();
        }
Beispiel #47
0
        internal new static IEnumerable <ProofState> Search(ProofState rootState, ErrorReporterDelegate er)
        {
            var stack = new Stack <IEnumerator <ProofState> >();

            stack.Push(Interpreter.EvalStep(rootState).GetEnumerator());
            IEnumerator <ProofState> enumerator = Enumerable.Empty <ProofState>().GetEnumerator();

            while (stack.Count > 0)
            {
                if (!enumerator.MoveNext())
                {
                    enumerator = stack.Pop();
                    if (!enumerator.MoveNext())
                    {
                        continue;
                    }
                }
                var proofState = enumerator.Current;
                //check if any new added coded reuqires to call verifier, or reach the last line of code
                if (proofState.IfVerify || proofState.IsEvaluated())
                {
                    proofState.IfVerify = false;
                    switch (VerifyState(proofState, er))
                    {
                    case VerifyResult.Verified:
                        proofState.MarkCurFrameAsTerminated(true);
                        if (proofState.IsTerminated())
                        {
                            yield return(proofState);

                            yield break;
                        }
                        //stack.Push(enumerator);
                        //enumerator = (Interpreter.EvalStep(proofState).GetEnumerator());
                        break;

                    case VerifyResult.Failed:
                        if (proofState.IsEvaluated())
                        {
                            proofState.MarkCurFrameAsTerminated(false);
                            if (proofState.IsTerminated())
                            {
                                yield return(proofState);

                                yield break;
                            }
                        }
                        break;

                    case VerifyResult.Unresolved:
                        //discharge current branch if fails to resolve
                        continue;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                /*
                 * when failed, check if this mmethod is evaluated , i.e. all tstmt are evalauted,
                 * if so, dischard this branch and continue with the next one
                 * otherwise, continue to evaluate the next stmt
                 */
                if (!proofState.IsEvaluated())
                {
                    //push the current one to the stack
                    stack.Push(enumerator);
                    //move to the next stmt
                    enumerator = (Interpreter.EvalStep(proofState).GetEnumerator());
                }
            }
        }
Beispiel #48
0
        /// <summary>
        /// Resolve, type check, infer invariants for, and verify the given Boogie program.
        /// The intention is that this Boogie program has been produced by translation from something
        /// else.  Hence, any resolution errors and type checking errors are due to errors in
        /// the translation.
        /// </summary>
        static PipelineOutcome BoogiePipeline(Bpl.Program /*!*/ program, string programId, string requestId, ErrorSink errorSink, ErrorReporterDelegate er)
        {
            Contract.Requires(program != null);

            PipelineOutcome oc = BoogieResolveAndTypecheck(program, errorSink);

            if (oc == PipelineOutcome.ResolvedAndTypeChecked)
            {
                ExecutionEngine.EliminateDeadVariables(program);
                ExecutionEngine.CollectModSets(program);
                ExecutionEngine.CoalesceBlocks(program);
                ExecutionEngine.Inline(program);
                return(ExecutionEngine.InferAndVerify(program, new PipelineStatistics(), programId, er, requestId));
            }
            return(oc);
        }
Beispiel #49
0
 public IEnumerable <ProofState> Search(ProofState state, ErrorReporterDelegate er)
 {
     Contract.Requires(state != null);
     return(default(IEnumerable <ProofState>));
 }
Beispiel #50
0
        /// <summary>
        /// Pipeline the boogie program to Dafny where it is valid
        /// </summary>
        /// <returns>Exit value</returns>
        public static PipelineOutcome BoogiePipeline(Bpl.Program program, IList <string> fileNames, string programId, ErrorReporterDelegate er, out PipelineStatistics stats, out List <ErrorInformation> errorList, Program tmpDafnyProgram = null)
        {
            Contract.Requires(program != null);
            Contract.Ensures(0 <= Contract.ValueAtReturn(out stats).InconclusiveCount&& 0 <= Contract.ValueAtReturn(out stats).TimeoutCount);

            LinearTypeChecker ltc;
            CivlTypeChecker   ctc;
            string            baseName = cce.NonNull(System.IO.Path.GetFileName(fileNames[fileNames.Count - 1]));

            baseName = cce.NonNull(System.IO.Path.ChangeExtension(baseName, "bpl"));
            string bplFileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), baseName);

            errorList = new List <ErrorInformation>();
            stats     = new PipelineStatistics();



            PipelineOutcome oc = ExecutionEngine.ResolveAndTypecheck(program, bplFileName, out ltc, out ctc);

            switch (oc)
            {
            case PipelineOutcome.ResolvedAndTypeChecked:
                ExecutionEngine.EliminateDeadVariables(program);
                ExecutionEngine.CollectModSets(program);
                ExecutionEngine.CoalesceBlocks(program);
                ExecutionEngine.Inline(program);
                errorList = new List <ErrorInformation>();
                var tmp = new List <ErrorInformation>();

                oc = ExecutionEngine.InferAndVerify(program, stats, programId, errorInfo => {
                    tmp.Add(errorInfo);
                });
                errorList.AddRange(tmp);

                return(oc);

            default:
                Contract.Assert(false);
                throw new cce.UnreachableException(); // unexpected outcome
            }
        }
Beispiel #51
0
        private static PipelineOutcome RunMLHoudini(Program program, PipelineStatistics stats, ErrorReporterDelegate er, string filename)
        {
            Contract.Requires(stats != null);

            //CommandLineOptions.Clo.PrintErrorModel = 1;
            CommandLineOptions.Clo.UseProverEvaluate = true;
            CommandLineOptions.Clo.ModelViewFile = "z3model";
            CommandLineOptions.Clo.UseArrayTheory = true;
            CommandLineOptions.Clo.TypeEncodingMethod = CommandLineOptions.TypeEncoding.Monomorphic;

            // Run Abstract Houdini
            var mlice = new Houdini.MLHoudini(program, CommandLineOptions.Clo.MLHoudini, filename);
            var mliceout = mlice.ComputeSummaries();
            ProcessOutcome(mliceout.outcome, mliceout.errors, "", stats, Console.Out, CommandLineOptions.Clo.ProverKillTime, er);
            ProcessErrors(mliceout.errors, mliceout.outcome, Console.Out, er);

            return PipelineOutcome.Done;
        }