Skip to content

Commit 5aa725d

Browse files
committed
[CodeCompletion] Delete dead code
1 parent acc6c10 commit 5aa725d

File tree

5 files changed

+0
-291
lines changed

5 files changed

+0
-291
lines changed

include/swift/IDE/CompletionLookup.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,19 +534,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
534534

535535
void addPostfixOperatorCompletion(OperatorDecl *op, Type resultType);
536536

537-
void tryPostfixOperator(Expr *expr, PostfixOperatorDecl *op);
538-
539537
void addAssignmentOperator(Type RHSType);
540538

541539
void addInfixOperatorCompletion(OperatorDecl *op, Type resultType,
542540
Type RHSType);
543541

544-
void tryInfixOperatorCompletion(Expr *foldedExpr, InfixOperatorDecl *op);
545-
546-
Expr *typeCheckLeadingSequence(Expr *LHS, ArrayRef<Expr *> leadingSequence);
547-
548-
void getOperatorCompletions(Expr *LHS, ArrayRef<Expr *> leadingSequence);
549-
550542
void addTypeRelationFromProtocol(CodeCompletionResultBuilder &builder,
551543
CodeCompletionLiteralKind kind);
552544

include/swift/Sema/IDETypeChecking.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,6 @@ namespace swift {
128128
ASTContext &Ctx, DeclContext *DC, CompletionTypeCheckKind kind,
129129
Expr *&parsedExpr, ConcreteDeclRef &referencedDecl);
130130

131-
/// Resolve type of operator function with \c opName appending it to \c LHS.
132-
///
133-
/// For \p refKind, use \c DeclRefKind::PostfixOperator for postfix operator,
134-
/// or \c DeclRefKind::BinaryOperator for infix operator.
135-
/// On success, returns resolved function type of the operator. The LHS should
136-
/// already be type-checked. This function guarantees LHS not to be modified.
137-
FunctionType *getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
138-
Identifier opName,
139-
DeclRefKind refKind,
140-
ConcreteDeclRef &referencedDecl);
141-
142-
/// Typecheck the given expression.
143-
bool typeCheckExpression(DeclContext *DC, Expr *&parsedExpr);
144-
145131
/// Type check a function body element which is at \p TagetLoc.
146132
bool typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext TypeCheckCtx,
147133
SourceLoc TargetLoc);

lib/IDE/CompletionLookup.cpp

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,18 +2416,6 @@ void CompletionLookup::addPostfixOperatorCompletion(OperatorDecl *op,
24162416
addTypeAnnotation(builder, resultType);
24172417
}
24182418

