|
24 | 24 | #include "swift/AST/GenericEnvironment.h" |
25 | 25 | #include "swift/AST/Initializer.h" |
26 | 26 | #include "swift/AST/NameLookup.h" |
| 27 | +#include "swift/AST/NameLookupRequests.h" |
27 | 28 | #include "swift/AST/ParameterList.h" |
28 | 29 | #include "swift/AST/PrettyStackTrace.h" |
29 | 30 | #include "swift/AST/PropertyWrappers.h" |
@@ -364,164 +365,101 @@ SILGenModule::getConformanceToBridgedStoredNSError(SILLocation loc, Type type) { |
364 | 365 | return SwiftModule->lookupConformance(type, proto); |
365 | 366 | } |
366 | 367 |
|
367 | | -static FuncDecl *lookupIntrinsic(ModuleDecl &module, |
368 | | - llvm::Optional<FuncDecl *> &cache, |
369 | | - Identifier name) { |
370 | | - if (cache) |
371 | | - return *cache; |
372 | | - |
373 | | - SmallVector<ValueDecl *, 1> decls; |
374 | | - module.lookupQualified(&module, DeclNameRef(name), SourceLoc(), |
375 | | - NL_QualifiedDefault | NL_IncludeUsableFromInline, |
376 | | - decls); |
377 | | - if (decls.size() != 1) { |
378 | | - cache = nullptr; |
379 | | - return nullptr; |
380 | | - } |
381 | | - auto func = dyn_cast<FuncDecl>(decls[0]); |
382 | | - cache = func; |
383 | | - return func; |
384 | | -} |
385 | | - |
386 | | -static FuncDecl *lookupConcurrencyIntrinsic(ASTContext &C, |
387 | | - llvm::Optional<FuncDecl *> &cache, |
388 | | - StringRef name) { |
| 368 | +static FuncDecl *lookupConcurrencyIntrinsic(ASTContext &C, StringRef name) { |
389 | 369 | auto *module = C.getLoadedModule(C.Id_Concurrency); |
390 | | - if (!module) { |
391 | | - cache = nullptr; |
| 370 | + if (!module) |
392 | 371 | return nullptr; |
393 | | - } |
394 | 372 |
|
395 | | - return lookupIntrinsic(*module, cache, C.getIdentifier(name)); |
| 373 | + return evaluateOrDefault( |
| 374 | + C.evaluator, LookupIntrinsicRequest{module, C.getIdentifier(name)}, |
| 375 | + /*default=*/nullptr); |
396 | 376 | } |
397 | 377 |
|
398 | | -FuncDecl * |
399 | | -SILGenModule::getAsyncLetStart() { |
400 | | - return lookupConcurrencyIntrinsic(getASTContext(), |
401 | | - AsyncLetStart, |
402 | | - "_asyncLetStart"); |
| 378 | +FuncDecl *SILGenModule::getAsyncLetStart() { |
| 379 | + return lookupConcurrencyIntrinsic(getASTContext(), "_asyncLetStart"); |
403 | 380 | } |
404 | 381 |
|
405 | | -FuncDecl * |
406 | | -SILGenModule::getAsyncLetGet() { |
407 | | - return lookupConcurrencyIntrinsic(getASTContext(), |
408 | | - AsyncLetGet, |
409 | | - "_asyncLet_get"); |
| 382 | +FuncDecl *SILGenModule::getAsyncLetGet() { |
| 383 | + return lookupConcurrencyIntrinsic(getASTContext(), "_asyncLet_get"); |
410 | 384 | } |
411 | 385 |
|
412 | | -FuncDecl * |
413 | | -SILGenModule::getAsyncLetGetThrowing() { |
414 | | - return lookupConcurrencyIntrinsic(getASTContext(), |
415 | | - AsyncLetGetThrowing, |
416 | | - "_asyncLet_get_throwing"); |
| 386 | +FuncDecl *SILGenModule::getAsyncLetGetThrowing() { |
| 387 | + return lookupConcurrencyIntrinsic(getASTContext(), "_asyncLet_get_throwing"); |
417 | 388 | } |
418 | 389 |
|
419 | | -FuncDecl * |
420 | | -SILGenModule::getFinishAsyncLet() { |
421 | | - return lookupConcurrencyIntrinsic(getASTContext(), |
422 | | - EndAsyncLet, |
423 | | - "_asyncLet_finish"); |
| 390 | +FuncDecl *SILGenModule::getFinishAsyncLet() { |
| 391 | + return lookupConcurrencyIntrinsic(getASTContext(), "_asyncLet_finish"); |
424 | 392 | } |
425 | 393 |
|
426 | | -FuncDecl * |
427 | | -SILGenModule::getTaskFutureGet() { |
428 | | - return lookupConcurrencyIntrinsic(getASTContext(), |
429 | | - TaskFutureGet, |
430 | | - "_taskFutureGet"); |
| 394 | +FuncDecl *SILGenModule::getTaskFutureGet() { |
| 395 | + return lookupConcurrencyIntrinsic(getASTContext(), "_taskFutureGet"); |
431 | 396 | } |
432 | 397 |
|
433 | | -FuncDecl * |
434 | | -SILGenModule::getTaskFutureGetThrowing() { |
435 | | - return lookupConcurrencyIntrinsic(getASTContext(), |
436 | | - TaskFutureGetThrowing, |
437 | | - "_taskFutureGetThrowing"); |
| 398 | +FuncDecl *SILGenModule::getTaskFutureGetThrowing() { |
| 399 | + return lookupConcurrencyIntrinsic(getASTContext(), "_taskFutureGetThrowing"); |
438 | 400 | } |
439 | 401 |
|
440 | | -FuncDecl * |
441 | | -SILGenModule::getResumeUnsafeContinuation() { |
| 402 | +FuncDecl *SILGenModule::getResumeUnsafeContinuation() { |
442 | 403 | return lookupConcurrencyIntrinsic(getASTContext(), |
443 | | - ResumeUnsafeContinuation, |
444 | 404 | "_resumeUnsafeContinuation"); |
445 | 405 | } |
446 | | -FuncDecl * |
447 | | -SILGenModule::getResumeUnsafeThrowingContinuation() { |
| 406 | +FuncDecl *SILGenModule::getResumeUnsafeThrowingContinuation() { |
448 | 407 | return lookupConcurrencyIntrinsic(getASTContext(), |
449 | | - ResumeUnsafeThrowingContinuation, |
450 | 408 | "_resumeUnsafeThrowingContinuation"); |
451 | 409 | } |
452 | | -FuncDecl * |
453 | | -SILGenModule::getResumeUnsafeThrowingContinuationWithError() { |
454 | | - return lookupConcurrencyIntrinsic(getASTContext(), |
455 | | - ResumeUnsafeThrowingContinuationWithError, |
456 | | - "_resumeUnsafeThrowingContinuationWithError"); |
| 410 | +FuncDecl *SILGenModule::getResumeUnsafeThrowingContinuationWithError() { |
| 411 | + return lookupConcurrencyIntrinsic( |
| 412 | + getASTContext(), "_resumeUnsafeThrowingContinuationWithError"); |
457 | 413 | } |
458 | | -FuncDecl * |
459 | | -SILGenModule::getRunTaskForBridgedAsyncMethod() { |
| 414 | +FuncDecl *SILGenModule::getRunTaskForBridgedAsyncMethod() { |
460 | 415 | return lookupConcurrencyIntrinsic(getASTContext(), |
461 | | - RunTaskForBridgedAsyncMethod, |
462 | 416 | "_runTaskForBridgedAsyncMethod"); |
463 | 417 | } |
464 | | -FuncDecl * |
465 | | -SILGenModule::getCheckExpectedExecutor() { |
466 | | - return lookupConcurrencyIntrinsic(getASTContext(), CheckExpectedExecutor, |
467 | | - "_checkExpectedExecutor"); |
| 418 | +FuncDecl *SILGenModule::getCheckExpectedExecutor() { |
| 419 | + return lookupConcurrencyIntrinsic(getASTContext(), "_checkExpectedExecutor"); |
468 | 420 | } |
469 | 421 |
|
470 | | -FuncDecl * |
471 | | -SILGenModule::getCreateCheckedContinuation() { |
| 422 | +FuncDecl *SILGenModule::getCreateCheckedContinuation() { |
472 | 423 | return lookupConcurrencyIntrinsic(getASTContext(), |
473 | | - CreateCheckedContinuation, |
474 | 424 | "_createCheckedContinuation"); |
475 | 425 | } |
476 | | -FuncDecl * |
477 | | -SILGenModule::getCreateCheckedThrowingContinuation() { |
| 426 | +FuncDecl *SILGenModule::getCreateCheckedThrowingContinuation() { |
478 | 427 | return lookupConcurrencyIntrinsic(getASTContext(), |
479 | | - CreateCheckedThrowingContinuation, |
480 | 428 | "_createCheckedThrowingContinuation"); |
481 | 429 | } |
482 | | -FuncDecl * |
483 | | -SILGenModule::getResumeCheckedContinuation() { |
| 430 | +FuncDecl *SILGenModule::getResumeCheckedContinuation() { |
484 | 431 | return lookupConcurrencyIntrinsic(getASTContext(), |
485 | | - ResumeCheckedContinuation, |
486 | 432 | "_resumeCheckedContinuation"); |
487 | 433 | } |
488 | | -FuncDecl * |
489 | | -SILGenModule::getResumeCheckedThrowingContinuation() { |
| 434 | +FuncDecl *SILGenModule::getResumeCheckedThrowingContinuation() { |
490 | 435 | return lookupConcurrencyIntrinsic(getASTContext(), |
491 | | - ResumeCheckedThrowingContinuation, |
492 | 436 | "_resumeCheckedThrowingContinuation"); |
493 | 437 | } |
494 | | -FuncDecl * |
495 | | -SILGenModule::getResumeCheckedThrowingContinuationWithError() { |
| 438 | +FuncDecl *SILGenModule::getResumeCheckedThrowingContinuationWithError() { |
496 | 439 | return lookupConcurrencyIntrinsic( |
497 | | - getASTContext(), ResumeCheckedThrowingContinuationWithError, |
498 | | - "_resumeCheckedThrowingContinuationWithError"); |
| 440 | + getASTContext(), "_resumeCheckedThrowingContinuationWithError"); |
499 | 441 | } |
500 | 442 |
|
501 | 443 | FuncDecl *SILGenModule::getAsyncMainDrainQueue() { |
502 | | - return lookupConcurrencyIntrinsic(getASTContext(), AsyncMainDrainQueue, |
503 | | - "_asyncMainDrainQueue"); |
| 444 | + return lookupConcurrencyIntrinsic(getASTContext(), "_asyncMainDrainQueue"); |
504 | 445 | } |
505 | 446 |
|
506 | 447 | FuncDecl *SILGenModule::getSwiftJobRun() { |
507 | | - return lookupConcurrencyIntrinsic(getASTContext(), SwiftJobRun, |
508 | | - "_swiftJobRun"); |
| 448 | + return lookupConcurrencyIntrinsic(getASTContext(), "_swiftJobRun"); |
509 | 449 | } |
510 | 450 |
|
511 | 451 | FuncDecl *SILGenModule::getExit() { |
512 | | - if (ExitFunc) |
513 | | - return *ExitFunc; |
514 | | - |
515 | 452 | ASTContext &C = getASTContext(); |
516 | 453 | ModuleDecl *concurrencyShims = |
517 | 454 | C.getModuleByIdentifier(C.getIdentifier("_SwiftConcurrencyShims")); |
518 | 455 |
|
519 | | - if (!concurrencyShims) { |
520 | | - ExitFunc = nullptr; |
| 456 | + if (!concurrencyShims) |
521 | 457 | return nullptr; |
522 | | - } |
523 | 458 |
|
524 | | - return lookupIntrinsic(*concurrencyShims, ExitFunc, C.getIdentifier("exit")); |
| 459 | + return evaluateOrDefault( |
| 460 | + C.evaluator, |
| 461 | + LookupIntrinsicRequest{concurrencyShims, C.getIdentifier("exit")}, |
| 462 | + /*default=*/nullptr); |
525 | 463 | } |
526 | 464 |
|
527 | 465 | ProtocolConformance *SILGenModule::getNSErrorConformanceToError() { |
|
0 commit comments