@@ -401,134 +401,6 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
401
401
return exprType;
402
402
}
403
403
404
- static FunctionType *
405
- getTypeOfCompletionOperatorImpl (DeclContext *DC, Expr *expr,
406
- ConcreteDeclRef &referencedDecl) {
407
- auto &Context = DC->getASTContext ();
408
-
409
- FrontendStatsTracer StatsTracer (Context.Stats ,
410
- " typecheck-completion-operator" , expr);
411
- PrettyStackTraceExpr stackTrace (Context, " type-checking" , expr);
412
-
413
- expr = expr->walk (SanitizeExpr (Context));
414
-
415
- ConstraintSystemOptions options;
416
- options |= ConstraintSystemFlags::SuppressDiagnostics;
417
-
418
- // Construct a constraint system from this expression.
419
- ConstraintSystem CS (DC, options);
420
- expr = CS.generateConstraints (expr, DC);
421
- if (!expr)
422
- return nullptr ;
423
-
424
- if (CS.isDebugMode ()) {
425
- auto &log = llvm::errs ();
426
- auto indent = CS.solverState ? CS.solverState ->getCurrentIndent () : 0 ;
427
- log.indent (indent)
428
- << " ---Initial constraints for the given expression---\n " ;
429
- expr->dump (log, indent);
430
- log << " \n " ;
431
- CS.print (log);
432
- }
433
-
434
- // Attempt to solve the constraint system.
435
- SmallVector<Solution, 4 > viable;
436
- if (CS.solve (viable, FreeTypeVariableBinding::Disallow))
437
- return nullptr ;
438
-
439
- auto &solution = viable[0 ];
440
- if (CS.isDebugMode ()) {
441
- auto &log = llvm::errs ();
442
- auto indent = CS.solverState ? CS.solverState ->getCurrentIndent () : 0 ;
443
- log.indent (indent) << " ---Solution---\n " ;
444
- solution.dump (log, indent);
445
- }
446
-
447
- // Fill the results.
448
- Expr *opExpr = cast<ApplyExpr>(expr)->getFn ();
449
- referencedDecl =
450
- solution.resolveLocatorToDecl (CS.getConstraintLocator (opExpr));
451
-
452
- // Return '(ArgType[, ArgType]) -> ResultType' as a function type.
453
- // We don't use the type of the operator expression because we want the types
454
- // of the *arguments* instead of the types of the parameters.
455
- auto *args = cast<ApplyExpr>(expr)->getArgs ();
456
- SmallVector<FunctionType::Param, 2 > argTypes;
457
- for (auto arg : *args)
458
- argTypes.emplace_back (solution.simplifyType (CS.getType (arg.getExpr ())));
459
-
460
- // FIXME: Verify ExtInfo state is correct, not working by accident.
461
- FunctionType::ExtInfo info;
462
- return FunctionType::get (argTypes, solution.simplifyType (CS.getType (expr)),
463
- info);
464
- }
465
-
466
- // / Return the type of operator function for specified LHS, or a null
467
- // / \c Type on error.
468
- FunctionType *
469
- TypeChecker::getTypeOfCompletionOperator (DeclContext *DC, Expr *LHS,
470
- Identifier opName, DeclRefKind refKind,
471
- ConcreteDeclRef &referencedDecl) {
472
-
473
- // For the infix operator, find the actual LHS from pre-folded LHS.
474
- if (refKind == DeclRefKind::BinaryOperator)
475
- LHS = TypeChecker::findLHS (DC, LHS, opName);
476
-
477
- if (!LHS)
478
- return nullptr ;
479
-
480
- auto LHSTy = LHS->getType ();
481
-
482
- // FIXME: 'UnresolvedType' still might be typechecked by an operator.
483
- if (!LHSTy || LHSTy->is <UnresolvedType>())
484
- return nullptr ;
485
-
486
- // Meta types and function types cannot be a operand of operator expressions.
487
- if (LHSTy->is <MetatypeType>() || LHSTy->is <AnyFunctionType>())
488
- return nullptr ;
489
-
490
- auto Loc = LHS->getEndLoc ();
491
-
492
- // Build temporary expression to typecheck.
493
- // We allocate these expressions on the stack because we know they can't
494
- // escape and there isn't a better way to allocate scratch Expr nodes.
495
-
496
- // Use a placeholder expr for the LHS argument to avoid sending
497
- // a pre-type-checked AST through the constraint system.
498
- OpaqueValueExpr argExpr (LHS->getSourceRange (), LHSTy,
499
- /* isPlaceholder=*/ true );
500
- UnresolvedDeclRefExpr UDRE (DeclNameRef (opName), refKind, DeclNameLoc (Loc));
501
- auto *opExpr = TypeChecker::resolveDeclRefExpr (
502
- &UDRE, DC, /* replaceInvalidRefsWithErrors=*/ true );
503
-
504
- auto &ctx = DC->getASTContext ();
505
- switch (refKind) {
506
- case DeclRefKind::PostfixOperator: {
507
- // (postfix_unary_expr
508
- // (declref_expr name=<opName>)
509
- // (argument_list
510
- // (<LHS>)))
511
- auto *postfixExpr = PostfixUnaryExpr::create (ctx, opExpr, &argExpr);
512
- return getTypeOfCompletionOperatorImpl (DC, postfixExpr, referencedDecl);
513
- }
514
-
515
- case DeclRefKind::BinaryOperator: {
516
- // (binary_expr
517
- // (declref_expr name=<opName>)
518
- // (argument_list
519
- // (<LHS>)
520
- // (code_completion_expr)))
521
- CodeCompletionExpr dummyRHS (Loc);
522
- auto *binaryExpr = BinaryExpr::create (ctx, &argExpr, opExpr, &dummyRHS,
523
- /* implicit*/ true );
524
- return getTypeOfCompletionOperatorImpl (DC, binaryExpr, referencedDecl);
525
- }
526
-
527
- default :
528
- llvm_unreachable (" Invalid DeclRefKind for operator completion" );
529
- }
530
- }
531
-
532
404
static bool hasTypeForCompletion (Solution &solution,
533
405
CompletionContextFinder &contextAnalyzer) {
534
406
if (contextAnalyzer.hasCompletionExpr ()) {
@@ -744,30 +616,6 @@ llvm::Optional<Type> swift::getTypeOfCompletionContextExpr(
744
616
referencedDecl);
745
617
}
746
618
747
- // / Return the type of operator function for specified LHS, or a null
748
- // / \c Type on error.
749
- FunctionType *
750
- swift::getTypeOfCompletionOperator (DeclContext *DC, Expr *LHS,
751
- Identifier opName, DeclRefKind refKind,
752
- ConcreteDeclRef &referencedDecl) {
753
- auto &ctx = DC->getASTContext ();
754
- DiagnosticSuppression suppression (ctx.Diags );
755
- return TypeChecker::getTypeOfCompletionOperator (DC, LHS, opName, refKind,
756
- referencedDecl);
757
- }
758
-
759
- bool swift::typeCheckExpression (DeclContext *DC, Expr *&parsedExpr) {
760
- auto &ctx = DC->getASTContext ();
761
-
762
- parsedExpr = parsedExpr->walk (SanitizeExpr (ctx));
763
-
764
- DiagnosticSuppression suppression (ctx.Diags );
765
- auto resultTy = TypeChecker::typeCheckExpression (
766
- parsedExpr, DC,
767
- /* contextualInfo=*/ {}, TypeCheckExprFlags::LeaveClosureBodyUnchecked);
768
- return !resultTy;
769
- }
770
-
771
619
LookupResult
772
620
swift::lookupSemanticMember (DeclContext *DC, Type ty, DeclName name) {
773
621
return TypeChecker::lookupMember (DC, ty, DeclNameRef (name), SourceLoc (),
0 commit comments