diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index da779db7a8cb2..8577b4dfedc57 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -7891,7 +7891,7 @@ ERROR(expected_macro_expansion_expr,PointsToFirstBadToken, ERROR(expected_macro_expansion_decls,PointsToFirstBadToken, "expected macro expansion to produce a declaration", ()) ERROR(macro_undefined,PointsToFirstBadToken, - "no macro named %0", (Identifier)) + "no macro named %0", (DeclName)) ERROR(external_macro_not_found,none, "external macro implementation type '%0.%1' could not be found for " "macro %2; %3", (StringRef, StringRef, DeclName, StringRef)) diff --git a/include/swift/AST/ProtocolConformanceRef.h b/include/swift/AST/ProtocolConformanceRef.h index 03e4ab4263af7..23ef80300d042 100644 --- a/include/swift/AST/ProtocolConformanceRef.h +++ b/include/swift/AST/ProtocolConformanceRef.h @@ -140,6 +140,7 @@ class ProtocolConformanceRef { } AbstractConformance *getAbstract() const { + ASSERT(isAbstract()); return Union.get(); } diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 91fcb097f4847..4697e46432196 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -520,7 +520,7 @@ struct ASTContext::Implementation { llvm::DenseMap OriginalBodySourceRanges; /// Macro discriminators per context. - llvm::DenseMap, unsigned> + llvm::DenseMap, unsigned> NextMacroDiscriminator; /// Local and closure discriminators per context. @@ -2286,8 +2286,8 @@ unsigned ASTContext::getNextMacroDiscriminator( MacroDiscriminatorContext context, DeclBaseName baseName ) { - std::pair key( - context.getOpaqueValue(), baseName.getIdentifier()); + std::pair key( + context.getOpaqueValue(), baseName); return getImpl().NextMacroDiscriminator[key]++; } diff --git a/lib/AST/ASTDemangler.cpp b/lib/AST/ASTDemangler.cpp index 9f9ce69996aa0..9e287f59628c2 100644 --- a/lib/AST/ASTDemangler.cpp +++ b/lib/AST/ASTDemangler.cpp @@ -767,8 +767,8 @@ Type ASTBuilder::createExistentialMetatypeType( Type ASTBuilder::createConstrainedExistentialType( Type base, ArrayRef constraints, ArrayRef inverseRequirements) { - llvm::SmallDenseMap primaryAssociatedTypes; - llvm::SmallDenseSet claimed; + llvm::SmallDenseMap primaryAssociatedTypes; + llvm::SmallDenseSet claimed; for (const auto &req : constraints) { switch (req.getKind()) { @@ -782,7 +782,7 @@ Type ASTBuilder::createConstrainedExistentialType( if (auto *memberTy = req.getFirstType()->getAs()) { if (memberTy->getBase()->is()) { // This is the only case we understand so far. - primaryAssociatedTypes[memberTy->getName()] = req.getSecondType(); + primaryAssociatedTypes[memberTy->getAssocType()] = req.getSecondType(); continue; } } @@ -799,7 +799,7 @@ Type ASTBuilder::createConstrainedExistentialType( llvm::SmallVector args; for (auto *assocTy : proto->getPrimaryAssociatedTypes()) { - auto found = primaryAssociatedTypes.find(assocTy->getName()); + auto found = primaryAssociatedTypes.find(assocTy); if (found == primaryAssociatedTypes.end()) return protoTy; args.push_back(found->second); diff --git a/lib/Parse/Lexer.cpp b/lib/Parse/Lexer.cpp index a1e3b467e2f9a..04d3309757978 100644 --- a/lib/Parse/Lexer.cpp +++ b/lib/Parse/Lexer.cpp @@ -660,8 +660,8 @@ static bool advanceIfValidContinuationOfOperator(char const *&ptr, /// Returns true if the given string is entirely whitespace (considering only /// those whitespace code points permitted in raw identifiers). -static bool isEntirelyWhitespace(StringRef string) { - if (string.empty()) return false; +static bool isEscapedIdentifierEntirelyWhitespace(StringRef string) { + if (string.empty()) return true; char const *p = string.data(), *end = string.end(); if (!advanceIf(p, end, isPermittedRawIdentifierWhitespace)) return false; @@ -703,7 +703,7 @@ bool Lexer::isValidAsEscapedIdentifier(StringRef string) { ; if (p != end) return false; - return !isEntirelyWhitespace(string); + return !isEscapedIdentifierEntirelyWhitespace(string); } /// Determines if the given string is a valid operator identifier, @@ -2315,7 +2315,8 @@ void Lexer::lexEscapedIdentifier() { // If we have the terminating "`", it's an escaped/raw identifier, unless it // contained only operator characters or was entirely whitespace. StringRef IdStr(IdentifierStart, CurPtr - IdentifierStart); - if (*CurPtr == '`' && !isOperator(IdStr) && !isEntirelyWhitespace(IdStr)) { + if (*CurPtr == '`' && !isOperator(IdStr) && + !isEscapedIdentifierEntirelyWhitespace(IdStr)) { ++CurPtr; formEscapedIdentifierToken(Quote); return; diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 6b0ffdac82f14..315aa2652b281 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -503,6 +503,9 @@ ParserResult Parser::parseExprSequenceElement(Diag<> message, peekToken().isContextualPunctuator("~")) && !peekToken().isAtStartOfLine()) { ParserResult ty = parseType(); + if (ty.isNull()) + return nullptr; + auto *typeExpr = new (Context) TypeExpr(ty.get()); return makeParserResult(typeExpr); } diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index 69f17ad3dacc7..a9fdcfcf4d2f7 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -4068,8 +4068,8 @@ namespace { } /// Lookup all macros with the given macro name. - SmallVector lookupMacros(Identifier moduleName, - Identifier macroName, + SmallVector lookupMacros(DeclName moduleName, + DeclName macroName, FunctionRefInfo functionRefInfo, MacroRoles roles) { SmallVector choices; @@ -4100,8 +4100,8 @@ namespace { CS.associateArgumentList(locator, expr->getArgs()); // Look up the macros with this name. - auto moduleIdent = expr->getModuleName().getBaseIdentifier(); - auto macroIdent = expr->getMacroName().getBaseIdentifier(); + auto moduleIdent = expr->getModuleName().getBaseName(); + auto macroIdent = expr->getMacroName().getBaseName(); FunctionRefInfo functionRefInfo = FunctionRefInfo::singleBaseNameApply(); auto macros = lookupMacros(moduleIdent, macroIdent, functionRefInfo, expr->getMacroRoles()); diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 0bf0bbc04d54f..544022084e962 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -7308,8 +7308,11 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind, // would be handled by existental promotion in cases where it's allowed. if (isTupleWithUnresolvedPackExpansion(origType1) || isTupleWithUnresolvedPackExpansion(origType2)) { - if (desugar1->is() != desugar2->is() && - (!desugar1->isAny() && !desugar2->isAny())) { + if (isa(desugar1) != isa(desugar2) && + !isa(desugar1) && + !isa(desugar2) && + !desugar1->isAny() && + !desugar2->isAny()) { return matchTypes( desugar1->is() ? type1 : TupleType::get({type1}, getASTContext()), diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 0089ccc9da1a1..2b4614391810e 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -2248,13 +2248,20 @@ ParamSpecifierRequest::evaluate(Evaluator &evaluator, auto typeRepr = param->getTypeRepr(); - if (!typeRepr && !param->isImplicit()) { - // Untyped closure parameter. - return ParamSpecifier::Default; - } + if (!typeRepr) { + if (!param->isImplicit()) { + // Untyped closure parameter. + return ParamSpecifier::Default; + } - assert(typeRepr != nullptr && "Should call setSpecifier() on " - "synthesized parameter declarations"); + if (param->isInvalid()) { + // Invalid parse. + return ParamSpecifier::Default; + } + + ASSERT(false && "Should call setSpecifier() on " + "synthesized parameter declarations"); + } // Look through top-level pack expansions. These specifiers are // part of what's repeated. diff --git a/lib/Sema/TypeCheckEffects.cpp b/lib/Sema/TypeCheckEffects.cpp index 938d9a05e37c6..07a1110f70084 100644 --- a/lib/Sema/TypeCheckEffects.cpp +++ b/lib/Sema/TypeCheckEffects.cpp @@ -1684,6 +1684,8 @@ class ApplyClassifier { const bool hasAnyConformances = llvm::any_of(substitutions.getConformances(), [](const ProtocolConformanceRef conformance) { + if (conformance.isInvalid()) + return false; auto *requirement = conformance.getProtocol(); return !requirement->getInvertibleProtocolKind(); }); diff --git a/lib/Sema/TypeCheckNameLookup.cpp b/lib/Sema/TypeCheckNameLookup.cpp index ae29222013ed4..5cf17e4994384 100644 --- a/lib/Sema/TypeCheckNameLookup.cpp +++ b/lib/Sema/TypeCheckNameLookup.cpp @@ -266,7 +266,7 @@ convertToUnqualifiedLookupOptions(NameLookupOptions options) { static void synthesizeCodingKeysIfNeededForUnqualifiedLookup(ASTContext &ctx, DeclContext *dc, DeclNameRef name) { - if (name.getBaseIdentifier() != ctx.Id_CodingKeys) + if (!name.isSimpleName(ctx.Id_CodingKeys)) return; for (auto typeCtx = dc->getInnermostTypeContext(); typeCtx != nullptr; diff --git a/lib/Sema/TypeCheckPattern.cpp b/lib/Sema/TypeCheckPattern.cpp index be0d57fc247e4..68fed74e6087a 100644 --- a/lib/Sema/TypeCheckPattern.cpp +++ b/lib/Sema/TypeCheckPattern.cpp @@ -221,6 +221,11 @@ static DeclRefTypeRepr *translateExprToDeclRefTypeRepr(Expr *E, ASTContext &C) { } DeclRefTypeRepr *visitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *udre) { + if (!udre->getName().isSimpleName() || + udre->getName().isOperator() || + udre->getName().isSpecial()) + return nullptr; + return UnqualifiedIdentTypeRepr::create(C, udre->getNameLoc(), udre->getName()); } diff --git a/test/DebugInfo/parameterized_existential_composition.swift b/test/DebugInfo/parameterized_existential_composition.swift index 89b448be390b5..4d884772f5f38 100644 --- a/test/DebugInfo/parameterized_existential_composition.swift +++ b/test/DebugInfo/parameterized_existential_composition.swift @@ -1,10 +1,17 @@ // RUN: %target-swift-frontend -emit-ir %s -g -target %target-swift-5.9-abi-triple +// Note: The goal of this test is to exercise the mangling/demangling via +// the -g flag. + public protocol P { associatedtype A associatedtype B } +public protocol P1 { + associatedtype A +} + public protocol Q { associatedtype C } @@ -31,6 +38,30 @@ public func foo(_ a: (any P & Q & R).Type) {} public func foo(_ a: (any P & Q & R & C).Type) {} public func foo(_ a: (any P & Q & R & AnyObject).Type) {} +public func foo(_ a: (any P & P1).Type) {} +public func foo(_ a: (any P & P1).Type) {} +public func foo(_ a: (any P & P1 & R).Type) {} +public func foo(_ a: (any P & P1 & R & C).Type) {} +public func foo(_ a: (any P & P1 & R & AnyObject).Type) {} + +public func foo(_ a: (any P & P1).Type) {} +public func foo(_ a: (any P & P1 & R).Type) {} +public func foo(_ a: (any P & P1 & R & C).Type) {} +public func foo(_ a: (any P & P1 & R & AnyObject).Type) {} + +public protocol Q2: Q {} + +public protocol Q3: Q { + associatedtype C +} + +public func foo(_ a: (any Q2 & R).Type) {} +public func foo(_ a: (any Q3 & R).Type) {} +public func foo(_ a: (any Q2 & Q3).Type) {} +public func foo(_ a: (any Q2 & Q3).Type) {} +public func foo2(_ a: (any Q2 & Q3).Type) {} +public func foo3(_ a: (any Q2 & Q3).Type) {} + public struct Foo { public var a1: (repeat any P & R) } diff --git a/test/decl/ext/specialize.swift b/test/decl/ext/specialize.swift index 72bef5ee947d7..84c1faadd7b00 100644 --- a/test/decl/ext/specialize.swift +++ b/test/decl/ext/specialize.swift @@ -86,3 +86,9 @@ class State { extension Test.Key { static let state = Self() } + +protocol P {} +struct S: P {} + +extension Sequence where Self == [S] {} +// expected-error@-1 {{generic signature requires types 'S' and 'any P' to be the same}} diff --git a/validation-test/compiler_crashers_2/1470917329979c9a.swift b/validation-test/compiler_crashers_2_fixed/1470917329979c9a.swift similarity index 80% rename from validation-test/compiler_crashers_2/1470917329979c9a.swift rename to validation-test/compiler_crashers_2_fixed/1470917329979c9a.swift index 8a98f89ef6258..c7f9b51c8a1ae 100644 --- a/validation-test/compiler_crashers_2/1470917329979c9a.swift +++ b/validation-test/compiler_crashers_2_fixed/1470917329979c9a.swift @@ -1,5 +1,5 @@ // {"signature":"swift::PackExpansionType::PackExpansionType(swift::Type, swift::Type, swift::RecursiveTypeProperties, swift::ASTContext const*)"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s struct a < each b { struct c { d : (repeat(each b diff --git a/validation-test/compiler_crashers_2/14b6ac8674b84f44.swift b/validation-test/compiler_crashers_2_fixed/14b6ac8674b84f44.swift similarity index 70% rename from validation-test/compiler_crashers_2/14b6ac8674b84f44.swift rename to validation-test/compiler_crashers_2_fixed/14b6ac8674b84f44.swift index 24b8bad880983..60c336e8529e5 100644 --- a/validation-test/compiler_crashers_2/14b6ac8674b84f44.swift +++ b/validation-test/compiler_crashers_2_fixed/14b6ac8674b84f44.swift @@ -1,4 +1,4 @@ // {"signature":"(anonymous namespace)::ABIDependencyEvaluator::computeABIDependenciesForModule(swift::ModuleDecl*)"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s switch { case init diff --git a/validation-test/compiler_crashers_2/43bf2cb496111e.swift b/validation-test/compiler_crashers_2_fixed/43bf2cb496111e.swift similarity index 57% rename from validation-test/compiler_crashers_2/43bf2cb496111e.swift rename to validation-test/compiler_crashers_2_fixed/43bf2cb496111e.swift index cdfc24fbd0bfb..2df690c1519a7 100644 --- a/validation-test/compiler_crashers_2/43bf2cb496111e.swift +++ b/validation-test/compiler_crashers_2_fixed/43bf2cb496111e.swift @@ -1,3 +1,3 @@ // {"signature":"swift::Lexer::formEscapedIdentifierToken(char const*)"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s `` diff --git a/validation-test/compiler_crashers_2/448bdb8b9df6dd2.swift b/validation-test/compiler_crashers_2_fixed/448bdb8b9df6dd2.swift similarity index 69% rename from validation-test/compiler_crashers_2/448bdb8b9df6dd2.swift rename to validation-test/compiler_crashers_2_fixed/448bdb8b9df6dd2.swift index ca2bcd37ab654..d975dbcedb5a0 100644 --- a/validation-test/compiler_crashers_2/448bdb8b9df6dd2.swift +++ b/validation-test/compiler_crashers_2_fixed/448bdb8b9df6dd2.swift @@ -1,3 +1,3 @@ // {"signature":"swift::DeclRefTypeRepr::overwriteNameRef(swift::DeclNameRef)"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s switch { case init( diff --git a/validation-test/compiler_crashers_2/59b42964e169b6fa.swift b/validation-test/compiler_crashers_2_fixed/59b42964e169b6fa.swift similarity index 82% rename from validation-test/compiler_crashers_2/59b42964e169b6fa.swift rename to validation-test/compiler_crashers_2_fixed/59b42964e169b6fa.swift index 1fafba98fc4df..9fb239872d3cb 100644 --- a/validation-test/compiler_crashers_2/59b42964e169b6fa.swift +++ b/validation-test/compiler_crashers_2_fixed/59b42964e169b6fa.swift @@ -1,5 +1,5 @@ // {"signature":"swift::ProtocolConformanceRef::getProtocol() const"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s func a, bool)"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s any a <