Skip to content

Commit 1992afe

Browse files
authored
Merge pull request #1656 from swiftwasm/release/5.3
[pull] swiftwasm-release/5.3 from release/5.3
2 parents 6064836 + 3c81a68 commit 1992afe

13 files changed

+117
-58
lines changed

cmake/modules/SwiftWindowsSupport.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ macro(swift_swap_compiler_if_needed target)
9696
set(CMAKE_C_COMPILER ${CLANG_LOCATION}/clang${CMAKE_EXECUTABLE_SUFFIX})
9797
set(CMAKE_CXX_COMPILER ${CLANG_LOCATION}/clang++${CMAKE_EXECUTABLE_SUFFIX})
9898
endif()
99+
100+
# Add a workaround for older clang-cl with a newer MSVC runtime. MSVC
101+
# 16.27 ships with a C++ compiler that enables conditional explicit from
102+
# C++20 unconditionally. Newer clang supports this, but the 5.3 release
103+
# branch clang does not. Add a workaround.
104+
add_compile_definitions($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:_HAS_CONDITIONAL_EXPLICIT=0>)
99105
else()
100106
message(SEND_ERROR "${target} requires a clang based compiler")
101107
endif()

lib/AST/ASTDemangler.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,16 @@ createSubstitutionMapFromGenericArgs(GenericSignature genericSig,
200200
if (!genericSig)
201201
return SubstitutionMap();
202202

203-
SmallVector<GenericTypeParamType *, 4> genericParams;
204-
genericSig->forEachParam([&](GenericTypeParamType *gp, bool canonical) {
205-
if (canonical)
206-
genericParams.push_back(gp);
207-
});
208-
if (genericParams.size() != args.size())
203+
if (genericSig->getGenericParams().size() != args.size())
209204
return SubstitutionMap();
210205

211206
return SubstitutionMap::get(
212207
genericSig,
213208
[&](SubstitutableType *t) -> Type {
214-
for (unsigned i = 0, e = genericParams.size(); i < e; ++i) {
215-
if (t->isEqual(genericParams[i]))
216-
return args[i];
217-
}
209+
auto *gp = cast<GenericTypeParamType>(t);
210+
unsigned ordinal = genericSig->getGenericParamOrdinal(gp);
211+
if (ordinal < args.size())
212+
return args[ordinal];
218213
return Type();
219214
},
220215
LookUpConformanceInModule(moduleDecl));

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5703,7 +5703,7 @@ Expr *ExprRewriter::coerceCallArguments(
57035703
SmallVector<LocatorPathElt, 4> path;
57045704
auto anchor = locator.getLocatorParts(path);
57055705
if (!path.empty() && path.back().is<LocatorPathElt::ApplyArgument>() &&
5706-
(isa<CallExpr>(anchor) || isa<SubscriptExpr>(anchor))) {
5706+
!isa<UnresolvedDotExpr>(anchor)) {
57075707
auto locatorPtr = cs.getConstraintLocator(locator);
57085708
assert(solution.trailingClosureMatchingChoices.count(locatorPtr) == 1);
57095709
trailingClosureMatching = solution.trailingClosureMatchingChoices.find(

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,9 +1831,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
18311831
if (auto rawTy = ED->getRawType()) {
18321832
// The raw type must be one of the blessed literal convertible types.
18331833
if (!computeAutomaticEnumValueKind(ED)) {
1834-
DE.diagnose(ED->getInherited().front().getSourceRange().Start,
1835-
diag::raw_type_not_literal_convertible, rawTy);
1836-
ED->getInherited().front().setInvalidType(getASTContext());
1834+
if (!rawTy->is<ErrorType>()) {
1835+
DE.diagnose(ED->getInherited().front().getSourceRange().Start,
1836+
diag::raw_type_not_literal_convertible, rawTy);
1837+
ED->getInherited().front().setInvalidType(getASTContext());
1838+
}
18371839
}
18381840

18391841
// We need at least one case to have a raw value.

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,16 @@ LookupResult TypeChecker::lookupMember(DeclContext *dc,
357357
return result;
358358
}
359359

360-
bool TypeChecker::isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl) {
360+
TypeChecker::UnsupportedMemberTypeAccessKind
361+
TypeChecker::isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl) {
361362
// We don't allow lookups of a non-generic typealias of an unbound
362363
// generic type, because we have no way to model such a type in the
363364
// AST.
364365
//
365366
// For generic typealiases, the typealias itself has an unbound
366367
// generic form whose parent type can be another unbound generic
367368
// type.
368-
//
369-
// FIXME: Could lift this restriction once we have sugared
370-
// "member types".
371-
if (type->is<UnboundGenericType>()) {
369+
if (type->hasUnboundGenericType()) {
372370
// Generic typealiases can be accessed with an unbound generic
373371
// base, since we represent the member type as an unbound generic
374372
// type.
@@ -379,12 +377,12 @@ bool TypeChecker::isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl) {
379377
if (!aliasDecl->isGeneric() &&
380378
aliasDecl->getUnderlyingType()->getCanonicalType()
381379
->hasTypeParameter()) {
382-
return true;
380+
return UnsupportedMemberTypeAccessKind::TypeAliasOfUnboundGeneric;
383381
}
384382
}
385383

386384
if (isa<AssociatedTypeDecl>(typeDecl))
387-
return true;
385+
return UnsupportedMemberTypeAccessKind::AssociatedTypeOfUnboundGeneric;
388386
}
389387

390388
if (type->isExistentialType() &&
@@ -394,15 +392,13 @@ bool TypeChecker::isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl) {
394392
if (auto *aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
395393
if (aliasDecl->getUnderlyingType()->getCanonicalType()
396394
->hasTypeParameter())
397-
return true;
398-
} else {
399-
// Don't allow lookups of other nested types of an existential type,
400-
// because there is no way to represent such types.
401-
return true;
395+
return UnsupportedMemberTypeAccessKind::TypeAliasOfExistential;
396+
} else if (isa<AssociatedTypeDecl>(typeDecl)) {
397+
return UnsupportedMemberTypeAccessKind::AssociatedTypeOfExistential;
402398
}
403399
}
404400

405-
return false;
401+
return UnsupportedMemberTypeAccessKind::None;
406402
}
407403

408404
LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
@@ -441,7 +437,8 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
441437
continue;
442438
}
443439

444-
if (isUnsupportedMemberTypeAccess(type, typeDecl)) {
440+
if (isUnsupportedMemberTypeAccess(type, typeDecl)
441+
!= TypeChecker::UnsupportedMemberTypeAccessKind::None) {
445442
auto memberType = typeDecl->getDeclaredInterfaceType();
446443

447444
// Add the type to the result set, so that we can diagnose the

lib/Sema/TypeCheckType.cpp

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -961,21 +961,32 @@ Type TypeChecker::applyUnboundGenericArguments(
961961

962962
/// Diagnose a use of an unbound generic type.
963963
static void diagnoseUnboundGenericType(Type ty, SourceLoc loc) {
964-
auto unbound = ty->castTo<UnboundGenericType>();
965-
{
966-
auto &ctx = ty->getASTContext();
967-
InFlightDiagnostic diag = ctx.Diags.diagnose(loc,
968-
diag::generic_type_requires_arguments, ty);
969-
if (auto *genericD = unbound->getDecl()) {
964+
auto &ctx = ty->getASTContext();
965+
if (auto unbound = ty->getAs<UnboundGenericType>()) {
966+
auto *decl = unbound->getDecl();
967+
{
968+
InFlightDiagnostic diag = ctx.Diags.diagnose(loc,
969+
diag::generic_type_requires_arguments, ty);
970970
SmallString<64> genericArgsToAdd;
971971
if (TypeChecker::getDefaultGenericArgumentsString(genericArgsToAdd,
972-
genericD))
972+
decl))
973973
diag.fixItInsertAfter(loc, genericArgsToAdd);
974974
}
975+
976+
decl->diagnose(diag::kind_declname_declared_here,
977+
DescriptiveDeclKind::GenericType,
978+
decl->getName());
979+
} else {
980+
ty.findIf([&](Type t) -> bool {
981+
if (auto unbound = t->getAs<UnboundGenericType>()) {
982+
ctx.Diags.diagnose(loc,
983+
diag::generic_type_requires_arguments, t);
984+
return true;
985+
}
986+
987+
return false;
988+
});
975989
}
976-
unbound->getDecl()->diagnose(diag::kind_declname_declared_here,
977-
DescriptiveDeclKind::GenericType,
978-
unbound->getDecl()->getName());
979990
}
980991

981992
// Produce a diagnostic if the type we referenced was an
@@ -1442,22 +1453,29 @@ static Type resolveNestedIdentTypeComponent(
14421453

14431454
auto maybeDiagnoseBadMemberType = [&](TypeDecl *member, Type memberType,
14441455
AssociatedTypeDecl *inferredAssocType) {
1445-
// Diagnose invalid cases.
1446-
if (TypeChecker::isUnsupportedMemberTypeAccess(parentTy, member)) {
1447-
if (!options.contains(TypeResolutionFlags::SilenceErrors)) {
1448-
if (parentTy->is<UnboundGenericType>())
1449-
diagnoseUnboundGenericType(parentTy, parentRange.End);
1450-
else if (parentTy->isExistentialType() &&
1451-
isa<AssociatedTypeDecl>(member)) {
1452-
diags.diagnose(comp->getNameLoc(), diag::assoc_type_outside_of_protocol,
1453-
comp->getNameRef());
1454-
} else if (parentTy->isExistentialType() &&
1455-
isa<TypeAliasDecl>(member)) {
1456-
diags.diagnose(comp->getNameLoc(), diag::typealias_outside_of_protocol,
1457-
comp->getNameRef());
1458-
}
1459-
}
1456+
if (options.contains(TypeResolutionFlags::SilenceErrors)) {
1457+
if (TypeChecker::isUnsupportedMemberTypeAccess(parentTy, member)
1458+
!= TypeChecker::UnsupportedMemberTypeAccessKind::None)
1459+
return ErrorType::get(ctx);
1460+
}
1461+
1462+
switch (TypeChecker::isUnsupportedMemberTypeAccess(parentTy, member)) {
1463+
case TypeChecker::UnsupportedMemberTypeAccessKind::None:
1464+
break;
1465+
1466+
case TypeChecker::UnsupportedMemberTypeAccessKind::TypeAliasOfUnboundGeneric:
1467+
case TypeChecker::UnsupportedMemberTypeAccessKind::AssociatedTypeOfUnboundGeneric:
1468+
diagnoseUnboundGenericType(parentTy, parentRange.End);
1469+
return ErrorType::get(ctx);
1470+
1471+
case TypeChecker::UnsupportedMemberTypeAccessKind::TypeAliasOfExistential:
1472+
diags.diagnose(comp->getNameLoc(), diag::typealias_outside_of_protocol,
1473+
comp->getNameRef());
1474+
return ErrorType::get(ctx);
14601475

1476+
case TypeChecker::UnsupportedMemberTypeAccessKind::AssociatedTypeOfExistential:
1477+
diags.diagnose(comp->getNameLoc(), diag::assoc_type_outside_of_protocol,
1478+
comp->getNameRef());
14611479
return ErrorType::get(ctx);
14621480
}
14631481

lib/Sema/TypeChecker.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,18 @@ class LookUpConformance {
10881088
PrecedenceGroupDecl *lookupPrecedenceGroup(DeclContext *dc, Identifier name,
10891089
SourceLoc nameLoc);
10901090

1091+
enum class UnsupportedMemberTypeAccessKind : uint8_t {
1092+
None,
1093+
TypeAliasOfUnboundGeneric,
1094+
TypeAliasOfExistential,
1095+
AssociatedTypeOfUnboundGeneric,
1096+
AssociatedTypeOfExistential
1097+
};
1098+
10911099
/// Check whether the given declaration can be written as a
10921100
/// member of the given base type.
1093-
bool isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl);
1101+
UnsupportedMemberTypeAccessKind
1102+
isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl);
10941103

10951104
/// @}
10961105

stdlib/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ else()
5555
add_compile_options(-fno-sanitize=all)
5656
endif()
5757

58+
# Add a workaround for older clang-cl with a newer MSVC runtime. MSVC 16.27
59+
# ships with a C++ compiler that enables conditional explicit from C++20
60+
# unconditionally. Newer clang supports this, but the 5.3 release branch clang
61+
# does not. Add a workaround.
62+
add_compile_definitions($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:_HAS_CONDITIONAL_EXPLICIT=0>)
63+
5864
# Do not enforce checks for LLVM's ABI-breaking build settings.
5965
# The Swift runtime uses some header-only code from LLVM's ADT classes,
6066
# but we do not want to link libSupport into the runtime. These checks rely

test/Generics/unbound.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,20 @@ struct X1<T> {
7474
func bar<U>() where T: X2<U> {}
7575
}
7676
class X2<T> {}
77+
78+
// <rdar://problem/67292528> missing check for unbound parent type
79+
struct Outer<K, V> {
80+
struct Inner {}
81+
82+
struct Middle {
83+
typealias Inner = Outer<K, V>.Middle
84+
}
85+
}
86+
87+
func makeInner() -> Outer<String, String>.Middle.Inner {
88+
return .init()
89+
}
90+
91+
var innerProperty: Outer.Middle.Inner = makeInner()
92+
// expected-error@-1 {{reference to generic type 'Outer' requires arguments in <...>}}
93+

test/IDE/print_ast_tc_decls_errors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ class ClassWithInheritance9 : FooClass, BarClass, FooProtocol, BarProtocol, FooN
109109
//===--- Inheritance list in enums.
110110
//===---
111111

112-
enum EnumWithInheritance1 : FooNonExistentProtocol {} // expected-error {{cannot find type 'FooNonExistentProtocol' in scope}} expected-error {{raw type}} expected-error {{an enum with no cases}}
112+
enum EnumWithInheritance1 : FooNonExistentProtocol {} // expected-error {{cannot find type 'FooNonExistentProtocol' in scope}} expected-error {{an enum with no cases}}
113113
// NO-TYREPR: {{^}}enum EnumWithInheritance1 : <<error type>> {{{$}}
114114
// TYREPR: {{^}}enum EnumWithInheritance1 : FooNonExistentProtocol {{{$}}
115115

116-
enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {} // expected-error {{cannot find type 'FooNonExistentProtocol' in scope}} expected-error {{cannot find type 'BarNonExistentProtocol' in scope}} expected-error {{raw type}} expected-error {{an enum with no cases}}
116+
enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {} // expected-error {{cannot find type 'FooNonExistentProtocol' in scope}} expected-error {{cannot find type 'BarNonExistentProtocol' in scope}} expected-error {{an enum with no cases}}
117117
// NO-TYREPR: {{^}}enum EnumWithInheritance2 : <<error type>>, <<error type>> {{{$}}
118118
// TYREPR: {{^}}enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {{{$}}
119119

0 commit comments

Comments
 (0)