Skip to content

Commit 549f630

Browse files
authored
Merge pull request #30809 from slavapestov/curry-thunk-source-range-fix
Sema: Fix source range for curry thunks
2 parents 08904ff + 5f51546 commit 549f630

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ static bool isUnmapped(ASTNode N) {
6868
LLVM_DEBUG(llvm::dbgs() << "Skipping ASTNode: implicit closure expr\n");
6969
return true;
7070
}
71-
72-
if (isa<AutoClosureExpr>(CE) &&
73-
cast<AutoClosureExpr>(CE)->getThunkKind() != AutoClosureExpr::Kind::None) {
74-
LLVM_DEBUG(llvm::dbgs() << "Skipping ASTNode: curry thunk expr\n");
75-
return true;
76-
}
7771
}
7872

7973
// Map all other kinds of expressions.

lib/Sema/CSApply.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -927,20 +927,31 @@ namespace {
927927
}
928928

929929
// (Self) -> ...
930-
auto *selfCall =
931-
CallExpr::createImplicit(context, ref, selfOpenedRef, { },
932-
[&](const Expr *E) { return cs.getType(E); });
933-
selfCall->setType(refTy->getResult());
934-
cs.cacheType(selfCall->getArg());
935-
cs.cacheType(selfCall);
936-
937-
// FIXME: This is a holdover from the old tuple-based function call
938-
// representation.
939-
auto selfArgTy = ParenType::get(context,
940-
selfParam.getPlainType(),
941-
selfParam.getParameterFlags());
942-
selfCall->getArg()->setType(selfArgTy);
943-
cs.cacheType(selfCall->getArg());
930+
ApplyExpr *selfCall;
931+
932+
// We build either a CallExpr or a DotSyntaxCallExpr depending on whether
933+
// the base is implicit or not. This helps maintain some invariants around
934+
// source ranges.
935+
if (selfParamRef->isImplicit()) {
936+
selfCall =
937+
CallExpr::createImplicit(context, ref, selfOpenedRef, { },
938+
[&](const Expr *E) { return cs.getType(E); });
939+
selfCall->setType(refTy->getResult());
940+
cs.cacheType(selfCall);
941+
942+
// FIXME: This is a holdover from the old tuple-based function call
943+
// representation.
944+
auto selfArgTy = ParenType::get(context,
945+
selfParam.getPlainType(),
946+
selfParam.getParameterFlags());
947+
selfCall->getArg()->setType(selfArgTy);
948+
cs.cacheType(selfCall->getArg());
949+
} else {
950+
selfCall = new (context) DotSyntaxCallExpr(ref, SourceLoc(), selfOpenedRef);
951+
selfCall->setImplicit(false);
952+
selfCall->setType(refTy->getResult());
953+
cs.cacheType(selfCall);
954+
}
944955

945956
if (selfParamRef->isSuperExpr())
946957
selfCall->setIsSuper(true);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %target-swift-emit-silgen %s
2+
3+
class Foo {
4+
init(f: @escaping () -> String = String.init) {
5+
}
6+
}

0 commit comments

Comments
 (0)