Skip to content

Commit d459ec8

Browse files
committed
Disable passing move-only types to our generic logging functions in Playground Transform, as such types are not supported in generics yet.
1 parent 6cdab78 commit d459ec8

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

lib/Sema/PlaygroundTransform.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class Instrumenter : InstrumenterBase {
429429
++EI;
430430
}
431431
}
432-
} else {
432+
} else if (shouldLogType(AE->getSrc()->getType())) {
433433
std::pair<PatternBindingDecl *, VarDecl *> PV =
434434
buildPatternAndVariable(AE->getSrc());
435435
DeclRefExpr *DRE = new (Context)
@@ -521,7 +521,7 @@ class Instrumenter : InstrumenterBase {
521521
}
522522
Handled = true; // Never log ()
523523
}
524-
if (!Handled) {
524+
if (!Handled && shouldLogType(E->getType())) {
525525
// do the same as for all other expressions
526526
std::pair<PatternBindingDecl *, VarDecl *> PV =
527527
buildPatternAndVariable(E);
@@ -539,7 +539,7 @@ class Instrumenter : InstrumenterBase {
539539
}
540540
}
541541
} else {
542-
if (E->getType()->getCanonicalType() != Context.TheEmptyTupleType) {
542+
if (E->getType()->getCanonicalType() != Context.TheEmptyTupleType && shouldLogType(E->getType())) {
543543
std::pair<PatternBindingDecl *, VarDecl *> PV =
544544
buildPatternAndVariable(E);
545545
Added<Stmt *> Log = buildLoggerCall(
@@ -559,7 +559,7 @@ class Instrumenter : InstrumenterBase {
559559
} else if (auto *S = Element.dyn_cast<Stmt *>()) {
560560
S->walk(CF);
561561
if (auto *RS = dyn_cast<ReturnStmt>(S)) {
562-
if (RS->hasResult()) {
562+
if (RS->hasResult() && shouldLogType(RS->getResult()->getType())) {
563563
std::pair<PatternBindingDecl *, VarDecl *> PV =
564564
buildPatternAndVariable(RS->getResult());
565565
DeclRefExpr *DRE = new (Context) DeclRefExpr(
@@ -621,7 +621,7 @@ class Instrumenter : InstrumenterBase {
621621
if (PL && Options.LogFunctionParameters) {
622622
size_t EI = 0;
623623
for (const auto &PD : *PL) {
624-
if (PD->hasName()) {
624+
if (PD->hasName() && shouldLogType(PD->getInterfaceType())) {
625625
DeclBaseName Name = PD->getName();
626626
Expr *PVVarRef = new (Context)
627627
DeclRefExpr(PD, DeclNameLoc(), /*implicit=*/true,
@@ -658,6 +658,10 @@ class Instrumenter : InstrumenterBase {
658658
// after or instead of the expression they're looking at. Only call this
659659
// if the variable has an initializer.
660660
Added<Stmt *> logVarDecl(VarDecl *VD) {
661+
if (!shouldLogType(VD->getInterfaceType())) {
662+
return nullptr;
663+
}
664+
661665
if (isa<ConstructorDecl>(TypeCheckDC) && VD->getNameStr().equals("self")) {
662666
// Don't log "self" in a constructor
663667
return nullptr;
@@ -674,6 +678,10 @@ class Instrumenter : InstrumenterBase {
674678
if (auto *DRE = dyn_cast<DeclRefExpr>(*RE)) {
675679
VarDecl *VD = cast<VarDecl>(DRE->getDecl());
676680

681+
if (!shouldLogType(VD->getInterfaceType())) {
682+
return nullptr;
683+
}
684+
677685
if (isa<ConstructorDecl>(TypeCheckDC) && VD->getBaseName() == "self") {
678686
// Don't log "self" in a constructor
679687
return nullptr;
@@ -686,6 +694,11 @@ class Instrumenter : InstrumenterBase {
686694
} else if (auto *MRE = dyn_cast<MemberRefExpr>(*RE)) {
687695
Expr *B = MRE->getBase();
688696
ConcreteDeclRef M = MRE->getMember();
697+
VarDecl *VD = cast<VarDecl>(M.getDecl());
698+
699+
if (!shouldLogType(VD->getInterfaceType())) {
700+
return nullptr;
701+
}
689702

690703
if (isa<ConstructorDecl>(TypeCheckDC) && digForName(B) == "self") {
691704
// Don't log attributes of "self" in a constructor
@@ -786,6 +799,14 @@ class Instrumenter : InstrumenterBase {
786799
return std::make_pair(PBD, VD);
787800
}
788801

802+
bool shouldLogType(Type Ty) {
803+
// Don't try to log ~Copyable types, as we can't pass them to the generic logging functions yet.
804+
if (Ty->isNoncopyable()) {
805+
return false;
806+
}
807+
return true;
808+
}
809+
789810
Added<Stmt *> buildLoggerCall(Added<Expr *> E, SourceRange SR,
790811
StringRef Name) {
791812
Expr *NameExpr = new (Context) StringLiteralExpr(

0 commit comments

Comments
 (0)