]> granicus.if.org Git - clang/commitdiff
Add a stop gap to Sema::CorrectTypo() to correct only up to 20 typos.
authorTed Kremenek <kremenek@apple.com>
Tue, 2 Feb 2010 02:07:01 +0000 (02:07 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 2 Feb 2010 02:07:01 +0000 (02:07 +0000)
This is to address a serious performance problem observed when running
'clang -fsyntax-only' on really broken source files.  In one case,
repeatedly calling CorrectTypo() caused one source file to be rejected
after 2 minutes instead of 1 second.

This patch causes typo correction to take neglible time on that file
while still providing correction results for the first 20 cases.  I
felt this was a reasonable number for moderately broken source files.

I don't claim this is the best solution.  Comments welcome.  It is
necessary for us to address this issue because it is a serious
performance problem.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95049 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
lib/Sema/Sema.h
lib/Sema/SemaLookup.cpp

index c0e7572cddea8db6eb040f515a48ba29851e0c9b..903b987080dc1aa7783b1d6e20227077477a9b3f 100644 (file)
@@ -364,7 +364,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
     GlobalNewDeleteDeclared(false), 
     CompleteTranslationUnit(CompleteTranslationUnit),
     NumSFINAEErrors(0), NonInstantiationEntries(0), 
-    CurrentInstantiationScope(0) 
+    CurrentInstantiationScope(0), TyposCorrected(0)
 {
   TUScope = 0;
   if (getLangOptions().CPlusPlus)
index 1595941651fcb4b13eea44e1ddedd627ece40899..9e28b519ff36e7105d0a88cec5a78c69d4ba71d8 100644 (file)
@@ -3305,6 +3305,9 @@ public:
   /// variables.
   LocalInstantiationScope *CurrentInstantiationScope;
 
+  /// \brief The number of typos corrected by CorrectTypo.
+  unsigned TyposCorrected;
+
   /// \brief An entity for which implicit template instantiation is required.
   ///
   /// The source location associated with the declaration is the first place in
index 95f0d318de23065e7d2dd401cc8eb7aa32e6adf2..d1a379435ef197ed0f27819e4b0a771911fb1f6c 100644 (file)
@@ -2348,9 +2348,16 @@ void TypoCorrectionConsumer::FoundDecl(NamedDecl *ND, NamedDecl *Hiding,
 bool Sema::CorrectTypo(LookupResult &Res, Scope *S, const CXXScopeSpec *SS,
                        DeclContext *MemberContext, bool EnteringContext,
                        const ObjCObjectPointerType *OPT) {
-  
   if (Diags.hasFatalErrorOccurred())
     return false;
+
+  // Provide a stop gap for files that are just seriously broken.  Trying
+  // to correct all typos can turn into a HUGE performance penalty, causing
+  // some files to take minutes to get rejected by the parser.
+  // FIXME: Is this the right solution?
+  if (TyposCorrected == 20)
+    return false;
+  ++TyposCorrected;
   
   // We only attempt to correct typos for identifiers.
   IdentifierInfo *Typo = Res.getLookupName().getAsIdentifierInfo();