2419-
void CompletionLookup::tryPostfixOperator(Expr *expr, PostfixOperatorDecl *op) {
2420-
ConcreteDeclRef referencedDecl;
2421-
FunctionType *funcTy = getTypeOfCompletionOperator(
2422-
const_cast<DeclContext *>(CurrDeclContext), expr, op->getName(),
2423-
DeclRefKind::PostfixOperator, referencedDecl);
2424-
if (!funcTy)
2425-
return;
2426-
2427-
// TODO: Use referencedDecl (FuncDecl) instead of 'op' (OperatorDecl).
2428-
addPostfixOperatorCompletion(op, funcTy->getResult());
2429-
}
2430-
24312419
void CompletionLookup::addAssignmentOperator(Type RHSType) {
24322420
CodeCompletionResultBuilder builder = makeResultBuilder(
24332421
CodeCompletionResultKind::BuiltinOperator, SemanticContextKind::None);
@@ -2472,104 +2460,6 @@ void CompletionLookup::addInfixOperatorCompletion(OperatorDecl *op,
24722460
addTypeAnnotation(builder, resultType);
24732461
}
24742462

2475-
void CompletionLookup::tryInfixOperatorCompletion(Expr *foldedExpr,
2476-
InfixOperatorDecl *op) {
2477-
ConcreteDeclRef referencedDecl;
2478-
FunctionType *funcTy = getTypeOfCompletionOperator(
2479-
const_cast<DeclContext *>(CurrDeclContext), foldedExpr, op->getName(),
2480-
DeclRefKind::BinaryOperator, referencedDecl);
2481-
if (!funcTy)
2482-
return;
2483-
2484-
Type lhsTy = funcTy->getParams()[0].getPlainType();
2485-
Type rhsTy = funcTy->getParams()[1].getPlainType();
2486-
Type resultTy = funcTy->getResult();
2487-
2488-
// Don't complete optional operators on non-optional types.
2489-
if (!lhsTy->getRValueType()->getOptionalObjectType()) {
2490-
// 'T ?? T'
2491-
if (op->getName().str() == "??")
2492-
return;
2493-
// 'T == nil'
2494-
if (auto NT = rhsTy->getNominalOrBoundGenericNominal())
2495-
if (NT->getName() ==
2496-
CurrDeclContext->getASTContext().Id_OptionalNilComparisonType)
2497-
return;
2498-
}
2499-
2500-
// If the right-hand side and result type are both type parameters, we're
2501-
// not providing a useful completion.
2502-
if (resultTy->isTypeParameter() && rhsTy->isTypeParameter())
2503-
return;
2504-
2505-
// TODO: Use referencedDecl (FuncDecl) instead of 'op' (OperatorDecl).
2506-
addInfixOperatorCompletion(op, funcTy->getResult(),
2507-
funcTy->getParams()[1].getPlainType());
2508-
}
2509-
2510-
Expr *
2511-
CompletionLookup::typeCheckLeadingSequence(Expr *LHS,
2512-
ArrayRef<Expr *> leadingSequence) {
2513-
if (leadingSequence.empty())
2514-
return LHS;
2515-
2516-
SourceRange sequenceRange(leadingSequence.front()->getStartLoc(),
2517-
LHS->getEndLoc());
2518-
auto *expr = findParsedExpr(CurrDeclContext, sequenceRange);
2519-
if (!expr)
2520-
return LHS;
2521-
2522-
if (expr->getType() && !expr->getType()->hasError())
2523-
return expr;
2524-
2525-
if (!typeCheckExpression(const_cast<DeclContext *>(CurrDeclContext), expr))
2526-
return expr;
2527-
return LHS;
2528-
}
2529-
2530-
void CompletionLookup::getOperatorCompletions(
2531-
Expr *LHS, ArrayRef<Expr *> leadingSequence) {
2532-
if (IsSuperRefExpr)
2533-
return;
2534-
2535-
Expr *foldedExpr = typeCheckLeadingSequence(LHS, leadingSequence);
2536-
2537-
SmallVector<OperatorDecl *, 16> operators;
2538-
collectOperators(operators);
2539-
// FIXME: this always chooses the first operator with the given name.
2540-
llvm::DenseSet<Identifier> seenPostfixOperators;
2541-
llvm::DenseSet<Identifier> seenInfixOperators;
2542-
2543-
for (auto op : operators) {
2544-
switch (op->getKind()) {
2545-
case DeclKind::PrefixOperator:
2546-
// Don't insert prefix operators in postfix position.
2547-
// FIXME: where should these get completed?
2548-
break;
2549-
case DeclKind::PostfixOperator:
2550-
if (seenPostfixOperators.insert(op->getName()).second)
2551-
tryPostfixOperator(LHS, cast<PostfixOperatorDecl>(op));
2552-
break;
2553-
case DeclKind::InfixOperator:
2554-
if (seenInfixOperators.insert(op->getName()).second)
2555-
tryInfixOperatorCompletion(foldedExpr, cast<InfixOperatorDecl>(op));
2556-
break;
2557-
default:
2558-
llvm_unreachable("unexpected operator kind");
2559-
}
2560-
}
2561-
2562-
if (leadingSequence.empty() && LHS->getType() &&
2563-
LHS->getType()->hasLValueType()) {
2564-
addAssignmentOperator(LHS->getType()->getRValueType());
2565-
}
2566-
2567-
// FIXME: unify this with the ?.member completions.
2568-
if (auto T = LHS->getType())
2569-
if (auto ValueT = T->getRValueType()->getOptionalObjectType())
2570-
addPostfixBang(ValueT);
2571-
}
2572-
25732463
void CompletionLookup::addTypeRelationFromProtocol(
25742464
CodeCompletionResultBuilder &builder, CodeCompletionLiteralKind kind) {
25752465
Type literalType;

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -401,134 +401,6 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
401401
return exprType;
402402
}
403403

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-
532404
static bool hasTypeForCompletion(Solution &solution,
533405
CompletionContextFinder &contextAnalyzer) {
534406
if (contextAnalyzer.hasCompletionExpr()) {
@@ -744,30 +616,6 @@ llvm::Optional<Type> swift::getTypeOfCompletionContextExpr(
744616
referencedDecl);
745617
}
746618

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-
771619
LookupResult
772620
swift::lookupSemanticMember(DeclContext *DC, Type ty, DeclName name) {
773621
return TypeChecker::lookupMember(DC, ty, DeclNameRef(name), SourceLoc(),

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -622,13 +622,6 @@ llvm::Optional<constraints::SyntacticElementTarget>
622622
typeCheckTarget(constraints::SyntacticElementTarget &target,
623623
TypeCheckExprOptions options = TypeCheckExprOptions());
624624

625-
/// Return the type of operator function for specified LHS, or a null
626-
/// \c Type on error.
627-
FunctionType *getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
628-
Identifier opName,
629-
DeclRefKind refKind,
630-
ConcreteDeclRef &refdDecl);
631-
632625
/// Remove any solutions from the provided vector that require more fixes than
633626
/// the best score or don't contain a type for the code completion token.
634627
void filterSolutionsForCodeCompletion(

0 commit comments

Comments
 (0)