Skip to content

Commit bc5a657

Browse files
authored
---
yaml --- r: 343189 b: refs/heads/master-rebranch c: da8ef33 h: refs/heads/master i: 343187: a0074e8
1 parent 42902a0 commit bc5a657

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+901
-3707
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 1c2868444163802c78685f00981fb484083fc78e
1458+
refs/heads/master-rebranch: da8ef333c6310968151fe9769baf7d9dcad59dc8
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ ERROR(decl_new_witness_table_entry,none,"%0 now requires %select{|no}1 new witne
9696

9797
ERROR(new_decl_without_intro,none,"%0 is a new API without @available attribute", (StringRef))
9898

99+
ERROR(objc_name_change,none,"%0 has ObjC name change from %1 to %2", (StringRef, StringRef, StringRef))
100+
99101
#ifndef DIAG_NO_UNDEF
100102
# if defined(DIAG)
101103
# undef DIAG

branches/master-rebranch/include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace swift {
259259
bool WarnIfASTScopeLookup = false;
260260

261261
/// Build the ASTScope tree lazily
262-
bool LazyASTScopes = false;
262+
bool LazyASTScopes = true;
263263

264264
/// Whether to use the import as member inference system
265265
///

branches/master-rebranch/include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ class CompilerInvocation {
297297
/// Called from lldb, see rdar://53971116
298298
void disableASTScopeLookup() {
299299
LangOpts.EnableASTScopeLookup = false;
300-
LangOpts.LazyASTScopes = false;
301300
}
302301

303302
CodeCompletionCallbacksFactory *getCodeCompletionFactory() const {

branches/master-rebranch/include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ KEY_STRING(IntroiOS, intro_iOS)
151151
KEY_STRING(IntrotvOS, intro_tvOS)
152152
KEY_STRING(IntrowatchOS, intro_watchOS)
153153
KEY_STRING(Introswift, intro_swift)
154+
KEY_STRING(ObjCName, objc_name)
154155

155156
KEY_STRING_ARR(SuperclassNames, superclassNames)
156157
KEY_STRING_ARR(ToolArgs, tool_arguments)

branches/master-rebranch/include/swift/Index/IndexSymbol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct IndexSymbol : IndexRelation {
6666
SmallVector<IndexRelation, 3> Relations;
6767
unsigned line = 0;
6868
unsigned column = 0;
69+
Optional<unsigned> offset;
6970

7071
IndexSymbol() = default;
7172

branches/master-rebranch/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
339339
Opts.DisableParserLookup;
340340
Opts.CompareToASTScopeLookup |= Args.hasArg(OPT_compare_to_astscope_lookup);
341341
Opts.WarnIfASTScopeLookup |= Args.hasArg(OPT_warn_if_astscope_lookup);
342-
Opts.LazyASTScopes |=
343-
Opts.EnableASTScopeLookup && Args.hasArg(OPT_lazy_astscopes);
342+
Opts.LazyASTScopes |= Args.hasArg(OPT_lazy_astscopes);
344343

345344
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
346345
Opts.NamedLazyMemberLoading &= !Args.hasArg(OPT_disable_named_lazy_member_loading);

branches/master-rebranch/lib/Index/Index.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/ADT/SmallVector.h"
3131
#include "llvm/Support/ErrorHandling.h"
3232
#include "llvm/Support/FileSystem.h"
33+
#include <tuple>
3334

3435
using namespace swift;
3536
using namespace swift::index;
@@ -475,7 +476,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
475476
return true;
476477

477478
IndexSymbol Info;
478-
std::tie(Info.line, Info.column) = getLineCol(Loc);
479+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
479480
Info.roles |= (unsigned)SymbolRole::Reference;
480481
Info.symInfo = getSymbolInfoForModule(Mod);
481482
getModuleNameAndUSR(Mod, Info.name, Info.USR);
@@ -587,10 +588,13 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
587588

588589
bool indexComment(const Decl *D);
589590

590-
std::pair<unsigned, unsigned> getLineCol(SourceLoc Loc) {
591+
std::tuple<unsigned, unsigned, Optional<unsigned>>
592+
getLineColAndOffset(SourceLoc Loc) {
591593
if (Loc.isInvalid())
592-
return std::make_pair(0, 0);
593-
return SrcMgr.getLineAndColumn(Loc, BufferID);
594+
return std::make_tuple(0, 0, None);
595+
auto lineAndColumn = SrcMgr.getLineAndColumn(Loc, BufferID);
596+
unsigned offset = SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
597+
return std::make_tuple(lineAndColumn.first, lineAndColumn.second, offset);
594598
}
595599

596600
bool shouldIndex(ValueDecl *D, bool IsRef) const {
@@ -1082,7 +1086,7 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
10821086
return false;
10831087
if (!reportPseudoSetterDecl(VarD))
10841088
return false;
1085-
}
1089+
}
10861090

10871091
for (auto accessor : StoreD->getAllAccessors()) {
10881092
// Don't include the implicit getter and setter if we added pseudo
@@ -1227,7 +1231,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
12271231
if (getNameAndUSR(D, /*ExtD=*/nullptr, Info.name, Info.USR))
12281232
return true;
12291233

1230-
std::tie(Info.line, Info.column) = getLineCol(Loc);
1234+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
12311235
if (!IsRef) {
12321236
if (auto Group = D->getGroupName())
12331237
Info.group = Group.getValue();
@@ -1248,7 +1252,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
12481252
if (getNameAndUSR(ExtendedD, ExtD, Info.name, Info.USR))
12491253
return true;
12501254

1251-
std::tie(Info.line, Info.column) = getLineCol(Loc);
1255+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
12521256
if (auto Group = ExtD->getGroupName())
12531257
Info.group = Group.getValue();
12541258
return false;
@@ -1404,7 +1408,7 @@ bool IndexSwiftASTWalker::initVarRefIndexSymbols(Expr *CurrentE, ValueDecl *D,
14041408
case swift::AccessKind::Write:
14051409
Info.roles |= (unsigned)SymbolRole::Write;
14061410
}
1407-
1411+
14081412
return false;
14091413
}
14101414

@@ -1455,7 +1459,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
14551459
OS << "t:" << tagName;
14561460
Info.USR = stringStorage.copyString(OS.str());
14571461
}
1458-
std::tie(Info.line, Info.column) = getLineCol(loc);
1462+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(loc);
14591463
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles)) {
14601464
Cancelled = true;
14611465
break;

branches/master-rebranch/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3149,7 +3149,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
31493149

31503150
if (DeclResult.hasCodeCompletion() && isCodeCompletionFirstPass() &&
31513151
!CurDeclContext->isModuleScopeContext() &&
3152-
!isa<TopLevelCodeDecl>(CurDeclContext)) {
3152+
!isa<TopLevelCodeDecl>(CurDeclContext) &&
3153+
!isa<AbstractClosureExpr>(CurDeclContext)) {
31533154
// Only consume non-toplevel decls.
31543155
consumeDecl(BeginParserPosition, Flags, /*IsTopLevel=*/false);
31553156

branches/master-rebranch/lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,15 +1668,6 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
16681668
if (!exprType)
16691669
return CS.TC.Diags.hadAnyError();
16701670

1671-
// If we contextually had an inout type, and got a non-lvalue result, then
1672-
// we fail with a mutability error.
1673-
if (contextualType->is<InOutType>() && !exprType->is<LValueType>()) {
1674-
AssignmentFailure failure(recheckedExpr, CS, recheckedExpr->getLoc(),
1675-
diag::cannot_pass_rvalue_inout_subelement,
1676-
diag::cannot_pass_rvalue_inout);
1677-
return failure.diagnose();
1678-
}
1679-
16801671
// If we don't have a type for the expression, then we cannot use it in
16811672
// conversion constraint diagnostic generation. If the types match, then it
16821673
// must not be the contextual type that is the problem.

branches/master-rebranch/lib/Sema/CSDiagnostics.cpp

Lines changed: 77 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,17 +1567,7 @@ bool AssignmentFailure::diagnoseAsError() {
15671567
Type neededType = contextualType->getInOutObjectType();
15681568
Type actualType = getType(immInfo.first)->getInOutObjectType();
15691569
if (!neededType->isEqual(actualType)) {
1570-
if (DeclDiagnostic.ID == diag::cannot_pass_rvalue_inout_subelement.ID) {
1571-
// We have a special diagnostic with tailored wording for this
1572-
// common case.
1573-
emitDiagnostic(Loc, diag::cannot_pass_rvalue_inout_converted,
1574-
actualType, neededType)
1575-
.highlight(immInfo.first->getSourceRange());
1576-
1577-
if (auto inoutExpr = dyn_cast<InOutExpr>(immInfo.first))
1578-
fixItChangeInoutArgType(inoutExpr->getSubExpr(), actualType,
1579-
neededType);
1580-
} else {
1570+
if (DeclDiagnostic.ID != diag::cannot_pass_rvalue_inout_subelement.ID) {
15811571
emitDiagnostic(Loc, DeclDiagnostic,
15821572
"implicit conversion from '" + actualType->getString() +
15831573
"' to '" + neededType->getString() +
@@ -1601,68 +1591,6 @@ bool AssignmentFailure::diagnoseAsError() {
16011591
return true;
16021592
}
16031593

1604-
void AssignmentFailure::fixItChangeInoutArgType(const Expr *arg,
1605-
Type actualType,
1606-
Type neededType) const {
1607-
auto *DC = getDC();
1608-
auto *DRE = dyn_cast<DeclRefExpr>(arg);
1609-
if (!DRE)
1610-
return;
1611-
1612-
auto *VD = dyn_cast_or_null<VarDecl>(DRE->getDecl());
1613-
if (!VD)
1614-
return;
1615-
1616-
// Don't emit for non-local variables.
1617-
// (But in script-mode files, we consider module-scoped
1618-
// variables in the same file to be local variables.)
1619-
auto VDC = VD->getDeclContext();
1620-
bool isLocalVar = VDC->isLocalContext();
1621-
if (!isLocalVar && VDC->isModuleScopeContext()) {
1622-
auto argFile = DC->getParentSourceFile();
1623-
auto varFile = VDC->getParentSourceFile();
1624-
isLocalVar = (argFile == varFile && argFile->isScriptMode());
1625-
}
1626-
if (!isLocalVar)
1627-
return;
1628-
1629-
SmallString<32> scratch;
1630-
SourceLoc endLoc; // Filled in if we decide to diagnose this
1631-
SourceLoc startLoc; // Left invalid if we're inserting
1632-
1633-
auto isSimpleTypelessPattern = [](Pattern *P) -> bool {
1634-
if (auto VP = dyn_cast_or_null<VarPattern>(P))
1635-
P = VP->getSubPattern();
1636-
return P && isa<NamedPattern>(P);
1637-
};
1638-
1639-
auto typeRange = VD->getTypeSourceRangeForDiagnostics();
1640-
if (typeRange.isValid()) {
1641-
startLoc = typeRange.Start;
1642-
endLoc = typeRange.End;
1643-
} else if (isSimpleTypelessPattern(VD->getParentPattern())) {
1644-
endLoc = VD->getNameLoc();
1645-
scratch += ": ";
1646-
}
1647-
1648-
if (endLoc.isInvalid())
1649-
return;
1650-
1651-
scratch += neededType.getString();
1652-
1653-
// Adjust into the location where we actually want to insert
1654-
endLoc = Lexer::getLocForEndOfToken(getASTContext().SourceMgr, endLoc);
1655-
1656-
// Since we already adjusted endLoc, this will turn an insertion
1657-
// into a zero-character replacement.
1658-
if (!startLoc.isValid())
1659-
startLoc = endLoc;
1660-
1661-
emitDiagnostic(VD->getLoc(), diag::inout_change_var_type_if_possible,
1662-
actualType, neededType)
1663-
.fixItReplaceChars(startLoc, endLoc, scratch);
1664-
}
1665-
16661594
std::pair<Expr *, Optional<OverloadChoice>>
16671595
AssignmentFailure::resolveImmutableBase(Expr *expr) const {
16681596
auto &cs = getConstraintSystem();
@@ -4348,3 +4276,79 @@ bool ThrowingFunctionConversionFailure::diagnoseAsError() {
43484276
getFromType(), getToType());
43494277
return true;
43504278
}
4279+
4280+
bool InOutConversionFailure::diagnoseAsError() {
4281+
auto *anchor = getAnchor();
4282+
emitDiagnostic(anchor->getLoc(), diag::cannot_pass_rvalue_inout_converted,
4283+
getFromType(), getToType());
4284+
fixItChangeArgumentType();
4285+
return true;
4286+
}
4287+
4288+
void InOutConversionFailure::fixItChangeArgumentType() const {
4289+
auto *argExpr = getAnchor();
4290+
auto *DC = getDC();
4291+
4292+
if (auto *IOE = dyn_cast<InOutExpr>(argExpr))
4293+
argExpr = IOE->getSubExpr();
4294+
4295+
auto *DRE = dyn_cast<DeclRefExpr>(argExpr);
4296+
if (!DRE)
4297+
return;
4298+
4299+
auto *VD = dyn_cast_or_null<VarDecl>(DRE->getDecl());
4300+
if (!VD)
4301+
return;
4302+
4303+
// Don't emit for non-local variables.
4304+
// (But in script-mode files, we consider module-scoped
4305+
// variables in the same file to be local variables.)
4306+
auto VDC = VD->getDeclContext();
4307+
bool isLocalVar = VDC->isLocalContext();
4308+
if (!isLocalVar && VDC->isModuleScopeContext()) {
4309+
auto argFile = DC->getParentSourceFile();
4310+
auto varFile = VDC->getParentSourceFile();
4311+
isLocalVar = (argFile == varFile && argFile->isScriptMode());
4312+
}
4313+
if (!isLocalVar)
4314+
return;
4315+
4316+
auto actualType = getFromType();
4317+
auto neededType = getToType();
4318+
4319+
SmallString<32> scratch;
4320+
SourceLoc endLoc; // Filled in if we decide to diagnose this
4321+
SourceLoc startLoc; // Left invalid if we're inserting
4322+
4323+
auto isSimpleTypelessPattern = [](Pattern *P) -> bool {
4324+
if (auto VP = dyn_cast_or_null<VarPattern>(P))
4325+
P = VP->getSubPattern();
4326+
return P && isa<NamedPattern>(P);
4327+
};
4328+
4329+
auto typeRange = VD->getTypeSourceRangeForDiagnostics();
4330+
if (typeRange.isValid()) {
4331+
startLoc = typeRange.Start;
4332+
endLoc = typeRange.End;
4333+
} else if (isSimpleTypelessPattern(VD->getParentPattern())) {
4334+
endLoc = VD->getNameLoc();
4335+
scratch += ": ";
4336+
}
4337+
4338+
if (endLoc.isInvalid())
4339+
return;
4340+
4341+
scratch += neededType.getString();
4342+
4343+
// Adjust into the location where we actually want to insert
4344+
endLoc = Lexer::getLocForEndOfToken(getASTContext().SourceMgr, endLoc);
4345+
4346+
// Since we already adjusted endLoc, this will turn an insertion
4347+
// into a zero-character replacement.
4348+
if (!startLoc.isValid())
4349+
startLoc = endLoc;
4350+
4351+
emitDiagnostic(VD->getLoc(), diag::inout_change_var_type_if_possible,
4352+
actualType, neededType)
4353+
.fixItReplaceChars(startLoc, endLoc, scratch);
4354+
}

branches/master-rebranch/lib/Sema/CSDiagnostics.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,6 @@ class AssignmentFailure final : public FailureDiagnostic {
574574
bool diagnoseAsError() override;
575575

576576
private:
577-
void fixItChangeInoutArgType(const Expr *arg, Type actualType,
578-
Type neededType) const;
579-
580577
/// Given an expression that has a non-lvalue type, dig into it until
581578
/// we find the part of the expression that prevents the entire subexpression
582579
/// from being mutable. For example, in a sequence like "x.v.v = 42" we want
@@ -1509,6 +1506,24 @@ class MissingContextualConformanceFailure final : public ContextualFailure {
15091506
bool diagnoseAsError() override;
15101507
};
15111508

1509+
/// Diagnose a conversion mismatch between object types of `inout`
1510+
/// argument/parameter e.g. `'inout S' argument conv 'inout P'`.
1511+
///
1512+
/// Even if `S` conforms to `P` there is no subtyping rule for
1513+
/// argument type of `inout` parameter, they have to be equal.
1514+
class InOutConversionFailure final : public ContextualFailure {
1515+
public:
1516+
InOutConversionFailure(Expr *root, ConstraintSystem &cs, Type argType,
1517+
Type paramType, ConstraintLocator *locator)
1518+
: ContextualFailure(root, cs, argType, paramType, locator) {}
1519+
1520+
bool diagnoseAsError() override;
1521+
1522+
protected:
1523+
/// Suggest to change a type of the argument if possible.
1524+
void fixItChangeArgumentType() const;
1525+
};
1526+
15121527
/// Diagnose generic argument omission e.g.
15131528
///
15141529
/// ```swift

branches/master-rebranch/lib/Sema/CSFix.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,3 +773,17 @@ IgnoreContextualType *IgnoreContextualType::create(ConstraintSystem &cs,
773773
return new (cs.getAllocator())
774774
IgnoreContextualType(cs, resultTy, specifiedTy, locator);
775775
}
776+
777+
bool AllowInOutConversion::diagnose(Expr *root, bool asNote) const {
778+
auto &cs = getConstraintSystem();
779+
InOutConversionFailure failure(root, cs, getFromType(), getToType(),
780+
getLocator());
781+
return failure.diagnose(asNote);
782+
}
783+
784+
AllowInOutConversion *AllowInOutConversion::create(ConstraintSystem &cs,
785+
Type argType, Type paramType,
786+
ConstraintLocator *locator) {
787+
return new (cs.getAllocator())
788+
AllowInOutConversion(cs, argType, paramType, locator);
789+
}

0 commit comments

Comments
 (0)