Skip to content

Commit 9c2400b

Browse files
committed
[CodeCompletion] Delete SanitizeExpr
rdar://111756748
1 parent 211171e commit 9c2400b

File tree

1 file changed

+0
-202
lines changed

1 file changed

+0
-202
lines changed

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 0 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -102,201 +102,6 @@ static Expr *extractKeyPathFromCurryThunkCall(Expr *E) {
102102
return cast<CallExpr>(E)->getArgs()->getUnlabeledUnaryExpr();
103103
}
104104

105-
namespace {
106-
107-
/// AST walker that "sanitizes" an expression for re-typechecking during
108-
/// code completion.
109-
///
110-
/// FIXME: Remove this.
111-
class SanitizeExpr : public ASTWalker {
112-
ASTContext &C;
113-
llvm::SmallDenseMap<OpaqueValueExpr *, Expr *, 4> OpenExistentials;
114-
115-
public:
116-
SanitizeExpr(ASTContext &C)
117-
: C(C) { }
118-
119-
MacroWalking getMacroWalkingBehavior() const override {
120-
return MacroWalking::Arguments;
121-
}
122-
123-
PreWalkResult<ArgumentList *>
124-
walkToArgumentListPre(ArgumentList *argList) override {
125-
// Return the argument list to the state prior to being rewritten. This will
126-
// strip default arguments and expand variadic args.
127-
return Action::Continue(argList->getOriginalArgs());
128-
}
129-
130-
PreWalkResult<Expr *> walkToExprPre(Expr *expr) override {
131-
while (true) {
132-
// OpenExistentialExpr contains OpaqueValueExpr in its sub expression.
133-
if (auto OOE = dyn_cast<OpenExistentialExpr>(expr)) {
134-
auto archetypeVal = OOE->getOpaqueValue();
135-
auto base = OOE->getExistentialValue();
136-
137-
bool inserted = OpenExistentials.insert({archetypeVal, base}).second;
138-
assert(inserted && "OpaqueValue appears multiple times?");
139-
(void)inserted;
140-
SWIFT_DEFER { OpenExistentials.erase(archetypeVal); };
141-
142-
// Walk to and return the base expression to erase any existentials
143-
// within it.
144-
return Action::SkipChildren(OOE->getSubExpr()->walk(*this));
145-
}
146-
147-
// Hacky, this behaves just like an OpenedExistential in that it changes
148-
// the expr tree.
149-
if (auto ISLE = dyn_cast<InterpolatedStringLiteralExpr>(expr)) {
150-
if (auto subExpr = ISLE->getAppendingExpr()->getSubExpr()) {
151-
if (auto opaqueValue = dyn_cast<OpaqueValueExpr>(subExpr)) {
152-
ISLE->getAppendingExpr()->setSubExpr(nullptr);
153-
}
154-
}
155-
}
156-
157-
// Substitute OpaqueValue with its representing existential.
158-
if (auto OVE = dyn_cast<OpaqueValueExpr>(expr)) {
159-
auto value = OpenExistentials.find(OVE);
160-
161-
if (value != OpenExistentials.end()) {
162-
expr = value->second;
163-
continue;
164-
} else {
165-
assert(OVE->isPlaceholder() &&
166-
"Didn't see this OVE in a containing OpenExistentialExpr?");
167-
}
168-
}
169-
170-
// Skip any implicit conversions applied to this expression.
171-
if (auto ICE = dyn_cast<ImplicitConversionExpr>(expr)) {
172-
expr = ICE->getSubExpr();
173-
continue;
174-
}
175-
176-
// MakeTemporarilyEscapableExpr is typechecked expression.
177-
if (auto MTEE = dyn_cast<MakeTemporarilyEscapableExpr>(expr)) {
178-
expr = MTEE->getOriginalExpr();
179-
continue;
180-
}
181-
182-
// Extract keypath from '{ `$kp$` in { $0[keyPath: $kp$] } }(keypath)'
183-
if (isKeyPathCurriedThunkCallExpr(expr)) {
184-
expr = extractKeyPathFromCurryThunkCall(expr);
185-
continue;
186-
}
187-
188-
if (auto ACE = dyn_cast<AutoClosureExpr>(expr)) {
189-
// Restore '@autoclosure'd value.
190-
// This is only valid if the closure doesn't have parameters.
191-
if (ACE->getParameters()->size() == 0) {
192-
expr = ACE->getSingleExpressionBody();
193-
continue;
194-
}
195-
// Restore autoclosure'd function reference.
196-
if (auto *unwrapped = ACE->getUnwrappedCurryThunkExpr()) {
197-
expr = unwrapped;
198-
continue;
199-
}
200-
201-
llvm_unreachable("other AutoClosureExpr must be handled specially");
202-
}
203-
204-
// Remove any semantic expression injected by typechecking.
205-
if (auto EPE = dyn_cast<EditorPlaceholderExpr>(expr)) {
206-
EPE->setSemanticExpr(nullptr);
207-
}
208-
209-
// If this is a closure, only walk into its children if they
210-
// are type-checked in the context of the enclosing expression.
211-
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
212-
for (auto &Param : *closure->getParameters()) {
213-
Param->setSpecifier(swift::ParamSpecifier::Default);
214-
}
215-
}
216-
217-
// Now, we're ready to walk into sub expressions.
218-
return Action::Continue(expr);
219-
}
220-
}
221-
222-
PostWalkResult<Expr *> walkToExprPost(Expr *expr) override {
223-
assert(!isa<ImplicitConversionExpr>(expr) &&
224-
"ImplicitConversionExpr should be eliminated in walkToExprPre");
225-
226-
auto buildMemberRef = [&](Type memberType, Expr *base, SourceLoc dotLoc,
227-
ConcreteDeclRef member, DeclNameLoc memberLoc,
228-
bool implicit) -> Expr * {
229-
auto *memberRef = new (C)
230-
MemberRefExpr(base, dotLoc, member, memberLoc, implicit);
231-
232-
if (memberType) {
233-
memberRef->setType(memberType);
234-
return memberRef;
235-
}
236-
237-
return memberRef;
238-
};
239-
240-
// A DotSyntaxCallExpr is a member reference that has already been
241-
// type-checked down to a call; turn it back into an overloaded
242-
// member reference expression.
243-
if (auto dotCall = dyn_cast<DotSyntaxCallExpr>(expr)) {
244-
DeclNameLoc memberLoc;
245-
auto memberAndFunctionRef = findReferencedDecl(dotCall->getFn(),
246-
memberLoc);
247-
if (memberAndFunctionRef.first) {
248-
assert(!isa<ImplicitConversionExpr>(dotCall->getBase()));
249-
auto *ref = buildMemberRef(dotCall->getType(),
250-
dotCall->getBase(),
251-
dotCall->getDotLoc(),
252-
memberAndFunctionRef.first,
253-
memberLoc, expr->isImplicit());
254-
return Action::Continue(ref);
255-
}
256-
}
257-
258-
if (auto *dynamicMember = dyn_cast<DynamicMemberRefExpr>(expr)) {
259-
if (auto memberRef = dynamicMember->getMember()) {
260-
assert(!isa<ImplicitConversionExpr>(dynamicMember->getBase()));
261-
auto *ref = buildMemberRef(dynamicMember->getType(),
262-
dynamicMember->getBase(),
263-
dynamicMember->getDotLoc(),
264-
memberRef,
265-
dynamicMember->getNameLoc(),
266-
expr->isImplicit());
267-
return Action::Continue(ref);
268-
}
269-
}
270-
271-
// A DotSyntaxBaseIgnoredExpr is a static member reference that has
272-
// already been type-checked down to a call where the argument doesn't
273-
// actually matter; turn it back into an overloaded member reference
274-
// expression.
275-
if (auto dotIgnored = dyn_cast<DotSyntaxBaseIgnoredExpr>(expr)) {
276-
DeclNameLoc memberLoc;
277-
auto memberAndFunctionRef = findReferencedDecl(dotIgnored->getRHS(),
278-
memberLoc);
279-
if (memberAndFunctionRef.first) {
280-
assert(!isa<ImplicitConversionExpr>(dotIgnored->getLHS()));
281-
auto *ref = buildMemberRef(dotIgnored->getType(),
282-
dotIgnored->getLHS(),
283-
dotIgnored->getDotLoc(),
284-
memberAndFunctionRef.first,
285-
memberLoc, expr->isImplicit());
286-
return Action::Continue(ref);
287-
}
288-
}
289-
return Action::Continue(expr);
290-
}
291-
292-
/// Ignore declarations.
293-
PreWalkAction walkToDeclPre(Decl *decl) override {
294-
return Action::SkipChildren();
295-
}
296-
};
297-
298-
} // end namespace
299-
300105
static Type
301106
getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
302107
ConcreteDeclRef &referencedDecl,
@@ -310,8 +115,6 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
310115
}
311116
auto &Context = dc->getASTContext();
312117

313-
expr = expr->walk(SanitizeExpr(Context));
314-
315118
FrontendStatsTracer StatsTracer(Context.Stats,
316119
"typecheck-expr-no-apply", expr);
317120
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
@@ -453,11 +256,6 @@ bool TypeChecker::typeCheckForCodeCompletion(
453256
return false;
454257
}
455258

456-
if (getAsExpr(target.getAsASTNode())) {
457-
SanitizeExpr sanitizer(Context);
458-
target = *target.walk(sanitizer);
459-
}
460-
461259
CompletionContextFinder contextAnalyzer(target, DC);
462260

463261
// If there was no completion expr (e.g. if the code completion location was

0 commit comments

Comments
 (0)