Skip to content

Hamish fuzzer fixes #81843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/ProtocolConformanceRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class ProtocolConformanceRef {
}

AbstractConformance *getAbstract() const {
ASSERT(isAbstract());
return Union.get<AbstractConformance *>();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ struct ASTContext::Implementation {
llvm::DenseMap<const AbstractFunctionDecl *, SourceRange> OriginalBodySourceRanges;

/// Macro discriminators per context.
llvm::DenseMap<std::pair<const void *, Identifier>, unsigned>
llvm::DenseMap<std::pair<const void *, DeclBaseName>, unsigned>
NextMacroDiscriminator;

/// Local and closure discriminators per context.
Expand Down Expand Up @@ -2286,8 +2286,8 @@ unsigned ASTContext::getNextMacroDiscriminator(
MacroDiscriminatorContext context,
DeclBaseName baseName
) {
std::pair<const void *, Identifier> key(
context.getOpaqueValue(), baseName.getIdentifier());
std::pair<const void *, DeclBaseName> key(
context.getOpaqueValue(), baseName);
return getImpl().NextMacroDiscriminator[key]++;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ Type ASTBuilder::createExistentialMetatypeType(
Type ASTBuilder::createConstrainedExistentialType(
Type base, ArrayRef<BuiltRequirement> constraints,
ArrayRef<BuiltInverseRequirement> inverseRequirements) {
llvm::SmallDenseMap<Identifier, Type> primaryAssociatedTypes;
llvm::SmallDenseSet<Identifier> claimed;
llvm::SmallDenseMap<AssociatedTypeDecl *, Type> primaryAssociatedTypes;
llvm::SmallDenseSet<AssociatedTypeDecl *> claimed;

for (const auto &req : constraints) {
switch (req.getKind()) {
Expand All @@ -782,7 +782,7 @@ Type ASTBuilder::createConstrainedExistentialType(
if (auto *memberTy = req.getFirstType()->getAs<DependentMemberType>()) {
if (memberTy->getBase()->is<GenericTypeParamType>()) {
// This is the only case we understand so far.
primaryAssociatedTypes[memberTy->getName()] = req.getSecondType();
primaryAssociatedTypes[memberTy->getAssocType()] = req.getSecondType();
continue;
}
}
Expand All @@ -799,7 +799,7 @@ Type ASTBuilder::createConstrainedExistentialType(

llvm::SmallVector<Type, 4> 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);
Expand Down
9 changes: 5 additions & 4 deletions lib/Parse/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
peekToken().isContextualPunctuator("~")) &&
!peekToken().isAtStartOfLine()) {
ParserResult<TypeRepr> ty = parseType();
if (ty.isNull())
return nullptr;

auto *typeExpr = new (Context) TypeExpr(ty.get());
return makeParserResult(typeExpr);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4068,8 +4068,8 @@ namespace {
}

/// Lookup all macros with the given macro name.
SmallVector<OverloadChoice, 1> lookupMacros(Identifier moduleName,
Identifier macroName,
SmallVector<OverloadChoice, 1> lookupMacros(DeclName moduleName,
DeclName macroName,
FunctionRefInfo functionRefInfo,
MacroRoles roles) {
SmallVector<OverloadChoice, 1> choices;
Expand Down Expand Up @@ -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());
Expand Down
7 changes: 5 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TupleType>() != desugar2->is<TupleType>() &&
(!desugar1->isAny() && !desugar2->isAny())) {
if (isa<TupleType>(desugar1) != isa<TupleType>(desugar2) &&
!isa<InOutType>(desugar1) &&
!isa<InOutType>(desugar2) &&
!desugar1->isAny() &&
!desugar2->isAny()) {
return matchTypes(
desugar1->is<TupleType>() ? type1
: TupleType::get({type1}, getASTContext()),
Expand Down
19 changes: 13 additions & 6 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/Sema/TypeCheckEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckNameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
31 changes: 31 additions & 0 deletions test/DebugInfo/parameterized_existential_composition.swift
Original file line number Diff line number Diff line change
@@ -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<A, B> {
associatedtype A
associatedtype B
}

public protocol P1<A> {
associatedtype A
}

public protocol Q<C> {
associatedtype C
}
Expand All @@ -31,6 +38,30 @@ public func foo(_ a: (any P<Int, Float> & Q<String> & R).Type) {}
public func foo(_ a: (any P<Int, Float> & Q<String> & R & C<Bool>).Type) {}
public func foo(_ a: (any P<Int, Float> & Q<String> & R & AnyObject).Type) {}

public func foo(_ a: (any P & P1).Type) {}
public func foo(_ a: (any P & P1<String>).Type) {}
public func foo(_ a: (any P & P1<String> & R).Type) {}
public func foo(_ a: (any P & P1<String> & R & C<Bool>).Type) {}
public func foo(_ a: (any P & P1<String> & R & AnyObject).Type) {}

public func foo(_ a: (any P<Int, Float> & P1).Type) {}
public func foo(_ a: (any P<Int, Float> & P1 & R).Type) {}
public func foo(_ a: (any P<Int, Float> & P1 & R & C<Bool>).Type) {}
public func foo(_ a: (any P<Int, Float> & P1 & R & AnyObject).Type) {}

public protocol Q2<C>: Q {}

public protocol Q3<C>: Q {
associatedtype C
}

public func foo(_ a: (any Q2<Int> & R).Type) {}
public func foo(_ a: (any Q3<Int> & R).Type) {}
public func foo(_ a: (any Q2 & Q3).Type) {}
public func foo(_ a: (any Q2 & Q3<Int>).Type) {}
public func foo2(_ a: (any Q2<Int> & Q3).Type) {}
public func foo3(_ a: (any Q2<Int> & Q3<Int>).Type) {}

public struct Foo<each T, U> {
public var a1: (repeat any P<each T, U> & R)
}
6 changes: 6 additions & 0 deletions test/decl/ext/specialize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ class State {
extension Test.Key<State> {
static let state = Self<State>()
}

protocol P {}
struct S: P {}

extension Sequence<any P> where Self == [S] {}
// expected-error@-1 {{generic signature requires types 'S' and 'any P' to be the same}}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
``
Original file line number Diff line number Diff line change
@@ -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(
Original file line number Diff line number Diff line change
@@ -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<each b {
enum c {
case struct var d: e struct e {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"signature":"swift::DeclAndTypePrinter::Implementation::visitVarDecl(swift::VarDecl*)"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
#init
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"signature":"swift::ParamSpecifierRequest::evaluate(swift::Evaluator&, swift::ParamDecl*) const"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
func a([0])
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"signature":"swift::Parser::parseExprSequenceElement(swift::Diag<>, bool)"}
// RUN: not --crash %target-swift-frontend -typecheck %s
// RUN: not %target-swift-frontend -typecheck %s
any a <