diff --git a/include/swift/AST/KnownIdentifiers.def b/include/swift/AST/KnownIdentifiers.def index 02ef359f568e3..2b0b4a7d11c7f 100644 --- a/include/swift/AST/KnownIdentifiers.def +++ b/include/swift/AST/KnownIdentifiers.def @@ -35,7 +35,6 @@ IDENTIFIER(Any) IDENTIFIER(ArrayLiteralElement) IDENTIFIER(asLocalActor) IDENTIFIER(atIndexedSubscript) -IDENTIFIER(basic_string) IDENTIFIER_(bridgeToObjectiveC) IDENTIFIER(buildArray) IDENTIFIER(buildBlock) diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index d3ebaa77a243d..854c34391cc5d 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -1110,9 +1110,6 @@ class alignas(1 << TypeAlignInBits) TypeBase /// Check if this is a ObjCBool type from the Objective-C module. bool isObjCBool(); - /// Check if this is a std.string type from C++. - bool isCxxString(); - /// Check if this is the type Unicode.Scalar from the Swift standard library. bool isUnicodeScalar(); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index a9bc44a7abe6c..fc0f07c2643c7 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -43,7 +43,6 @@ #include "swift/AST/Types.h" #include "swift/Basic/Assertions.h" #include "swift/Basic/Compiler.h" -#include "clang/AST/DeclCXX.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" @@ -1303,21 +1302,6 @@ bool TypeBase::isObjCBool() { return module->getName().is("ObjectiveC") && NTD->getName().is("ObjCBool"); } -bool TypeBase::isCxxString() { - auto *nominal = getAnyNominal(); - if (!nominal) - return false; - - auto *clangDecl = - dyn_cast_or_null(nominal->getClangDecl()); - if (!clangDecl) - return false; - - auto &ctx = nominal->getASTContext(); - return clangDecl->isInStdNamespace() && clangDecl->getIdentifier() && - ctx.Id_basic_string.is(clangDecl->getName()); -} - bool TypeBase::isUnicodeScalar() { if (!is()) return false; diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 0cc585646950d..510e94b332c50 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -257,28 +257,11 @@ void ConstraintSystem::assignFixedType(TypeVariableType *typeVar, Type type, // If the protocol has a default type, check it. if (auto defaultType = TypeChecker::getDefaultType(literalProtocol, DC)) { - auto isDefaultType = [&literalProtocol, &defaultType](Type type) { - // Treat `std.string` as a default type just like we do - // Swift standard library `String`. This helps to disambiguate - // operator overloads that use `std.string` vs. a custom C++ - // type that conforms to `ExpressibleByStringLiteral` as well. - // - // This doesn't clash with String because inference won't attempt - // C++ types unless we discover them from a constraint and the - // optimizer and old hacks always prefer the actual default type. - if (literalProtocol->getKnownProtocolKind() == - KnownProtocolKind::ExpressibleByStringLiteral && - type->isCxxString()) { - return true; - } - - // Check whether the nominal types match. This makes sure that we - // properly handle Array vs. Array. - return defaultType->getAnyNominal() == type->getAnyNominal(); - }; - - if (!isDefaultType(type)) + // Check whether the nominal types match. This makes sure that we + // properly handle Array vs. Array. + if (defaultType->getAnyNominal() != type->getAnyNominal()) { increaseScore(SK_NonDefaultLiteral, locator); + } } break; diff --git a/test/Interop/Cxx/stdlib/Inputs/std-string.h b/test/Interop/Cxx/stdlib/Inputs/std-string.h index 68423dbd70cf9..62de38a035e83 100644 --- a/test/Interop/Cxx/stdlib/Inputs/std-string.h +++ b/test/Interop/Cxx/stdlib/Inputs/std-string.h @@ -6,15 +6,3 @@ struct HasMethodThatReturnsString { }; inline std::string takesStringWithDefaultArg(std::string s = "abc") { return s; } - -struct StringBox { - std::string value; - - friend bool operator==(const StringBox &lhs, const std::string &rhs) { - return lhs.value == rhs; - } - - friend bool operator==(const std::string &lhs, const StringBox &rhs) { - return rhs == lhs; - } -}; diff --git a/test/Interop/Cxx/stdlib/custom-expressible-by-string-literal.swift b/test/Interop/Cxx/stdlib/custom-expressible-by-string-literal.swift deleted file mode 100644 index 2de6173b1e8fa..0000000000000 --- a/test/Interop/Cxx/stdlib/custom-expressible-by-string-literal.swift +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: %target-swift-emit-silgen -verify -I %S/Inputs -cxx-interoperability-mode=upcoming-swift %s | %FileCheck %s - -import CxxStdlib -import StdString - -extension StringBox: @retroactive ExpressibleByStringLiteral { - public init(stringLiteral value: String) { - self.value = std.string(value) - } -} - -// CHECK-LABEL: sil hidden [ossa] @$s4main4testyyF -// CHECK: // function_ref static std{{.*}}basic_string, std{{.*}}allocator>.== infix(_:_:) -// CHECK: // function_ref static std{{.*}}basic_string, std{{.*}}allocator>.== infix(_:_:) -// CHECK: // function_ref static String.== infix(_:_:) -// CHECK: } // end sil function '$s4main4testyyF' -func test() { - let cxxString: std.string = "" - let _ = cxxString == "def" // Ok - let _ = "def" == cxxString // Ok - let _ = "def" == "hello" // Ok -}