mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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"
This commit is contained in:
@@ -35,7 +35,6 @@ IDENTIFIER(Any)
|
||||
IDENTIFIER(ArrayLiteralElement)
|
||||
IDENTIFIER(asLocalActor)
|
||||
IDENTIFIER(atIndexedSubscript)
|
||||
IDENTIFIER(basic_string)
|
||||
IDENTIFIER_(bridgeToObjectiveC)
|
||||
IDENTIFIER(buildArray)
|
||||
IDENTIFIER(buildBlock)
|
||||
|
||||
@@ -1112,9 +1112,6 @@ public:
|
||||
/// 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();
|
||||
|
||||
|
||||
@@ -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<clang::CXXRecordDecl>(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<StructType>())
|
||||
return false;
|
||||
|
||||
@@ -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<T>.
|
||||
return defaultType->getAnyNominal() == type->getAnyNominal();
|
||||
};
|
||||
|
||||
if (!isDefaultType(type))
|
||||
// Check whether the nominal types match. This makes sure that we
|
||||
// properly handle Array vs. Array<T>.
|
||||
if (defaultType->getAnyNominal() != type->getAnyNominal()) {
|
||||
increaseScore(SK_NonDefaultLiteral, locator);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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<CChar, std{{.*}}char_traits<CChar>, std{{.*}}allocator<CChar>>.== infix(_:_:)
|
||||
// CHECK: // function_ref static std{{.*}}basic_string<CChar, std{{.*}}char_traits<CChar>, std{{.*}}allocator<CChar>>.== 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
|
||||
}
|
||||
Reference in New Issue
Block a user