@@ -235,9 +235,6 @@ namespace {
235
235
236
236
bool useASTScopesForLookup () const ;
237
237
238
- // / For testing, assume this lookup is enabled:
239
- bool wouldUseASTScopesForLookupIfItWereEnabled () const ;
240
-
241
238
void lookUpTopLevelNamesInModuleScopeContext (DeclContext *);
242
239
243
240
void lookInASTScopes ();
@@ -399,13 +396,6 @@ namespace {
399
396
void print (raw_ostream &OS) const ;
400
397
void printResults (raw_ostream &OS) const ;
401
398
402
- bool verifyEqualTo (const UnqualifiedLookupFactory &&, StringRef thisLabel,
403
- StringRef otherLabel) const ;
404
-
405
- // / Legacy lookup is wrong here; we should NOT find this symbol.
406
- bool shouldDiffer () const ;
407
- StringRef getSourceFileName () const ;
408
-
409
399
#ifndef NDEBUG
410
400
bool isTargetLookup () const ;
411
401
void stopForDebuggingIfStartingTargetLookup (bool isASTScopeLookup) const ;
@@ -497,14 +487,7 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
497
487
498
488
ContextAndUnresolvedIsCascadingUse contextAndIsCascadingUse{
499
489
DC, initialIsCascadingUse};
500
- const bool crosscheckUnqualifiedLookup =
501
- Ctx.LangOpts .CrosscheckUnqualifiedLookup ;
502
490
if (useASTScopesForLookup ()) {
503
- static bool haveWarned = false ;
504
- if (!haveWarned && Ctx.LangOpts .WarnIfASTScopeLookup ) {
505
- haveWarned = true ;
506
- llvm::errs () << " WARNING: TRYING Scope exclusively\n " ;
507
- }
508
491
lookInASTScopes ();
509
492
} else {
510
493
#ifndef NDEBUG
@@ -516,28 +499,6 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
516
499
else
517
500
lookupNamesIntroducedBy (contextAndIsCascadingUse, NULL );
518
501
}
519
-
520
- if (crosscheckUnqualifiedLookup &&
521
- wouldUseASTScopesForLookupIfItWereEnabled ()) {
522
- ResultsVector results;
523
- size_t indexOfFirstOuterResult = 0 ;
524
- UnqualifiedLookupFactory altLookup (Name, DC, Loc, options, results,
525
- indexOfFirstOuterResult);
526
- if (!useASTScopesForLookup ())
527
- altLookup.lookInASTScopes ();
528
- else if (Name.isOperator ())
529
- altLookup.lookupOperatorInDeclContexts (contextAndIsCascadingUse);
530
- else
531
- altLookup.lookupNamesIntroducedBy (contextAndIsCascadingUse, NULL );
532
-
533
- const auto *ASTScopeLabel = " ASTScope lookup" ;
534
- const auto *contextLabel = " context-bsed lookup" ;
535
- const auto *mainLabel =
536
- useASTScopesForLookup () ? ASTScopeLabel : contextLabel;
537
- const auto *alternateLabel =
538
- useASTScopesForLookup () ? contextLabel : ASTScopeLabel;
539
- assert (verifyEqualTo (std::move (altLookup), mainLabel, alternateLabel));
540
- }
541
502
}
542
503
543
504
void UnqualifiedLookupFactory::lookUpTopLevelNamesInModuleScopeContext (
@@ -562,12 +523,6 @@ void UnqualifiedLookupFactory::lookUpTopLevelNamesInModuleScopeContext(
562
523
}
563
524
564
525
bool UnqualifiedLookupFactory::useASTScopesForLookup () const {
565
- return Ctx.LangOpts .EnableASTScopeLookup &&
566
- wouldUseASTScopesForLookupIfItWereEnabled ();
567
- }
568
-
569
- bool UnqualifiedLookupFactory::wouldUseASTScopesForLookupIfItWereEnabled ()
570
- const {
571
526
if (!Loc.isValid ())
572
527
return false ;
573
528
return (bool ) DC->getParentSourceFile ();
@@ -1335,124 +1290,6 @@ void UnqualifiedLookupFactory::print(raw_ostream &OS) const {
1335
1290
OS << " \n " ;
1336
1291
}
1337
1292
1338
- #pragma mark debugging: output utilities for grepping
1339
-
1340
- static void writeLine (std::string s) {
1341
- llvm::errs () << " \n +-+-+-+- " << s << " \n " ;
1342
- }
1343
-
1344
- StringRef UnqualifiedLookupFactory::getSourceFileName () const {
1345
- return DC->getParentSourceFile ()->getFilename ();
1346
- }
1347
-
1348
- static void writeFirstLine (const UnqualifiedLookupFactory &ul, llvm::Twine s) {
1349
- std::string line =
1350
- std::string (" In file: " ) + ul.getSourceFileName ().str () + " , " + s.str ();
1351
- writeLine (line);
1352
- }
1353
-
1354
- static void writeInconsistent (const UnqualifiedLookupFactory &me,
1355
- StringRef thisLabel,
1356
- const UnqualifiedLookupFactory &other,
1357
- StringRef otherLabel, llvm::Twine s) {
1358
- writeFirstLine (me, s);
1359
- other.print (llvm::errs ());
1360
- llvm::errs () << " \n " << thisLabel << " Results:\n " ;
1361
- me.printResults (llvm::errs ());
1362
- llvm::errs () << " \n " << otherLabel << " Results:\n " ;
1363
- other.printResults (llvm::errs ());
1364
- me.printScopes (llvm::errs ());
1365
- }
1366
-
1367
- #pragma mark comparing results
1368
-
1369
- bool UnqualifiedLookupFactory::verifyEqualTo (
1370
- const UnqualifiedLookupFactory &&other, const StringRef thisLabel,
1371
- StringRef otherLabel) const {
1372
- if (shouldDiffer ()) {
1373
- return true ;
1374
- }
1375
- auto writeErr = [&](llvm::Twine s) {
1376
- writeInconsistent (*this , thisLabel, other, otherLabel, s);
1377
- };
1378
- if (Results.size () != other.Results .size ()) {
1379
- writeErr (thisLabel + " found " + std::to_string (Results.size ()) + " but " +
1380
- otherLabel + " found " + std::to_string (other.Results .size ()));
1381
- assert (false && " mismatch in number of results" );
1382
- }
1383
- for (size_t i : indices (Results)) {
1384
- const auto &e = Results[i];
1385
- const auto &oe = other.Results [i];
1386
- if (e.getValueDecl () != oe.getValueDecl ()) {
1387
- // print_ast_tc_function_bodies.swift generic from subscript vs get fn
1388
- std::string a; llvm::raw_string_ostream as (a);
1389
- std::string b; llvm::raw_string_ostream bs (b);
1390
- e.getValueDecl ()->print (as);
1391
- oe.getValueDecl ()->print (bs);
1392
- if (a == b)
1393
- llvm::errs () << " ValueDecls differ but print same\n " ;
1394
- else {
1395
- writeErr (std::string ( " ValueDecls differ at " ) + std::to_string (i));
1396
- assert (false && " other lookup found different Decl" );
1397
- }
1398
- }
1399
- if (e.getDeclContext () != oe.getDeclContext ()) {
1400
- writeErr ((std::string (" Contexts differ at " )) + std::to_string (i));
1401
- assert (false && " ASTScopeImpl found different context" );
1402
- }
1403
- // unsigned printContext(llvm::raw_ostream &OS, unsigned indent = 0,
1404
- // bool onlyAPartialLine = false) const;
1405
- }
1406
- if (IndexOfFirstOuterResult != other.IndexOfFirstOuterResult ) {
1407
- writeErr ( std::string (" IndexOfFirstOuterResult differs, should be: " )
1408
- + std::to_string (IndexOfFirstOuterResult)
1409
- + std::string ( " , is: " )
1410
- + std::to_string (other.IndexOfFirstOuterResult ));
1411
- assert (false && " other lookup IndexOfFirstOuterResult differs" );
1412
- }
1413
- if (recordedSF != other.recordedSF ) {
1414
- writeErr (std::string (" recordedSF differs: shouldBe: " ) +
1415
- (recordedSF ? recordedSF->getFilename ().str ()
1416
- : std::string (" <no name>" )) +
1417
- std::string (" is: " ) +
1418
- (other.recordedSF ? other.recordedSF ->getFilename ().str ()
1419
- : std::string (" <no name>" )));
1420
- assert (false && " other lookup recordedSF differs" );
1421
- }
1422
- if (recordedSF && recordedIsCascadingUse != other.recordedIsCascadingUse ) {
1423
- writeErr (std::string (" recordedIsCascadingUse differs: shouldBe: " ) +
1424
- std::to_string (recordedIsCascadingUse) + std::string (" is: " ) +
1425
- std::to_string (other.recordedIsCascadingUse ));
1426
- assert (false && " other lookup recordedIsCascadingUse differs" );
1427
- }
1428
- return true ;
1429
- }
1430
-
1431
- bool UnqualifiedLookupFactory::shouldDiffer () const {
1432
- auto *SF = dyn_cast<SourceFile>(DC->getModuleScopeContext ());
1433
- if (!SF)
1434
- return false ;
1435
-
1436
- static std::vector<const char *> testsThatShouldDiffer {
1437
- " swift/test/Constraints/diagnostics.swift" ,
1438
- " swift/test/Constraints/enum_cases.swift" ,
1439
- " swift/test/Constraints/rdar39401774.swift" ,
1440
- " swift/test/Constraints/rdar39401774-astscope.swift" ,
1441
- " swift/test/Interpreter/repl.swift" ,
1442
- " swift/test/Sema/diag_defer_captures.swift" ,
1443
- " swift/test/Sema/diag_use_before_declaration.swift" ,
1444
- " swift/test/SourceKit/CodeFormat/indent-closure.swift" ,
1445
- " swift/test/TypeCoercion/overload_noncall.swift" ,
1446
- " swift/test/expr/capture/nested_class.swift" ,
1447
- " swift/test/expr/capture/order.swift" ,
1448
- " swift/test/NameLookup/name_lookup2.swift"
1449
- };
1450
- StringRef fileName = SF->getFilename ();
1451
- return llvm::any_of (testsThatShouldDiffer, [&](const char *testFile) {
1452
- return fileName.endswith (testFile);
1453
- });
1454
- }
1455
-
1456
1293
#pragma mark breakpointing
1457
1294
#ifndef NDEBUG
1458
1295
0 commit comments