mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into master-next
This commit is contained in:
@@ -128,7 +128,7 @@ createVarWithPattern(ASTContext &cxt, DeclContext *dc, Identifier name, Type ty,
|
||||
/*IsStatic*/false,
|
||||
/*IsLet*/isLet,
|
||||
/*IsCaptureList*/false,
|
||||
SourceLoc(), name, ty, dc);
|
||||
SourceLoc(), name, dc->mapTypeIntoContext(ty), dc);
|
||||
if (isImplicit)
|
||||
var->setImplicit();
|
||||
var->setInterfaceType(ty);
|
||||
@@ -3167,7 +3167,7 @@ namespace {
|
||||
/*IsStatic*/false, /*IsLet*/ false,
|
||||
/*IsCaptureList*/false,
|
||||
Impl.importSourceLoc(decl->getLocStart()),
|
||||
name, type, dc);
|
||||
name, dc->mapTypeIntoContext(type), dc);
|
||||
result->setInterfaceType(type);
|
||||
|
||||
// If this is a compatibility stub, mark is as such.
|
||||
@@ -3388,7 +3388,7 @@ namespace {
|
||||
/*IsStatic*/ false, /*IsLet*/ false,
|
||||
/*IsCaptureList*/false,
|
||||
Impl.importSourceLoc(decl->getLocation()),
|
||||
name, type, dc);
|
||||
name, dc->mapTypeIntoContext(type), dc);
|
||||
result->setInterfaceType(type);
|
||||
|
||||
// Handle attributes.
|
||||
@@ -3464,7 +3464,7 @@ namespace {
|
||||
/*IsLet*/Impl.shouldImportGlobalAsLet(decl->getType()),
|
||||
/*IsCaptureList*/false,
|
||||
Impl.importSourceLoc(decl->getLocation()),
|
||||
name, type, dc);
|
||||
name, dc->mapTypeIntoContext(type), dc);
|
||||
result->setInterfaceType(type);
|
||||
|
||||
// If imported as member, the member should be final.
|
||||
@@ -4324,7 +4324,6 @@ namespace {
|
||||
isInSystemModule(dc),
|
||||
/*isFullyBridgeable*/false);
|
||||
if (superclassType) {
|
||||
superclassType = result->mapTypeOutOfContext(superclassType);
|
||||
assert(superclassType->is<ClassType>() ||
|
||||
superclassType->is<BoundGenericClassType>());
|
||||
inheritedTypes.push_back(TypeLoc::withoutLoc(superclassType));
|
||||
@@ -4539,8 +4538,8 @@ namespace {
|
||||
getOverridableAccessibility(dc),
|
||||
/*IsStatic*/decl->isClassProperty(), /*IsLet*/false,
|
||||
/*IsCaptureList*/false, Impl.importSourceLoc(decl->getLocation()),
|
||||
name, type, dc);
|
||||
result->setInterfaceType(dc->mapTypeOutOfContext(type));
|
||||
name, dc->mapTypeIntoContext(type), dc);
|
||||
result->setInterfaceType(type);
|
||||
|
||||
// Turn this into a computed property.
|
||||
// FIXME: Fake locations for '{' and '}'?
|
||||
@@ -4930,6 +4929,7 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
|
||||
auto storedUnderlyingType = Impl.importType(
|
||||
decl->getUnderlyingType(), ImportTypeKind::Value, isInSystemModule(dc),
|
||||
decl->getUnderlyingType()->isBlockPointerType(), OTK_None);
|
||||
|
||||
if (auto objTy = storedUnderlyingType->getAnyOptionalObjectType())
|
||||
storedUnderlyingType = objTy;
|
||||
|
||||
@@ -5288,16 +5288,30 @@ Decl *SwiftDeclConverter::importGlobalAsMethod(
|
||||
auto &C = Impl.SwiftContext;
|
||||
SmallVector<ParameterList *, 2> bodyParams;
|
||||
|
||||
// There is an inout 'self' when we have an instance method of a
|
||||
// value-semantic type whose 'self' parameter is a
|
||||
// pointer-to-non-const.
|
||||
// There is an inout 'self' when the parameter is a pointer to a non-const
|
||||
// instance of the type we're importing onto. Importing this as a method means
|
||||
// that the method should be treated as mutating in this situation.
|
||||
bool selfIsInOut = false;
|
||||
if (selfIdx && !dc->getDeclaredTypeOfContext()->hasReferenceSemantics()) {
|
||||
auto selfParam = decl->getParamDecl(*selfIdx);
|
||||
auto selfParamTy = selfParam->getType();
|
||||
if ((selfParamTy->isPointerType() || selfParamTy->isReferenceType()) &&
|
||||
!selfParamTy->getPointeeType().isConstQualified())
|
||||
!selfParamTy->getPointeeType().isConstQualified()) {
|
||||
selfIsInOut = true;
|
||||
|
||||
// If there's a swift_newtype, check the levels of indirection: self is
|
||||
// only inout if this is a pointer to the typedef type (which itself is a
|
||||
// pointer).
|
||||
if (auto nominalTypeDecl =
|
||||
dc->getAsNominalTypeOrNominalTypeExtensionContext()) {
|
||||
if (auto clangDCTy = dyn_cast_or_null<clang::TypedefNameDecl>(
|
||||
nominalTypeDecl->getClangDecl()))
|
||||
if (auto newtypeAttr = getSwiftNewtypeAttr(clangDCTy, getVersion()))
|
||||
if (clangDCTy->getUnderlyingType().getCanonicalType() !=
|
||||
selfParamTy->getPointeeType().getCanonicalType())
|
||||
selfIsInOut = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bodyParams.push_back(ParameterList::createWithoutLoc(ParamDecl::createSelf(
|
||||
@@ -5474,7 +5488,8 @@ SwiftDeclConverter::getImplicitProperty(ImportedName importedName,
|
||||
|
||||
auto property = Impl.createDeclWithClangNode<VarDecl>(
|
||||
getter, Accessibility::Public, /*IsStatic*/isStatic, /*isLet*/false,
|
||||
/*IsCaptureList*/false, SourceLoc(), propertyName, swiftPropertyType, dc);
|
||||
/*IsCaptureList*/false, SourceLoc(), propertyName,
|
||||
dc->mapTypeIntoContext(swiftPropertyType), dc);
|
||||
property->setInterfaceType(swiftPropertyType);
|
||||
|
||||
// Note that we've formed this property.
|
||||
@@ -7001,6 +7016,41 @@ void ClangImporter::Implementation::importAttributes(
|
||||
PlatformAgnostic, /*Implicit=*/false);
|
||||
|
||||
MappedDecl->getAttrs().add(AvAttr);
|
||||
|
||||
// For enum cases introduced in the 2017 SDKs, add
|
||||
// @_downgrade_exhaustivity_check in Swift 3.
|
||||
if (C.LangOpts.isSwiftVersion3() && isa<EnumElementDecl>(MappedDecl)) {
|
||||
bool downgradeExhaustivity = false;
|
||||
switch (*platformK) {
|
||||
case PlatformKind::OSX:
|
||||
case PlatformKind::OSXApplicationExtension:
|
||||
downgradeExhaustivity = (introduced.getMajor() == 10 &&
|
||||
introduced.getMinor() &&
|
||||
*introduced.getMinor() == 13);
|
||||
break;
|
||||
|
||||
case PlatformKind::iOS:
|
||||
case PlatformKind::iOSApplicationExtension:
|
||||
case PlatformKind::tvOS:
|
||||
case PlatformKind::tvOSApplicationExtension:
|
||||
downgradeExhaustivity = (introduced.getMajor() == 11);
|
||||
break;
|
||||
|
||||
case PlatformKind::watchOS:
|
||||
case PlatformKind::watchOSApplicationExtension:
|
||||
downgradeExhaustivity = (introduced.getMajor() == 4);
|
||||
break;
|
||||
|
||||
case PlatformKind::none:
|
||||
break;
|
||||
}
|
||||
|
||||
if (downgradeExhaustivity) {
|
||||
auto attr =
|
||||
new (C) DowngradeExhaustivityCheckAttr(/*isImplicit=*/true);
|
||||
MappedDecl->getAttrs().add(attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7692,11 +7742,11 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
|
||||
var = createDeclWithClangNode<VarDecl>(ClangN, Accessibility::Public,
|
||||
/*IsStatic*/isStatic, /*IsLet*/false,
|
||||
/*IsCaptureList*/false, SourceLoc(),
|
||||
name, type, dc);
|
||||
name, dc->mapTypeIntoContext(type), dc);
|
||||
} else {
|
||||
var = new (SwiftContext)
|
||||
VarDecl(/*IsStatic*/isStatic, /*IsLet*/false, /*IsCaptureList*/false,
|
||||
SourceLoc(), name, type, dc);
|
||||
SourceLoc(), name, dc->mapTypeIntoContext(type), dc);
|
||||
}
|
||||
|
||||
var->setInterfaceType(type);
|
||||
@@ -7857,8 +7907,9 @@ ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t extra) {
|
||||
for (auto entry : table->lookupGlobalsAsMembers(effectiveClangContext)) {
|
||||
auto decl = entry.get<clang::NamedDecl *>();
|
||||
|
||||
// Only continue members in the same submodule as this extension.
|
||||
if (decl->getImportedOwningModule() != submodule) continue;
|
||||
// Only include members in the same submodule as this extension.
|
||||
if (getClangSubmoduleForDecl(decl) != submodule)
|
||||
continue;
|
||||
|
||||
forEachDistinctName(decl, [&](ImportedName newName,
|
||||
ImportNameVersion nameVersion) {
|
||||
@@ -7870,8 +7921,18 @@ ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t extra) {
|
||||
|
||||
// Then try to import the decl under the specified name.
|
||||
auto *member = importDecl(decl, nameVersion);
|
||||
if (!member || member->getDeclContext() != ext)
|
||||
return;
|
||||
if (!member) return;
|
||||
|
||||
// Find the member that will land in an extension context.
|
||||
while (!isa<ExtensionDecl>(member->getDeclContext())) {
|
||||
auto nominal = dyn_cast<NominalTypeDecl>(member->getDeclContext());
|
||||
if (!nominal) return;
|
||||
|
||||
member = nominal;
|
||||
if (member->hasClangNode()) return;
|
||||
}
|
||||
|
||||
if (member->getDeclContext() != ext) return;
|
||||
ext->addMember(member);
|
||||
|
||||
for (auto alternate : getAlternateDecls(member)) {
|
||||
|
||||
Reference in New Issue
Block a user