Skip to content

[Gardening] Fix some set but not used variables #78750

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 1 commit into from
Jan 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 lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Type ASTBuilder::createNominalType(GenericTypeDecl *decl, Type parent) {
return Type();

// If the declaration is generic, fail.
if (auto list = nominalDecl->getGenericParams())
if (nominalDecl->isGeneric())
return Type();

// Imported types can be renamed to be members of other (non-generic)
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5692,7 +5692,7 @@ namespace {
} else if (auto *VD = originator.dyn_cast<VarDecl *>()) {
printFieldQuotedRaw([&](raw_ostream &OS) { VD->dumpRef(OS); },
Label::optional("originating_var"), DeclColor);
} else if (auto *EE = originator.dyn_cast<ErrorExpr *>()) {
} else if (originator.is<ErrorExpr *>()) {
printFlag("error_expr");
} else if (auto *DMT = originator.dyn_cast<DependentMemberType *>()) {
printRec(DMT, Label::always("dependent_member_type"));
Expand Down
10 changes: 5 additions & 5 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3050,7 +3050,7 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl,
appendIdentifier(interface->getObjCRuntimeNameAsString());
} else if (UseObjCRuntimeNames && protocol) {
appendIdentifier(protocol->getObjCRuntimeNameAsString());
} else if (auto ctsd = dyn_cast<clang::ClassTemplateSpecializationDecl>(namedDecl)) {
} else if (isa<clang::ClassTemplateSpecializationDecl>(namedDecl)) {
// If this is a `ClassTemplateSpecializationDecl`, it was
// imported as a Swift decl with `__CxxTemplateInst...` name.
// `ClassTemplateSpecializationDecl`'s name does not include information about
Expand Down Expand Up @@ -3247,7 +3247,7 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
appendOperator("YK");
}
}
switch (auto diffKind = fn->getDifferentiabilityKind()) {
switch (fn->getDifferentiabilityKind()) {
case DifferentiabilityKind::NonDifferentiable:
break;
case DifferentiabilityKind::Forward:
Expand Down Expand Up @@ -4158,11 +4158,11 @@ void ASTMangler::appendAccessorEntity(StringRef accessorKindCode,

BaseEntitySignature base(decl);
appendContextOf(decl, base);
if (auto *varDecl = dyn_cast<VarDecl>(decl)) {
if (isa<VarDecl>(decl)) {
appendDeclName(decl);
appendDeclType(decl, base);
appendOperator("v", accessorKindCode);
} else if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(decl)) {
} else if (isa<SubscriptDecl>(decl)) {
appendDeclType(decl, base);

StringRef privateDiscriminator = getPrivateDiscriminatorIfNecessary(decl);
Expand Down Expand Up @@ -4957,7 +4957,7 @@ getPrecheckedLocalContextDiscriminator(const Decl *decl, Identifier name) {
std::string ASTMangler::mangleAttachedMacroExpansion(
const Decl *decl, CustomAttr *attr, MacroRole role) {
if (auto abiDecl = getABIDecl(decl)) {
return mangleAttachedMacroExpansion(decl, attr, role);
return mangleAttachedMacroExpansion(abiDecl, attr, role);
}

// FIXME(kavon): using the decl causes a cycle. Is a null base fine?
Expand Down
10 changes: 5 additions & 5 deletions lib/AST/ASTNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ bool ASTNode::isImplicit() const {
return D->isImplicit();
if (const auto *P = this->dyn_cast<Pattern*>())
return P->isImplicit();
if (const auto *T = this->dyn_cast<TypeRepr*>())
if (this->is<TypeRepr *>())
return false;
if (const auto *C = this->dyn_cast<StmtConditionElement *>())
if (this->is<StmtConditionElement *>())
return false;
if (const auto *I = this->dyn_cast<CaseLabelItem *>())
if (this->is<CaseLabelItem *>())
return false;
llvm_unreachable("unsupported AST node");
}
Expand Down Expand Up @@ -124,9 +124,9 @@ void ASTNode::dump(raw_ostream &OS, unsigned Indent) const {
P->dump(OS, Indent);
else if (auto T = dyn_cast<TypeRepr*>())
T->print(OS);
else if (auto *C = dyn_cast<StmtConditionElement *>())
else if (is<StmtConditionElement *>())
OS.indent(Indent) << "(statement condition)";
else if (auto *I = dyn_cast<CaseLabelItem *>()) {
else if (is<CaseLabelItem *>()) {
OS.indent(Indent) << "(case label item)";
} else
llvm_unreachable("unsupported AST node");
Expand Down
10 changes: 5 additions & 5 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static bool isPrespecilizationDeclWithTarget(const ValueDecl *vd) {
for (auto *attr : vd->getAttrs().getAttributes<SpecializeAttr>()) {
if (!attr->isExported())
continue;
if (auto *targetFun = attr->getTargetFunctionDecl(vd))
if (attr->getTargetFunctionDecl(vd))
return true;
}
return false;
Expand Down Expand Up @@ -4132,7 +4132,7 @@ void PrintAST::visitAccessorDecl(AccessorDecl *decl) {
// Explicitly print 'mutating' and 'nonmutating' if needed.
printSelfAccessKindModifiersIfNeeded(decl);

switch (auto kind = decl->getAccessorKind()) {
switch (decl->getAccessorKind()) {
case AccessorKind::Get:
case AccessorKind::DistributedGet:
case AccessorKind::Address:
Expand Down Expand Up @@ -4769,13 +4769,13 @@ void PrintAST::visitErrorExpr(ErrorExpr *expr) {

void PrintAST::visitTernaryExpr(TernaryExpr *expr) {
if (auto condExpr = expr->getCondExpr()) {
visit(expr->getCondExpr());
visit(condExpr);
}
Printer << " ? ";
visit(expr->getThenExpr());
Printer << " : ";
if (auto elseExpr = expr->getElseExpr()) {
visit(expr->getElseExpr());
visit(elseExpr);
}
}

Expand Down Expand Up @@ -6056,7 +6056,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
} else if (auto *VD = originator.dyn_cast<VarDecl *>()) {
Printer << "decl = ";
Printer << VD->getName();
} else if (auto *EE = originator.dyn_cast<ErrorExpr *>()) {
} else if (originator.is<ErrorExpr *>()) {
Printer << "error_expr";
} else if (auto *DMT = originator.dyn_cast<DependentMemberType *>()) {
visit(DMT);
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ class Verifier : public ASTWalker {
resultType = FD->mapTypeIntoContext(resultType);
} else if (auto closure = dyn_cast<AbstractClosureExpr>(func)) {
resultType = closure->getResultType();
} else if (auto *CD = dyn_cast<ConstructorDecl>(func)) {
} else if (isa<ConstructorDecl>(func)) {
resultType = TupleType::getEmpty(Ctx);
} else {
resultType = TupleType::getEmpty(Ctx);
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,

for (auto &origComponent : components) {
auto component = origComponent;
switch (auto kind = component.getKind()) {
switch (component.getKind()) {
case KeyPathExpr::Component::Kind::Subscript:
case KeyPathExpr::Component::Kind::UnresolvedSubscript: {
if (auto *newArgs = doIt(component.getSubscriptArgs())) {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void OpenedTypeAttr::printImpl(ASTPrinter &printer,
printer << "(\"" << getUUID() << "\"";
if (auto constraintType = getConstraintType()) {
printer << ", ";
getConstraintType()->print(printer, options);
constraintType->print(printer, options);
}
printer << ")";
printer.printStructurePost(PrintStructureKind::BuiltinAttribute);
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ AccessLevel ImportDecl::getAccessLevel() const {
}

bool ImportDecl::isAccessLevelImplicit() const {
if (auto attr = getAttrs().getAttribute<AccessControlAttr>()) {
if (getAttrs().hasAttribute<AccessControlAttr>()) {
return false;
}
return true;
Expand Down Expand Up @@ -4678,7 +4678,7 @@ static AccessLevel getAdjustedFormalAccess(const ValueDecl *VD,
if (useDC) {
// If the use site decl context is PackageUnit, just return
// the access level that's passed in
if (auto usePkg = useDC->getPackageContext())
if (useDC->getPackageContext())
return access;
// Check whether we need to modify the access level based on
// @testable/@_private import attributes.
Expand Down Expand Up @@ -8013,7 +8013,7 @@ bool VarDecl::isMemberwiseInitialized(bool preferDeclaredProperties) const {
// memberwise initializable when it could be used to initialize
// other stored properties.
if (hasInitAccessor()) {
if (auto *init = getAccessor(AccessorKind::Init))
if (getAccessor(AccessorKind::Init))
return true;
}

Expand Down Expand Up @@ -11509,7 +11509,7 @@ ActorIsolation swift::getActorIsolationOfContext(
return getClosureActorIsolation(closure);
}

if (auto *tld = dyn_cast<TopLevelCodeDecl>(dcToUse)) {
if (isa<TopLevelCodeDecl>(dcToUse)) {
if (dcToUse->isAsyncContext() ||
dcToUse->getASTContext().LangOpts.StrictConcurrencyLevel >=
StrictConcurrency::Complete) {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/DistributedDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Type swift::getConcreteReplacementForProtocolActorSystemType(
}

/// === Maybe the value is declared in a protocol?
if (auto protocol = DC->getSelfProtocolDecl()) {
if (DC->getSelfProtocolDecl()) {
GenericSignature signature;
if (auto *genericContext = anyValue->getAsGenericContext()) {
signature = genericContext->getGenericSignature();
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ StringRef ModuleDecl::getModuleFilename() const {
continue;
}
// Skip synthesized files.
if (auto *SFU = dyn_cast<SynthesizedFileUnit>(F))
if (isa<SynthesizedFileUnit>(F))
continue;
return StringRef();
}
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ namelookup::isInMacroArgument(SourceFile *sourceFile, SourceLoc loc) {

if (macro.getFreestanding()) {
inMacroArgument = true;
} else if (auto *attr = macro.getAttr()) {
} else if (macro.getAttr()) {
auto *moduleScope = sourceFile->getModuleScopeContext();
auto results =
lookupMacros(moduleScope, macro.getModuleName(),
Expand Down Expand Up @@ -1914,7 +1914,7 @@ PotentialMacroExpansions PotentialMacroExpansionsInContextRequest::evaluate(
dc->getModuleScopeContext(), med->getMacroName(),
MacroRole::Declaration, nameTracker);
} else if (auto *vd = dyn_cast<ValueDecl>(member)) {
nameTracker.attachedTo = dyn_cast<ValueDecl>(member);
nameTracker.attachedTo = vd;
forEachPotentialAttachedMacro(member, MacroRole::Peer, nameTracker);
}
}
Expand Down Expand Up @@ -2000,7 +2000,7 @@ populateLookupTableEntryFromMacroExpansions(ASTContext &ctx,
dc->getModuleScopeContext(), med->getMacroName(),
MacroRole::Declaration, nameTracker);
} else if (auto *vd = dyn_cast<ValueDecl>(member)) {
nameTracker.attachedTo = dyn_cast<ValueDecl>(member);
nameTracker.attachedTo = vd;
forEachPotentialAttachedMacro(member, MacroRole::Peer, nameTracker);
}

Expand Down Expand Up @@ -3606,7 +3606,7 @@ CollectedOpaqueReprs swift::collectOpaqueTypeReprs(TypeRepr *r, ASTContext &ctx,
if (!Ctx.LangOpts.hasFeature(Feature::ImplicitSome))
return Action::Continue();

if (auto existential = dyn_cast<ExistentialTypeRepr>(repr)) {
if (isa<ExistentialTypeRepr>(repr)) {
return Action::SkipNode();
} else if (auto composition = dyn_cast<CompositionTypeRepr>(repr)) {
if (!composition->isTypeReprAny())
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/SubstitutionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ SubstitutionMap::getOverrideSubstitutions(
const ValueDecl *baseDecl,
const ValueDecl *derivedDecl) {
// For overrides within a protocol hierarchy, substitute the Self type.
if (auto baseProto = baseDecl->getDeclContext()->getSelfProtocolDecl()) {
if (baseDecl->getDeclContext()->getSelfProtocolDecl()) {
auto baseSig = baseDecl->getInnermostDeclContext()
->getGenericSignatureOfContext();
return baseSig->getIdentitySubstitutionMap();
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/TypeSubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ operator()(CanType dependentType, Type conformingReplacementType,
ProtocolDecl *conformedProtocol) const {
// Lookup conformances for archetypes that conform concretely
// via a superclass.
if (auto archetypeType = conformingReplacementType->getAs<ArchetypeType>()) {
if (conformingReplacementType->is<ArchetypeType>()) {
return lookupConformance(
conformingReplacementType, conformedProtocol,
/*allowMissing=*/true);
Expand Down Expand Up @@ -667,7 +667,7 @@ SubstitutionMap TypeBase::getContextSubstitutionMap() {
}

// This case indicates we have invalid nesting of types.
if (auto protocolTy = baseTy->getAs<ProtocolType>()) {
if (baseTy->is<ProtocolType>()) {
if (!first)
break;

Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5792,7 +5792,7 @@ synthesizeBaseClassFieldGetterOrAddressGetterBody(AbstractFunctionDecl *afd,
baseMemberDotCallExpr->setThrows(nullptr);

ArgumentList *argumentList;
if (auto subscript = dyn_cast<SubscriptDecl>(baseClassVar)) {
if (isa<SubscriptDecl>(baseClassVar)) {
auto paramDecl = getterDecl->getParameters()->get(0);
auto paramRefExpr = new (ctx) DeclRefExpr(paramDecl, DeclNameLoc(),
/*Implicit=*/true);
Expand Down
9 changes: 3 additions & 6 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@ void ClangImporter::Implementation::addSynthesizedProtocolAttrs(
// ctx.getProtocol(kind) != nulltpr which would be nice.
if (auto proto = ctx.getProtocol(kind))
nominal->getAttrs().add(
new (ctx) SynthesizedProtocolAttr(ctx.getProtocol(kind), this,
isUnchecked));
new (ctx) SynthesizedProtocolAttr(proto, this, isUnchecked));
}
}

Expand Down Expand Up @@ -4183,8 +4182,7 @@ namespace {

if (decl->isVirtual()) {
if (auto funcDecl = dyn_cast_or_null<FuncDecl>(method)) {
if (auto structDecl =
dyn_cast_or_null<StructDecl>(method->getDeclContext())) {
if (isa_and_nonnull<StructDecl>(method->getDeclContext())) {
// If this is a method of a Swift struct, any possible override of
// this method would get sliced away, and an invocation would get
// dispatched statically. This is fine because it matches the C++
Expand All @@ -4196,8 +4194,7 @@ namespace {
"virtual function is not available in Swift "
"because it is pure");
}
} else if (auto classDecl = dyn_cast_or_null<ClassDecl>(
funcDecl->getDeclContext())) {
} else if (isa_and_nonnull<ClassDecl>(funcDecl->getDeclContext())) {
// This is a foreign reference type. Since `class T` on the Swift
// side is mapped from `T*` on the C++ side, an invocation of a
// virtual method `t->method()` should get dispatched dynamically.
Expand Down
3 changes: 1 addition & 2 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
arguments.push_back("-disable-objc-interop");
}

if (const Arg *arg = inputArgs.getLastArg(
options::OPT_experimental_serialize_debug_info)) {
if (inputArgs.getLastArg(options::OPT_experimental_serialize_debug_info)) {
arguments.push_back(
inputArgs.MakeArgString(Twine("-experimental-serialize-debug-info")));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/DriverTool/autolink_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static bool extractLinkerFlags(const llvm::object::Binary *Bin,
}
}
return bool(Error);
} else if (auto *IRObjectFile = llvm::dyn_cast<llvm::object::IRObjectFile>(Bin)) {
} else if (llvm::isa<llvm::object::IRObjectFile>(Bin)) {
// Ignore the LLVM IR files (LTO)
return false;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3259,7 +3259,7 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
if (auto A = Args.getLastArg(OPT_enable_round_trip_debug_types,
OPT_disable_round_trip_debug_types)) {
Opts.DisableRoundTripDebugTypes =
Args.hasArg(OPT_disable_round_trip_debug_types);
A->getOption().matches(OPT_disable_round_trip_debug_types);
}

if (Args.hasArg(OPT_disable_debugger_shadow_copies))
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ Type CompletionLookup::getAssociatedTypeType(const AssociatedTypeDecl *ATD) {
CurrDeclContext->getInnermostTypeContext()->getDeclaredTypeInContext();
if (BaseTy) {
BaseTy = BaseTy->getInOutObjectType()->getMetatypeInstanceType();
if (auto NTD = BaseTy->getAnyNominal()) {
if (BaseTy->getAnyNominal()) {
auto Conformance = lookupConformance(BaseTy, ATD->getProtocol());
if (Conformance.isConcrete()) {
return Conformance.getConcrete()->getTypeWitness(
Expand Down
4 changes: 2 additions & 2 deletions lib/IDE/Formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class RangeWalker: protected ASTWalker {
SourceRange Braces(PGD->getLBraceLoc(), PGD->getRBraceLoc());
if (!handleBraces(Braces, ContextLoc))
return Action::Stop();
} else if (auto *PDD = dyn_cast<PoundDiagnosticDecl>(D)) {
} else if (isa<PoundDiagnosticDecl>(D)) {
// TODO: add paren locations to PoundDiagnosticDecl
}

Expand Down Expand Up @@ -580,7 +580,7 @@ class RangeWalker: protected ASTWalker {
} else if (auto *WS = dyn_cast<WhileStmt>(S)) {
if (!handleBraceStmt(WS->getBody(), WS->getWhileLoc()))
return Action::Stop();
} else if (auto *PAS = dyn_cast<PoundAssertStmt>(S)) {
} else if (isa<PoundAssertStmt>(S)) {
// TODO: add paren locations to PoundAssertStmt
}

Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/SourceEntityWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ bool SemaAnnotator::shouldIgnore(Decl *D) {
// Walk into missing decls to visit their attributes if they were generated
// by a member attribute expansion. Note that we would have already skipped
// this decl if we were ignoring expansions, so no need to check that.
if (auto *missing = dyn_cast<MissingDecl>(D)) {
if (isa<MissingDecl>(D)) {
if (D->isInMacroExpansionInContext())
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenArchetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ const TypeInfo *TypeConverter::convertArchetypeType(ArchetypeType *archetype) {
// Opaque result types can be private and from a different module. In this
// case we can't access their type metadata from another module.
IsABIAccessible_t abiAccessible = IsABIAccessible;
if (auto opaqueArchetype = dyn_cast<OpaqueTypeArchetypeType>(archetype)) {
if (isa<OpaqueTypeArchetypeType>(archetype)) {
auto &currentSILModule = IGM.getSILModule();
abiAccessible =
currentSILModule.isTypeMetadataAccessible(archetype->getCanonicalType())
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6620,7 +6620,7 @@ llvm::FunctionType *FunctionPointer::getFunctionType() const {
}

// Read the function type off the global or else from the Signature.
if (auto *constant = dyn_cast<llvm::Constant>(Value)) {
if (isa<llvm::Constant>(Value)) {
auto *gv = dyn_cast<llvm::GlobalValue>(Value);
if (!gv) {
return Sig.getType();
Expand Down
Loading