Skip to content

Commit 6b1697e

Browse files
committed
use new llvm::Optional APIs to fix deprecation warnings
1 parent 746dd98 commit 6b1697e

20 files changed

+28
-28
lines changed

include/swift/Basic/Lazy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class LazyValue {
3939
LazyValue(Initializer Init) : Init(Init){};
4040

4141
T &get() {
42-
if (!Value.hasValue()) {
42+
if (!Value.has_value()) {
4343
Value = Init();
4444
}
4545
return Value.value();

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,7 @@ RestrictedImportKind SourceFile::getRestrictedImportKind(const ModuleDecl *modul
32323232

32333233
ImportAccessLevel
32343234
SourceFile::getImportAccessLevel(const ModuleDecl *targetModule) const {
3235-
assert(Imports.hasValue());
3235+
assert(Imports.has_value());
32363236

32373237
// Leave it to the caller to avoid calling this service for a self import.
32383238
// We want to return AccessLevel::Public, but there's no import site to return.

lib/AST/ParameterPack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static CanPackType getApproximateFormalPackType(const ASTContext &ctx,
481481
formalEltTypes->push_back(formalEltType);
482482
}
483483

484-
assert(isLegal || formalEltTypes.hasValue());
484+
assert(isLegal || formalEltTypes.has_value());
485485
}
486486

487487
// Use the array we built if we made one (if we ever saw a non-legal

lib/IDE/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ void swift::ide::SourceEditConsumer::acceptMacroExpansionBuffer(
702702
containingSF->getParentModule()->getSourceFileContainingLocation(
703703
originalSourceRange.getStart());
704704
StringRef originalPath;
705-
if (originalFile->getBufferID().hasValue() &&
705+
if (originalFile->getBufferID().has_value() &&
706706
containingSF->getBufferID() != originalFile->getBufferID()) {
707707
originalPath = SM.getIdentifierForBuffer(*originalFile->getBufferID());
708708
}

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
27002700

27012701
return llvm::DIExpression::createFragmentExpression(
27022702
DIExpr, PieceFragment.OffsetInBits, PieceFragment.SizeInBits)
2703-
.getValueOr(nullptr);
2703+
.value_or(nullptr);
27042704
}
27052705

27062706
llvm::SmallVector<uint64_t, 2> Operands;
@@ -2715,7 +2715,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
27152715
if (VarFragment.SizeInBits)
27162716
DIExpr = llvm::DIExpression::createFragmentExpression(
27172717
DIExpr, VarFragment.OffsetInBits, VarFragment.SizeInBits)
2718-
.getValueOr(nullptr);
2718+
.value_or(nullptr);
27192719

27202720
if (!DIExpr)
27212721
return nullptr;
@@ -2726,7 +2726,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
27262726
if (PieceFragment.SizeInBits)
27272727
return llvm::DIExpression::createFragmentExpression(
27282728
DIExpr, PieceFragment.OffsetInBits, PieceFragment.SizeInBits)
2729-
.getValueOr(nullptr);
2729+
.value_or(nullptr);
27302730

27312731
return DIExpr;
27322732
};

lib/IRGen/TypeLayout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class LayoutStringBuilder {
243243
compactXIByteCount << 59 |
244244
enumData.xiOffset;
245245
B.addInt64(byteCountsAndOffset);
246-
B.addSize(enumData.payload->fixedSize(IGM).getValue());
246+
B.addSize(enumData.payload->fixedSize(IGM).value());
247247
B.addInt64(enumData.zeroTagValue);
248248
B.addSize(Size(enumData.xiTagValues));
249249
auto nestedRefCountBytesPlaceholder =

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
16681668
case tok::kw_self: { // self
16691669
auto canParseBindingInPattern = [&]() {
16701670
if (InBindingPattern != PatternBindingState::ImplicitlyImmutable &&
1671-
!InBindingPattern.getIntroducer().hasValue()) {
1671+
!InBindingPattern.getIntroducer().has_value()) {
16721672
return false;
16731673
}
16741674
// If we have "case let x.", "case let x(", or "case let x[", we parse 'x'
@@ -1699,7 +1699,7 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
16991699
// If we have an inout/let/var, set that as our introducer. otherwise
17001700
// default to Let.
17011701
auto introducer =
1702-
InBindingPattern.getIntroducer().getValueOr(VarDecl::Introducer::Let);
1702+
InBindingPattern.getIntroducer().value_or(VarDecl::Introducer::Let);
17031703
auto pattern = createBindingFromPattern(loc, name, introducer);
17041704
return makeParserResult(new (Context) UnresolvedPatternExpr(pattern));
17051705
}

lib/Parse/ParsePattern.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ ParserResult<Pattern> Parser::parseTypedPattern() {
10651065
///
10661066
ParserResult<Pattern> Parser::parsePattern() {
10671067
auto introducer =
1068-
InBindingPattern.getIntroducer().getValueOr(VarDecl::Introducer::Let);
1068+
InBindingPattern.getIntroducer().value_or(VarDecl::Introducer::Let);
10691069
switch (Tok.getKind()) {
10701070
case tok::l_paren:
10711071
return parsePatternTuple();
@@ -1119,7 +1119,7 @@ ParserResult<Pattern> Parser::parsePattern() {
11191119
SourceLoc varLoc = consumeToken();
11201120

11211121
// 'var', 'let', 'inout' patterns shouldn't nest.
1122-
if (InBindingPattern.getIntroducer().hasValue()) {
1122+
if (InBindingPattern.getIntroducer().has_value()) {
11231123
auto diag = diag::var_pattern_in_var;
11241124
unsigned index = *newBindingState.getSelectIndexForIntroducer();
11251125
if (Context.LangOpts.hasFeature(Feature::ReferenceBindings)) {
@@ -1150,7 +1150,7 @@ ParserResult<Pattern> Parser::parsePattern() {
11501150
return nullptr;
11511151
return makeParserResult(new (Context) BindingPattern(
11521152
varLoc,
1153-
newBindingState.getIntroducer().getValueOr(VarDecl::Introducer::Var),
1153+
newBindingState.getIntroducer().value_or(VarDecl::Introducer::Var),
11541154
subPattern.get()));
11551155
}
11561156

@@ -1347,7 +1347,7 @@ ParserResult<Pattern>
13471347
Parser::parseMatchingPatternAsBinding(PatternBindingState newState,
13481348
SourceLoc varLoc, bool isExprBasic) {
13491349
// 'var', 'let', 'inout' patterns shouldn't nest.
1350-
if (InBindingPattern.getIntroducer().hasValue()) {
1350+
if (InBindingPattern.getIntroducer().has_value()) {
13511351
auto diag = diag::var_pattern_in_var;
13521352
if (Context.LangOpts.hasFeature(Feature::ReferenceBindings))
13531353
diag = diag::var_pattern_in_var_inout;
@@ -1372,7 +1372,7 @@ Parser::parseMatchingPatternAsBinding(PatternBindingState newState,
13721372
if (subPattern.isNull())
13731373
return nullptr;
13741374
auto *varP = new (Context) BindingPattern(
1375-
varLoc, newState.getIntroducer().getValueOr(VarDecl::Introducer::Var),
1375+
varLoc, newState.getIntroducer().value_or(VarDecl::Introducer::Var),
13761376
subPattern.get());
13771377
return makeParserResult(ParserStatus(subPattern), varP);
13781378
}

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ Parser::parseStmtConditionElement(SmallVectorImpl<StmtConditionElement> &result,
16631663
consumeToken(tok::kw_case);
16641664

16651665
auto newPatternBindingState = PatternBindingState::get(BindingKindStr)
1666-
.getValueOr(PatternBindingState(PatternBindingState::InVar));
1666+
.value_or(PatternBindingState(PatternBindingState::InVar));
16671667
BindingKindStr = "case";
16681668

16691669
// In our recursive parse, remember that we're in a var/let pattern.
@@ -1693,7 +1693,7 @@ Parser::parseStmtConditionElement(SmallVectorImpl<StmtConditionElement> &result,
16931693
// Otherwise, this is an implicit optional binding "if let".
16941694
ThePattern = parseMatchingPatternAsBinding(
16951695
PatternBindingState::get(BindingKindStr)
1696-
.getValueOr(PatternBindingState(PatternBindingState::InVar)),
1696+
.value_or(PatternBindingState(PatternBindingState::InVar)),
16971697
IntroducerLoc,
16981698
/*isExprBasic*/ true);
16991699
// The let/var pattern is part of the statement.

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ class ModuleWriter {
878878
os << " { } SWIFT_UNAVAILABLE_MSG(\"";
879879

880880
auto diag =
881-
representation.isUnsupported() && representation.error.hasValue()
881+
representation.isUnsupported() && representation.error.has_value()
882882
? cxx_translation::diagnoseRepresenationError(
883883
*representation.error, const_cast<ValueDecl *>(vd))
884884
: Diagnostic(

0 commit comments

Comments
 (0)