Ejemplo n.º 1
0
        public static bool Verify(Dafny.Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er)
        {
            Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter, er);
            translator.InsertChecksums = true;
            translator.UniqueIdPrefix  = uniqueIdPrefix;
            Bpl.Program boogieProgram = translator.Translate(dafnyProgram, r: resolver.MostRecentResolver);

            //Interpreter.ResetTacnyResultList();
            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);
            }
        }
Ejemplo n.º 2
0
 public RunVerifierThreadParams(Dafny.Program i_program, ITextSnapshot i_snapshot, string i_requestId, ResolverTagger i_errorListHolder, bool i_diagnoseTimeouts)
 {
     program          = i_program;
     snapshot         = i_snapshot;
     requestId        = i_requestId;
     errorListHolder  = i_errorListHolder;
     diagnoseTimeouts = i_diagnoseTimeouts;
 }
Ejemplo n.º 3
0
        // Keep track of the most recent resolution results.
        void _aggregator_TagsChanged(object sender, TagsChangedEventArgs e)
        {
            var r = sender as ResolverTagger;

            if (r != null)
            {
                lock (this) {
                    resolver = r;
                }
                timer.Stop();
                timer.Start();
            }
        }
Ejemplo n.º 4
0
        public void ShowErrorModel(IWpfTextView activeTextView)
        {
            ResolverTagger resolver = null;
            var            show     = activeTextView != null &&
                                      DafnyLanguage.ResolverTagger.ResolverTaggers.TryGetValue(activeTextView.TextBuffer, out resolver) &&
                                      resolver.Program != null &&
                                      resolver.VerificationErrors.Any(err => err.IsSelected && !string.IsNullOrEmpty(err.ModelText));

            if (show)
            {
                var selectedError = resolver.VerificationErrors.FirstOrDefault(err => err.IsSelected && !string.IsNullOrEmpty(err.ModelText));

                if (selectedError != null)
                {
                    DafnyMenuPackage.ShowErrorModelInBVD(selectedError.ModelText, selectedError.SelectedStateId);
                }
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        void RunVerifier(Dafny.Program program, ITextSnapshot snapshot, string requestId, ResolverTagger errorListHolder, bool diagnoseTimeouts)
        {
            Contract.Requires(program != null);
            Contract.Requires(snapshot != null);
            Contract.Requires(requestId != null);
            Contract.Requires(errorListHolder != null);

            if (_logSnapshots)
            {
                var logDirName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(program.FullName), "logs");
                Directory.CreateDirectory(logDirName);
                var logFileName = System.IO.Path.Combine(logDirName, System.IO.Path.GetFileName(System.IO.Path.ChangeExtension(program.FullName, string.Format("{0}.v{1}{2}", _created.Ticks, _version, System.IO.Path.GetExtension(program.FullName)))));
                using (var writer = new StreamWriter(logFileName))
                {
                    snapshot.Write(writer);
                }
                _version++;
            }

            DafnyDriver.SetDiagnoseTimeouts(diagnoseTimeouts);

            try
            {
                string filename = _document != null ? _document.FilePath : "<program>";
                var    driver   = new DafnyDriver(_buffer, filename);
                bool   success  = driver.Verify(program, errorListHolder, GetHashCode().ToString(), requestId, errorInfo =>
                {
                    if (!_disposed)
                    {
                        errorInfo.BoogieErrorCode = null;
                        var isRecycled            = false;
                        ITextSnapshot s           = null;
                        if (errorInfo.OriginalRequestId != null)
                        {
                            isRecycled = errorInfo.OriginalRequestId != requestId;
                            RequestIdToSnapshot.TryGetValue(errorInfo.OriginalRequestId, out s);
                        }
                        if (s == null && errorInfo.RequestId != null)
                        {
                            RequestIdToSnapshot.TryGetValue(errorInfo.RequestId, out s);
                        }
                        if (s != null)
                        {
                            errorListHolder.AddError(new DafnyError(errorInfo.Tok.filename, errorInfo.Tok.line - 1, errorInfo.Tok.col - 1, ErrorCategory.VerificationError, errorInfo.FullMsg, s, isRecycled, errorInfo.Model.ToString(), System.IO.Path.GetFullPath(_document.FilePath) == errorInfo.Tok.filename), errorInfo.ImplementationName, requestId);
                            foreach (var aux in errorInfo.Aux)
                            {
                                errorListHolder.AddError(new DafnyError(aux.Tok.filename, aux.Tok.line - 1, aux.Tok.col - 1, ErrorCategory.AuxInformation, aux.FullMsg, s, isRecycled, null, System.IO.Path.GetFullPath(_document.FilePath) == aux.Tok.filename), errorInfo.ImplementationName, requestId);
                            }
                        }
                    }
                });
                if (!success)
                {
                    foreach (var error in driver.Errors)
                    {
                        errorListHolder.AddError(error, "$$program$$", requestId);
                    }
                }
            }
            catch (Exception e)
            {
                errorListHolder.AddError(new DafnyError("$$program$$", 0, 0, ErrorCategory.InternalError, "Verification process error: " + e.Message, snapshot, false), "$$program$$", requestId);
            }
            finally
            {
                DafnyDriver.SetDiagnoseTimeouts(!diagnoseTimeouts);
            }

            lock (this) {
                bufferChangesPreVerificationStart.Clear();
                verificationInProgress = false;
            }

            errorListHolder.UpdateErrorList(snapshot);

            // Notify to-whom-it-may-concern about the cleared pre-verification changes
            NotifyAboutChangedTags(snapshot);

            // If new changes took place since we started the verification, we may need to kick off another verification
            // immediately.
            UponIdle(null, null);
        }
Ejemplo n.º 7
0
        private void RunVerifier(Dafny.Program program, ITextSnapshot snapshot, string requestId, ResolverTagger errorListHolder, bool diagnoseTimeouts)
        {
            Contract.Requires(program != null);
            Contract.Requires(snapshot != null);
            Contract.Requires(requestId != null);
            Contract.Requires(errorListHolder != null);

            if (_logSnapshots)
            {
                var logDirName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(program.FullName), "logs");
                Directory.CreateDirectory(logDirName);
                var logFileName = System.IO.Path.Combine(logDirName, System.IO.Path.GetFileName(System.IO.Path.ChangeExtension(program.FullName, string.Format("{0}.v{1}{2}", _created.Ticks, _version, System.IO.Path.GetExtension(program.FullName)))));
                using (var writer = new StreamWriter(logFileName))
                {
                    snapshot.Write(writer);
                }
                _version++;
            }

            DafnyDriver.SetDiagnoseTimeouts(diagnoseTimeouts);
            errorListHolder.FatalVerificationError = null;
            var tacticsErrorList = new List <Tacny.CompoundErrorInformation>();

            //var unresolvedProgram = new TacnyDriver(snapshot.TextBuffer, _document.FilePath).ReParse(false);
            //Dafny.Program unresolvedProgram = null;
            // if (!TacnyDriver.GetExistingProgramFromBuffer(snapshot.TextBuffer, out unresolvedProgram))
            //  unresolvedProgram = new TacnyDriver(snapshot.TextBuffer, _document.FilePath).ReParse(false);

            var success = true;

#if !DEBUGTHROW
            try
            {
#endif
            success = DafnyDriver.Verify(program, errorListHolder, GetHashCode().ToString(), requestId, errorInfo =>
            {
                if (_disposed)
                {
                    return;
                }

                var tacticErrorInfo = errorInfo as Tacny.CompoundErrorInformation;
                if (tacticErrorInfo != null)
                {
                    tacticsErrorList.Add(tacticErrorInfo);
                    return;
                }

                errorInfo.BoogieErrorCode = null;
                var isRecycled            = false;
                ITextSnapshot s           = null;
                if (errorInfo.OriginalRequestId != null)
                {
                    isRecycled = errorInfo.OriginalRequestId != requestId;
                    RequestIdToSnapshot.TryGetValue(errorInfo.OriginalRequestId, out s);
                }
                if (s == null && errorInfo.RequestId != null)
                {
                    RequestIdToSnapshot.TryGetValue(errorInfo.RequestId, out s);
                }
                if (s == null)
                {
                    return;
                }

                errorListHolder.AddError(
                    new DafnyError(errorInfo.Tok.filename, errorInfo.Tok.line - 1, errorInfo.Tok.col - 1,
                                   ErrorCategory.VerificationError, errorInfo.FullMsg, s, isRecycled, errorInfo.Model.ToString(),
                                   System.IO.Path.GetFullPath(_document.FilePath) == errorInfo.Tok.filename),
                    errorInfo.ImplementationName, requestId);
                foreach (var aux in errorInfo.Aux)
                {
                    errorListHolder.AddError(
                        new DafnyError(aux.Tok.filename, aux.Tok.line - 1, aux.Tok.col - 1,
                                       ErrorCategory.AuxInformation, aux.FullMsg, s, isRecycled, null,
                                       System.IO.Path.GetFullPath(_document.FilePath) == aux.Tok.filename),
                        errorInfo.ImplementationName, requestId);
                }
            });
            if (!success)
            {
                errorListHolder.AddError(
                    new DafnyError("$$program$$", 0, 0, ErrorCategory.InternalError, "Verification process error", snapshot, false),
                    "$$program$$", requestId);
            }
#if !DEBUGTHROW
        }

        catch (Exception e)
        {
            errorListHolder.FatalVerificationError = new DafnyError("$$program$$", 0, 0,
                                                                    ErrorCategory.InternalError, "Fatal verification error: " + e.Message + "\n" + e.StackTrace, snapshot, false);
        }
        finally
        {
#endif
            ITextSnapshot snap;
            RequestIdToSnapshot.TryGetValue(requestId, out snap);
            var addedErrors = new List <DafnyError>();
            if (tacticsErrorList.Count > 0)
            {
                success = false;
                try {
                    tacticsErrorList.ForEach(errorInfo => new TacticErrorReportingResolver(errorInfo)
                                             .AddTacticErrors(addedErrors, snap, _document.FilePath));
                    addedErrors.ForEach(error => errorListHolder.AddError(error, "$$program_tactics$$", requestId));
                } catch (TacticErrorResolutionException e) {
                    errorListHolder.AddError(
                        new DafnyError("$$program_tactics$$", 0, 0, ErrorCategory.InternalError,
                                       "Error resolving tactics error " + e.Message + "\n" + e.StackTrace, snapshot, false),
                        "$$program_tactics$$", requestId);
                }
            }
            DafnyDriver.SetDiagnoseTimeouts(!diagnoseTimeouts);
#if !DEBUGTHROW
        }
#endif
            lock (this) {
                bufferChangesPreVerificationStart.Clear();
                verificationInProgress = false;
            }

            if (success)
            {
                DafnyClassifier.DafnyMenuPackage.TacnyMenuProxy.UpdateRot(_document.FilePath, snapshot);
            }

            errorListHolder.UpdateErrorList(snapshot);

            // Notify to-whom-it-may-concern about the cleared pre-verification changes
            NotifyAboutChangedTags(snapshot);

            // If new changes took place since we started the verification, we may need to kick off another verification
            // immediately.
            UponIdle(null, null);
        }