Skip to content

Commit 4234fb7

Browse files
authored
Merge pull request #85340 from egorzhdan/egorzhdan/revert-cs-std-string
Revert "[ConstraintSystem] C++ Interop: Binding a string literal to `std.string` shouldn't increase the score"
2 parents 158729c + 6852bc9 commit 4234fb7

File tree

6 files changed

+4
-75
lines changed

6 files changed

+4
-75
lines changed

include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ IDENTIFIER(Any)
3535
IDENTIFIER(ArrayLiteralElement)
3636
IDENTIFIER(asLocalActor)
3737
IDENTIFIER(atIndexedSubscript)
38-
IDENTIFIER(basic_string)
3938
IDENTIFIER_(bridgeToObjectiveC)
4039
IDENTIFIER(buildArray)
4140
IDENTIFIER(buildBlock)

include/swift/AST/Types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
11121112
/// Check if this is a ObjCBool type from the Objective-C module.
11131113
bool isObjCBool();
11141114

1115-
/// Check if this is a std.string type from C++.
1116-
bool isCxxString();
1117-
11181115
/// Check if this is the type Unicode.Scalar from the Swift standard library.
11191116
bool isUnicodeScalar();
11201117

lib/AST/Type.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "swift/AST/Types.h"
4444
#include "swift/Basic/Assertions.h"
4545
#include "swift/Basic/Compiler.h"
46-
#include "clang/AST/DeclCXX.h"
4746
#include "llvm/ADT/APFloat.h"
4847
#include "llvm/ADT/STLExtras.h"
4948
#include "llvm/ADT/SmallPtrSet.h"
@@ -1303,21 +1302,6 @@ bool TypeBase::isObjCBool() {
13031302
return module->getName().is("ObjectiveC") && NTD->getName().is("ObjCBool");
13041303
}
13051304

1306-
bool TypeBase::isCxxString() {
1307-
auto *nominal = getAnyNominal();
1308-
if (!nominal)
1309-
return false;
1310-
1311-
auto *clangDecl =
1312-
dyn_cast_or_null<clang::CXXRecordDecl>(nominal->getClangDecl());
1313-
if (!clangDecl)
1314-
return false;
1315-
1316-
auto &ctx = nominal->getASTContext();
1317-
return clangDecl->isInStdNamespace() && clangDecl->getIdentifier() &&
1318-
ctx.Id_basic_string.is(clangDecl->getName());
1319-
}
1320-
13211305
bool TypeBase::isUnicodeScalar() {
13221306
if (!is<StructType>())
13231307
return false;

lib/Sema/ConstraintSystem.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -257,28 +257,11 @@ void ConstraintSystem::assignFixedType(TypeVariableType *typeVar, Type type,
257257

258258
// If the protocol has a default type, check it.
259259
if (auto defaultType = TypeChecker::getDefaultType(literalProtocol, DC)) {
260-
auto isDefaultType = [&literalProtocol, &defaultType](Type type) {
261-
// Treat `std.string` as a default type just like we do
262-
// Swift standard library `String`. This helps to disambiguate
263-
// operator overloads that use `std.string` vs. a custom C++
264-
// type that conforms to `ExpressibleByStringLiteral` as well.
265-
//
266-
// This doesn't clash with String because inference won't attempt
267-
// C++ types unless we discover them from a constraint and the
268-
// optimizer and old hacks always prefer the actual default type.
269-
if (literalProtocol->getKnownProtocolKind() ==
270-
KnownProtocolKind::ExpressibleByStringLiteral &&
271-
type->isCxxString()) {
272-
return true;
273-
}
274-
275-
// Check whether the nominal types match. This makes sure that we
276-
// properly handle Array vs. Array<T>.
277-
return defaultType->getAnyNominal() == type->getAnyNominal();
278-
};
279-
280-
if (!isDefaultType(type))
260+
// Check whether the nominal types match. This makes sure that we
261+
// properly handle Array vs. Array<T>.
262+
if (defaultType->getAnyNominal() != type->getAnyNominal()) {
281263
increaseScore(SK_NonDefaultLiteral, locator);
264+
}
282265
}
283266

284267
break;

test/Interop/Cxx/stdlib/Inputs/std-string.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,3 @@ struct HasMethodThatReturnsString {
66
};
77

88
inline std::string takesStringWithDefaultArg(std::string s = "abc") { return s; }
9-
10-
struct StringBox {
11-
std::string value;
12-
13-
friend bool operator==(const StringBox &lhs, const std::string &rhs) {
14-
return lhs.value == rhs;
15-
}
16-
17-
friend bool operator==(const std::string &lhs, const StringBox &rhs) {
18-
return rhs == lhs;
19-
}
20-
};

test/Interop/Cxx/stdlib/custom-expressible-by-string-literal.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)