Skip to content

Commit 0e1cdb5

Browse files
authored
Merge pull request #68080 from ahoppen/ahoppen/delete-sanitize-expr
[CodeCompletion] Delete `SanitizeExpr`
2 parents 93c42f7 + 9c2400b commit 0e1cdb5

7 files changed

+0
-1781
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;

0 commit comments

Comments
 (0)