Skip to content

[CodeCompletion] Delete SanitizeExpr #68080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions include/swift/IDE/CompletionLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,19 +534,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {

void addPostfixOperatorCompletion(OperatorDecl *op, Type resultType);

void tryPostfixOperator(Expr *expr, PostfixOperatorDecl *op);

void addAssignmentOperator(Type RHSType);

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

void tryInfixOperatorCompletion(Expr *foldedExpr, InfixOperatorDecl *op);

Expr *typeCheckLeadingSequence(Expr *LHS, ArrayRef<Expr *> leadingSequence);

void getOperatorCompletions(Expr *LHS, ArrayRef<Expr *> leadingSequence);

void addTypeRelationFromProtocol(CodeCompletionResultBuilder &builder,
CodeCompletionLiteralKind kind);

Expand Down
14 changes: 0 additions & 14 deletions include/swift/Sema/IDETypeChecking.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,6 @@ namespace swift {
ASTContext &Ctx, DeclContext *DC, CompletionTypeCheckKind kind,
Expr *&parsedExpr, ConcreteDeclRef &referencedDecl);

/// Resolve type of operator function with \c opName appending it to \c LHS.
///
/// For \p refKind, use \c DeclRefKind::PostfixOperator for postfix operator,
/// or \c DeclRefKind::BinaryOperator for infix operator.
/// On success, returns resolved function type of the operator. The LHS should
/// already be type-checked. This function guarantees LHS not to be modified.
FunctionType *getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
Identifier opName,
DeclRefKind refKind,
ConcreteDeclRef &referencedDecl);

/// Typecheck the given expression.
bool typeCheckExpression(DeclContext *DC, Expr *&parsedExpr);

/// Type check a function body element which is at \p TagetLoc.
bool typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext TypeCheckCtx,
SourceLoc TargetLoc);
Expand Down
110 changes: 0 additions & 110 deletions lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2416,18 +2416,6 @@ void CompletionLookup::addPostfixOperatorCompletion(OperatorDecl *op,
addTypeAnnotation(builder, resultType);
}

void CompletionLookup::tryPostfixOperator(Expr *expr, PostfixOperatorDecl *op) {
ConcreteDeclRef referencedDecl;
FunctionType *funcTy = getTypeOfCompletionOperator(
const_cast<DeclContext *>(CurrDeclContext), expr, op->getName(),
DeclRefKind::PostfixOperator, referencedDecl);
if (!funcTy)
return;

// TODO: Use referencedDecl (FuncDecl) instead of 'op' (OperatorDecl).
addPostfixOperatorCompletion(op, funcTy->getResult());
}

void CompletionLookup::addAssignmentOperator(Type RHSType) {
CodeCompletionResultBuilder builder = makeResultBuilder(
CodeCompletionResultKind::BuiltinOperator, SemanticContextKind::None);
Expand Down Expand Up @@ -2472,104 +2460,6 @@ void CompletionLookup::addInfixOperatorCompletion(OperatorDecl *op,
addTypeAnnotation(builder, resultType);
}

void CompletionLookup::tryInfixOperatorCompletion(Expr *foldedExpr,
InfixOperatorDecl *op) {
ConcreteDeclRef referencedDecl;
FunctionType *funcTy = getTypeOfCompletionOperator(
const_cast<DeclContext *>(CurrDeclContext), foldedExpr, op->getName(),
DeclRefKind::BinaryOperator, referencedDecl);
if (!funcTy)
return;

Type lhsTy = funcTy->getParams()[0].getPlainType();
Type rhsTy = funcTy->getParams()[1].getPlainType();
Type resultTy = funcTy->getResult();

// Don't complete optional operators on non-optional types.
if (!lhsTy->getRValueType()->getOptionalObjectType()) {
// 'T ?? T'
if (op->getName().str() == "??")
return;
// 'T == nil'
if (auto NT = rhsTy->getNominalOrBoundGenericNominal())
if (NT->getName() ==
CurrDeclContext->getASTContext().Id_OptionalNilComparisonType)
return;
}

// If the right-hand side and result type are both type parameters, we're
// not providing a useful completion.
if (resultTy->isTypeParameter() && rhsTy->isTypeParameter())
return;

// TODO: Use referencedDecl (FuncDecl) instead of 'op' (OperatorDecl).
addInfixOperatorCompletion(op, funcTy->getResult(),
funcTy->getParams()[1].getPlainType());
}

Expr *
CompletionLookup::typeCheckLeadingSequence(Expr *LHS,
ArrayRef<Expr *> leadingSequence) {
if (leadingSequence.empty())
return LHS;

SourceRange sequenceRange(leadingSequence.front()->getStartLoc(),
LHS->getEndLoc());
auto *expr = findParsedExpr(CurrDeclContext, sequenceRange);
if (!expr)
return LHS;

if (expr->getType() && !expr->getType()->hasError())
return expr;

if (!typeCheckExpression(const_cast<DeclContext *>(CurrDeclContext), expr))
return expr;
return LHS;
}

void CompletionLookup::getOperatorCompletions(
Expr *LHS, ArrayRef<Expr *> leadingSequence) {
if (IsSuperRefExpr)
return;

Expr *foldedExpr = typeCheckLeadingSequence(LHS, leadingSequence);

SmallVector<OperatorDecl *, 16> operators;
collectOperators(operators);
// FIXME: this always chooses the first operator with the given name.
llvm::DenseSet<Identifier> seenPostfixOperators;
llvm::DenseSet<Identifier> seenInfixOperators;

for (auto op : operators) {
switch (op->getKind()) {
case DeclKind::PrefixOperator:
// Don't insert prefix operators in postfix position.
// FIXME: where should these get completed?
break;
case DeclKind::PostfixOperator:
if (seenPostfixOperators.insert(op->getName()).second)
tryPostfixOperator(LHS, cast<PostfixOperatorDecl>(op));
break;
case DeclKind::InfixOperator:
if (seenInfixOperators.insert(op->getName()).second)
tryInfixOperatorCompletion(foldedExpr, cast<InfixOperatorDecl>(op));
break;
default:
llvm_unreachable("unexpected operator kind");
}
}

if (leadingSequence.empty() && LHS->getType() &&
LHS->getType()->hasLValueType()) {
addAssignmentOperator(LHS->getType()->getRValueType());
}

// FIXME: unify this with the ?.member completions.
if (auto T = LHS->getType())
if (auto ValueT = T->getRValueType()->getOptionalObjectType())
addPostfixBang(ValueT);
}

void CompletionLookup::addTypeRelationFromProtocol(
CodeCompletionResultBuilder &builder, CodeCompletionLiteralKind kind) {
Type literalType;
Expand Down
Loading