Esempio n. 1
0
        /// <summary>
        /// This method is invoked when the user has been idle for a little while.
        /// Note, "sender" and "args" are allowed to be passed in as null--they are not used by this method.
        /// </summary>
        public void UponIdle(object sender, EventArgs args)
        {
            lock (this) {
                if (verificationInProgress)
                {
                    // This UponIdle message came at an inopportune time--we've already kicked off a verification.
                    // Just back off.
                    resolver.UpdateErrorList(resolver.Snapshot);
                    return;
                }

                if (resolver == null)
                {
                    return;
                }

                Dafny.Program prog;
                ITextSnapshot snap;
                lock (resolver) {
                    prog = resolver.Program;
                    snap = resolver.Snapshot;
                }
                if (prog == null || VerificationDisabled)
                {
                    return;
                }
                // We have a successfully resolved program to verify

                var dt = isDiagnosingTimeouts;
                if (!dt)
                {
                    var resolvedVersion = snap.Version.VersionNumber;
                    if (bufferChangesPostVerificationStart.Count == 0)
                    {
                        // Nothing new to verify.  No reason to start a new verification.
                        return;
                    }
                    else if (!bufferChangesPostVerificationStart.TrueForAll(span => span.Snapshot.Version.VersionNumber <= resolvedVersion))
                    {
                        // There have been buffer changes since the program that was resolved.  Do nothing here,
                        // and instead just await the next resolved program.
                        return;
                    }
                }

                // at this time, we're committed to running the verifier
                lastRequestId = null;
                lock (RequestIdToSnapshot)
                {
                    do
                    {
                        lastRequestId = DateTime.UtcNow.Ticks.ToString();
                    } while (RequestIdToSnapshot.ContainsKey(lastRequestId));
                    RequestIdToSnapshot[lastRequestId] = snap;
                }

                if (_document != null)
                {
                    ProgressTaggers[_document.TextBuffer] = this;
                }

                RunVerifierThreadParams verifierThreadParams = new RunVerifierThreadParams(prog, snap, lastRequestId, resolver, dt);
                Thread thread = new Thread(RunVerifierThreadRoutine, _verificationTaskStackSize);
                thread.Start(verifierThreadParams);

                verificationInProgress = true;
                if (dt)
                {
                    isDiagnosingTimeouts = false;
                }

                // Change orange progress markers into yellow ones
                Contract.Assert(bufferChangesPreVerificationStart.Count == 0); // follows from monitor invariant
                var empty = bufferChangesPreVerificationStart;
                bufferChangesPreVerificationStart  = bufferChangesPostVerificationStart;
                bufferChangesPostVerificationStart = empty;

                // Notify to-whom-it-may-concern about the changes we just made
                NotifyAboutChangedTags(snap);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }