@@ -179,10 +179,6 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
179
179
180
180
ConcreteDeclRef callee;
181
181
if (auto *calleeDRE = dyn_cast<DeclRefExpr>(base)) {
182
- // This only cares about declarations of noescape function type.
183
- auto AFT = calleeDRE->getType ()->getAs <FunctionType>();
184
- if (AFT && AFT->isNoEscape ())
185
- checkNoEscapeParameterCall (Call);
186
182
checkForSuspiciousBitCasts (calleeDRE, Call);
187
183
callee = calleeDRE->getDeclRef ();
188
184
@@ -416,104 +412,6 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
416
412
TC.diagnose (E->getStartLoc (), diag::value_of_module_type);
417
413
}
418
414
419
- class NoEscapeArgument {
420
- llvm::PointerIntPair<ParamDecl*, 1 , bool > ParamAndIsCapture;
421
- public:
422
- NoEscapeArgument () {}
423
- NoEscapeArgument (ParamDecl *param, bool isCapture)
424
- : ParamAndIsCapture(param, isCapture) {
425
- assert (param);
426
- }
427
-
428
- explicit operator bool () const {
429
- return ParamAndIsCapture.getPointer () != nullptr ;
430
- }
431
-
432
- ParamDecl *getDecl () const { return ParamAndIsCapture.getPointer (); }
433
- bool isDeclACapture () const { return ParamAndIsCapture.getInt (); }
434
-
435
- static NoEscapeArgument find (TypeChecker &tc, ValueDecl *decl,
436
- bool isCapture) {
437
- if (auto param = dyn_cast<ParamDecl>(decl)) {
438
- if (auto fnType =
439
- param->getInterfaceType ()->getAs <AnyFunctionType>()) {
440
- if (fnType->isNoEscape ())
441
- return { param, isCapture };
442
- }
443
- return {};
444
- }
445
-
446
- if (auto fn = dyn_cast<AbstractFunctionDecl>(decl)) {
447
- if (fn->getDeclContext ()->isLocalContext ()) {
448
- return findInCaptures (tc, fn);
449
- }
450
- return {};
451
- }
452
-
453
- // FIXME: captures of computed local vars? Can these be non-escaping?
454
- return {};
455
- }
456
-
457
- static NoEscapeArgument findInCaptures (TypeChecker &tc,
458
- AnyFunctionRef fn) {
459
- // Ensure we have accurate capture information for the function.
460
- tc.computeCaptures (fn);
461
-
462
- for (const auto &capture : fn.getCaptureInfo ().getCaptures ()) {
463
- if (capture.isDynamicSelfMetadata ()) continue ;
464
- if (auto param = find (tc, capture.getDecl (), true ))
465
- return param;
466
- }
467
- return {};
468
- }
469
- };
470
-
471
- // / Enforce the exclusivity rule against calling a non-escaping
472
- // / function parameter with another non-escaping function parameter
473
- // / as an argument.
474
- void checkNoEscapeParameterCall (ApplyExpr *apply) {
475
- NoEscapeArgument noescapeArgument;
476
- Expr *problematicArg = nullptr ;
477
-
478
- visitArguments (apply, [&](unsigned argIndex, Expr *arg) {
479
- // Just find the first problematic argument.
480
- if (noescapeArgument) return ;
481
-
482
- // Remember the expression which used the argument.
483
- problematicArg = arg;
484
-
485
- // Look through the same set of nodes that we look through when
486
- // checking for no-escape functions.
487
- arg = lookThroughArgument (arg);
488
-
489
- // If the argument isn't noescape, ignore it.
490
- auto fnType = arg->getType ()->getAs <AnyFunctionType>();
491
- if (!fnType || !fnType->isNoEscape ())
492
- return ;
493
-
494
- // Okay, it should be a closure or a decl ref.
495
- if (auto declRef = dyn_cast<DeclRefExpr>(arg)) {
496
- noescapeArgument =
497
- NoEscapeArgument::find (TC, declRef->getDecl (), false );
498
- } else if (auto closure = dyn_cast<AbstractClosureExpr>(arg)) {
499
- noescapeArgument =
500
- NoEscapeArgument::findInCaptures (TC, closure);
501
- } else {
502
- // This can happen with withoutActuallyEscaping.
503
- assert (isa<OpaqueValueExpr>(arg) &&
504
- " unexpected expression yielding noescape closure" );
505
- }
506
- });
507
-
508
- if (!noescapeArgument) return ;
509
-
510
- TC.diagnose (apply->getLoc (),
511
- diag::err_noescape_param_call,
512
- noescapeArgument.getDecl ()->getName (),
513
- noescapeArgument.isDeclACapture ())
514
- .highlight (problematicArg->getSourceRange ());
515
- }
516
-
517
415
// Diagnose metatype values that don't appear as part of a property,
518
416
// method, or constructor reference.
519
417
void checkUseOfMetaTypeName (Expr *E) {
0 commit comments