Skip to content

Commit 67e0f74

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 06eb7e4 + 6bf5dae commit 67e0f74

File tree

6 files changed

+53
-46
lines changed

6 files changed

+53
-46
lines changed

include/swift/AST/Decl.h

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ class alignas(1 << DeclAlignInBits) Decl {
676676

677677
Decl(const Decl&) = delete;
678678
void operator=(const Decl&) = delete;
679+
SourceLoc getLocFromSource() const;
679680

680681
protected:
681682

@@ -1582,7 +1583,7 @@ enum class ImportKind : uint8_t {
15821583
class ImportDecl final : public Decl,
15831584
private llvm::TrailingObjects<ImportDecl, std::pair<Identifier,SourceLoc>> {
15841585
friend TrailingObjects;
1585-
1586+
friend class Decl;
15861587
public:
15871588
typedef std::pair<Identifier, SourceLoc> AccessPathElement;
15881589

@@ -1654,7 +1655,7 @@ class ImportDecl final : public Decl,
16541655
}
16551656

16561657
SourceLoc getStartLoc() const { return ImportLoc; }
1657-
SourceLoc getLoc() const { return getFullAccessPath().front().second; }
1658+
SourceLoc getLocFromSource() const { return getFullAccessPath().front().second; }
16581659
SourceRange getSourceRange() const {
16591660
return SourceRange(ImportLoc, getFullAccessPath().back().second);
16601661
}
@@ -1716,6 +1717,7 @@ class ExtensionDecl final : public GenericContext, public Decl,
17161717
std::pair<LazyMemberLoader *, uint64_t> takeConformanceLoaderSlow();
17171718

17181719
friend class ExtendedNominalRequest;
1720+
friend class Decl;
17191721
public:
17201722
using Decl::getASTContext;
17211723

@@ -1728,7 +1730,7 @@ class ExtensionDecl final : public GenericContext, public Decl,
17281730
ClangNode clangNode = ClangNode());
17291731

17301732
SourceLoc getStartLoc() const { return ExtensionLoc; }
1731-
SourceLoc getLoc() const { return ExtensionLoc; }
1733+
SourceLoc getLocFromSource() const { return ExtensionLoc; }
17321734
SourceRange getSourceRange() const {
17331735
return { ExtensionLoc, Braces.End };
17341736
}
@@ -2041,7 +2043,7 @@ class PatternBindingEntry {
20412043
class PatternBindingDecl final : public Decl,
20422044
private llvm::TrailingObjects<PatternBindingDecl, PatternBindingEntry> {
20432045
friend TrailingObjects;
2044-
2046+
friend class Decl;
20452047
SourceLoc StaticLoc; ///< Location of the 'static/class' keyword, if present.
20462048
SourceLoc VarLoc; ///< Location of the 'var' keyword.
20472049

@@ -2050,7 +2052,7 @@ class PatternBindingDecl final : public Decl,
20502052
PatternBindingDecl(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
20512053
SourceLoc VarLoc, unsigned NumPatternEntries,
20522054
DeclContext *Parent);
2053-
2055+
SourceLoc getLocFromSource() const { return VarLoc; }
20542056
public:
20552057
static PatternBindingDecl *create(ASTContext &Ctx, SourceLoc StaticLoc,
20562058
StaticSpellingKind StaticSpelling,
@@ -2080,7 +2082,6 @@ class PatternBindingDecl final : public Decl,
20802082
SourceLoc getStartLoc() const {
20812083
return StaticLoc.isValid() ? StaticLoc : VarLoc;
20822084
}
2083-
SourceLoc getLoc() const { return VarLoc; }
20842085
SourceRange getSourceRange() const;
20852086

20862087
unsigned getNumPatternEntries() const {
@@ -2216,7 +2217,8 @@ class PatternBindingDecl final : public Decl,
22162217
/// global variables.
22172218
class TopLevelCodeDecl : public DeclContext, public Decl {
22182219
BraceStmt *Body;
2219-
2220+
SourceLoc getLocFromSource() const { return getStartLoc(); }
2221+
friend class Decl;
22202222
public:
22212223
TopLevelCodeDecl(DeclContext *Parent, BraceStmt *Body = nullptr)
22222224
: DeclContext(DeclContextKind::TopLevelCodeDecl, Parent),
@@ -2227,7 +2229,6 @@ class TopLevelCodeDecl : public DeclContext, public Decl {
22272229
void setBody(BraceStmt *b) { Body = b; }
22282230

22292231
SourceLoc getStartLoc() const;
2230-
SourceLoc getLoc() const { return getStartLoc(); }
22312232
SourceRange getSourceRange() const;
22322233

22332234
static bool classof(const Decl *D) {
@@ -2266,6 +2267,8 @@ class IfConfigDecl : public Decl {
22662267
/// The array is ASTContext allocated.
22672268
ArrayRef<IfConfigClause> Clauses;
22682269
SourceLoc EndLoc;
2270+
SourceLoc getLocFromSource() const { return Clauses[0].Loc; }
2271+
friend class Decl;
22692272
public:
22702273

22712274
IfConfigDecl(DeclContext *Parent, ArrayRef<IfConfigClause> Clauses,
@@ -2291,7 +2294,6 @@ class IfConfigDecl : public Decl {
22912294
}
22922295

22932296
SourceLoc getEndLoc() const { return EndLoc; }
2294-
SourceLoc getLoc() const { return Clauses[0].Loc; }
22952297

22962298
bool hadMissingEnd() const { return Bits.IfConfigDecl.HadMissingEnd; }
22972299

@@ -2308,7 +2310,8 @@ class PoundDiagnosticDecl : public Decl {
23082310
SourceLoc StartLoc;
23092311
SourceLoc EndLoc;
23102312
StringLiteralExpr *Message;
2311-
2313+
SourceLoc getLocFromSource() const { return StartLoc; }
2314+
friend class Decl;
23122315
public:
23132316
PoundDiagnosticDecl(DeclContext *Parent, bool IsError, SourceLoc StartLoc,
23142317
SourceLoc EndLoc, StringLiteralExpr *Message)
@@ -2337,7 +2340,6 @@ class PoundDiagnosticDecl : public Decl {
23372340
}
23382341

23392342
SourceLoc getEndLoc() const { return EndLoc; };
2340-
SourceLoc getLoc() const { return StartLoc; }
23412343

23422344
SourceRange getSourceRange() const {
23432345
return SourceRange(StartLoc, EndLoc);
@@ -2400,7 +2402,8 @@ class ValueDecl : public Decl {
24002402
friend class IsFinalRequest;
24012403
friend class IsDynamicRequest;
24022404
friend class IsImplicitlyUnwrappedOptionalRequest;
2403-
2405+
friend class Decl;
2406+
SourceLoc getLocFromSource() const { return NameLoc; }
24042407
protected:
24052408
ValueDecl(DeclKind K,
24062409
llvm::PointerUnion<DeclContext *, ASTContext *> context,
@@ -2473,7 +2476,6 @@ class ValueDecl : public Decl {
24732476
bool canInferObjCFromRequirement(ValueDecl *requirement);
24742477

24752478
SourceLoc getNameLoc() const { return NameLoc; }
2476-
SourceLoc getLoc() const { return NameLoc; }
24772479

24782480
bool isUsableFromInline() const;
24792481

@@ -6281,6 +6283,7 @@ AbstractStorageDecl::AccessorRecord::getAccessor(AccessorKind kind) const {
62816283
class EnumCaseDecl final : public Decl,
62826284
private llvm::TrailingObjects<EnumCaseDecl, EnumElementDecl *> {
62836285
friend TrailingObjects;
6286+
friend class Decl;
62846287
SourceLoc CaseLoc;
62856288

62866289
EnumCaseDecl(SourceLoc CaseLoc,
@@ -6293,6 +6296,7 @@ class EnumCaseDecl final : public Decl,
62936296
std::uninitialized_copy(Elements.begin(), Elements.end(),
62946297
getTrailingObjects<EnumElementDecl *>());
62956298
}
6299+
SourceLoc getLocFromSource() const { return CaseLoc; }
62966300

62976301
public:
62986302
static EnumCaseDecl *create(SourceLoc CaseLoc,
@@ -6304,11 +6308,6 @@ class EnumCaseDecl final : public Decl,
63046308
return {getTrailingObjects<EnumElementDecl *>(),
63056309
Bits.EnumCaseDecl.NumElements};
63066310
}
6307-
6308-
SourceLoc getLoc() const {
6309-
return CaseLoc;
6310-
}
6311-
63126311
SourceRange getSourceRange() const;
63136312

63146313
static bool classof(const Decl *D) {
@@ -6721,7 +6720,8 @@ class PrecedenceGroupDecl : public Decl {
67216720
SourceLoc higherThanLoc, ArrayRef<Relation> higherThan,
67226721
SourceLoc lowerThanLoc, ArrayRef<Relation> lowerThan,
67236722
SourceLoc rbraceLoc);
6724-
6723+
friend class Decl;
6724+
SourceLoc getLocFromSource() const { return NameLoc; }
67256725
public:
67266726
static PrecedenceGroupDecl *create(DeclContext *dc,
67276727
SourceLoc precedenceGroupLoc,
@@ -6741,7 +6741,6 @@ class PrecedenceGroupDecl : public Decl {
67416741
SourceLoc rbraceLoc);
67426742

67436743

6744-
SourceLoc getLoc() const { return NameLoc; }
67456744
SourceRange getSourceRange() const {
67466745
return { PrecedenceGroupLoc, RBraceLoc };
67476746
}
@@ -6860,7 +6859,8 @@ class OperatorDecl : public Decl {
68606859
ArrayRef<Identifier> Identifiers;
68616860
ArrayRef<SourceLoc> IdentifierLocs;
68626861
ArrayRef<NominalTypeDecl *> DesignatedNominalTypes;
6863-
6862+
SourceLoc getLocFromSource() const { return NameLoc; }
6863+
friend class Decl;
68646864
public:
68656865
OperatorDecl(DeclKind kind, DeclContext *DC, SourceLoc OperatorLoc,
68666866
Identifier Name, SourceLoc NameLoc,
@@ -6875,7 +6875,6 @@ class OperatorDecl : public Decl {
68756875
: Decl(kind, DC), OperatorLoc(OperatorLoc), NameLoc(NameLoc), name(Name),
68766876
DesignatedNominalTypes(DesignatedNominalTypes) {}
68776877

6878-
SourceLoc getLoc() const { return NameLoc; }
68796878

68806879
SourceLoc getOperatorLoc() const { return OperatorLoc; }
68816880
SourceLoc getNameLoc() const { return NameLoc; }
@@ -7038,6 +7037,10 @@ class MissingMemberDecl : public Decl {
70387037
&& "not enough bits");
70397038
setImplicit();
70407039
}
7040+
friend class Decl;
7041+
SourceLoc getLocFromSource() const {
7042+
return SourceLoc();
7043+
}
70417044
public:
70427045
static MissingMemberDecl *
70437046
create(ASTContext &ctx, DeclContext *DC, DeclName name,
@@ -7062,10 +7065,6 @@ class MissingMemberDecl : public Decl {
70627065
return Bits.MissingMemberDecl.NumberOfFieldOffsetVectorEntries;
70637066
}
70647067

7065-
SourceLoc getLoc() const {
7066-
return SourceLoc();
7067-
}
7068-
70697068
SourceRange getSourceRange() const {
70707069
return SourceRange();
70717070
}

lib/AST/Decl.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,18 +470,26 @@ SourceRange Decl::getSourceRangeIncludingAttrs() const {
470470
return Range;
471471
}
472472

473-
SourceLoc Decl::getLoc() const {
473+
SourceLoc Decl::getLocFromSource() const {
474474
switch (getKind()) {
475475
#define DECL(ID, X) \
476-
static_assert(sizeof(checkSourceLocType(&ID##Decl::getLoc)) == 1, \
477-
#ID "Decl is missing getLoc()"); \
478-
case DeclKind::ID: return cast<ID##Decl>(this)->getLoc();
476+
static_assert(sizeof(checkSourceLocType(&ID##Decl::getLocFromSource)) == 1, \
477+
#ID "Decl is missing getLocFromSource()"); \
478+
case DeclKind::ID: return cast<ID##Decl>(this)->getLocFromSource();
479479
#include "swift/AST/DeclNodes.def"
480480
}
481481

482482
llvm_unreachable("Unknown decl kind");
483483
}
484484

485+
SourceLoc Decl::getLoc() const {
486+
#define DECL(ID, X) \
487+
static_assert(sizeof(checkSourceLocType(&ID##Decl::getLoc)) == 2, \
488+
#ID "Decl is re-defining getLoc()");
489+
#include "swift/AST/DeclNodes.def"
490+
return getLocFromSource();
491+
}
492+
485493
Expr *AbstractFunctionDecl::getSingleExpressionBody() const {
486494
assert(hasSingleExpressionBody() && "Not a single-expression body");
487495
auto braceStmt = getBody();

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -837,20 +837,20 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
837837
const auto &param = Parameters[paramIdx];
838838

839839
unsigned newArgIdx = Arguments.size();
840-
auto argLoc =
840+
auto *argLoc = CS.getConstraintLocator(
841841
Locator
842842
.withPathElement(LocatorPathElt::ApplyArgToParam(
843843
newArgIdx, paramIdx, param.getParameterFlags()))
844-
.withPathElement(LocatorPathElt::SynthesizedArgument(newArgIdx));
844+
.withPathElement(LocatorPathElt::SynthesizedArgument(newArgIdx)));
845845

846-
auto *argType = CS.createTypeVariable(
847-
CS.getConstraintLocator(argLoc),
848-
TVO_CanBindToInOut | TVO_CanBindToLValue | TVO_CanBindToNoEscape);
846+
auto *argType =
847+
CS.createTypeVariable(argLoc, TVO_CanBindToInOut | TVO_CanBindToLValue |
848+
TVO_CanBindToNoEscape);
849849

850850
CS.recordHole(argType);
851-
CS.addUnsolvedConstraint(Constraint::create(
852-
CS, ConstraintKind::Defaultable, argType, CS.getASTContext().TheAnyType,
853-
CS.getConstraintLocator(argLoc)));
851+
CS.addUnsolvedConstraint(
852+
Constraint::create(CS, ConstraintKind::Defaultable, argType,
853+
CS.getASTContext().TheAnyType, argLoc));
854854

855855
Arguments.push_back(param.withType(argType));
856856
++NumSynthesizedArgs;

test/Driver/advanced_output_file_map.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
// DUMPOFM-NEXT: {{.*}}/advanced_output_file_map.swift -> swiftdoc: "/build/swiftmodule/advanced_output_file_map_x.swiftdoc"
2020
// DUMPOFM-NEXT: {{.*}}/advanced_output_file_map.swift -> diagnostics: "/build/dia/advanced_output_file_map.dia"
2121

22-
// BINDINGS: # "x86_64-apple-macosx10.9" - "swift{{c?(\.EXE)?}}", inputs: ["{{.*}}/advanced_output_file_map.swift"], output: {object: "/build/obj/advanced_output_file_map.o", dependencies: "/build/d/advanced_output_file_map.d", swiftmodule: "/build/swiftmodule/advanced_output_file_map.swiftmodule", swiftdoc: "/build/swiftmodule/advanced_output_file_map_x.swiftdoc", swiftsourceinfo: "/build/swiftmodule/advanced_output_file_map.swiftsourceinfo", diagnostics: "/build/dia/advanced_output_file_map.dia"}
23-
// BINDINGS: # "x86_64-apple-macosx10.9" - "swift{{c?(\.EXE)?}}", inputs: ["{{.*}}/Inputs/main.swift"], output: {object: "/build/obj/main.o", dependencies: "/build/d/main.d", swiftmodule: "/build/swiftmodule/main.swiftmodule", swiftdoc: "/build/swiftmodule/main_x.swiftdoc", swiftsourceinfo: "/build/swiftmodule/main.swiftsourceinfo", diagnostics: "/build/dia/main.dia"}
24-
// BINDINGS: # "x86_64-apple-macosx10.9" - "swift{{c?(\.EXE)?}}", inputs: ["{{.*}}/Inputs/lib.swift"], output: {object: "/build/obj/lib.o", dependencies: "/build/d/lib.d", swiftmodule: "/build/swiftmodule/lib.swiftmodule", swiftdoc: "/build/swiftmodule/lib_x.swiftdoc", swiftsourceinfo: "/build/swiftmodule/lib.swiftsourceinfo", diagnostics: "/build/dia/lib.dia"}
25-
// BINDINGS: # "x86_64-apple-macosx10.9" - "swift{{c?(\.EXE)?}}", inputs: ["/build/obj/advanced_output_file_map.o", "/build/obj/main.o", "/build/obj/lib.o"], output: {swiftmodule: "/build/OutputFileMap.swiftmodule", swiftdoc: "/build/OutputFileMap.swiftdoc", swiftsourceinfo: "/build/OutputFileMap.swiftsourceinfo"}
22+
// BINDINGS: # "x86_64-apple-macosx10.9" - "swift{{c?(\.EXE)?}}", inputs: ["{{.*}}/advanced_output_file_map.swift"], output: {object: "/build/obj/advanced_output_file_map.o", dependencies: "/build/d/advanced_output_file_map.d", swiftmodule: "/build/swiftmodule/advanced_output_file_map.swiftmodule", swiftdoc: "/build/swiftmodule/advanced_output_file_map_x.swiftdoc", swiftsourceinfo: "/build/swiftmodule{{[/\\]}}advanced_output_file_map.swiftsourceinfo", diagnostics: "/build/dia/advanced_output_file_map.dia"}
23+
// BINDINGS: # "x86_64-apple-macosx10.9" - "swift{{c?(\.EXE)?}}", inputs: ["{{.*}}/Inputs/main.swift"], output: {object: "/build/obj/main.o", dependencies: "/build/d/main.d", swiftmodule: "/build/swiftmodule/main.swiftmodule", swiftdoc: "/build/swiftmodule/main_x.swiftdoc", swiftsourceinfo: "/build/swiftmodule{{[/\\]}}main.swiftsourceinfo", diagnostics: "/build/dia/main.dia"}
24+
// BINDINGS: # "x86_64-apple-macosx10.9" - "swift{{c?(\.EXE)?}}", inputs: ["{{.*}}/Inputs/lib.swift"], output: {object: "/build/obj/lib.o", dependencies: "/build/d/lib.d", swiftmodule: "/build/swiftmodule/lib.swiftmodule", swiftdoc: "/build/swiftmodule/lib_x.swiftdoc", swiftsourceinfo: "/build/swiftmodule{{[/\\]}}lib.swiftsourceinfo", diagnostics: "/build/dia/lib.dia"}
25+
// BINDINGS: # "x86_64-apple-macosx10.9" - "swift{{c?(\.EXE)?}}", inputs: ["/build/obj/advanced_output_file_map.o", "/build/obj/main.o", "/build/obj/lib.o"], output: {swiftmodule: "/build/OutputFileMap.swiftmodule", swiftdoc: "/build/OutputFileMap.swiftdoc", swiftsourceinfo: "/build{{[/\\]}}OutputFileMap.swiftsourceinfo"}
2626
// BINDINGS: # "x86_64-apple-macosx10.9" - "ld{{(.exe)?}}", inputs: ["/build/obj/advanced_output_file_map.o", "/build/obj/main.o", "/build/obj/lib.o", "/build/OutputFileMap.swiftmodule"], output: {image: "/build/advanced_output_file_map.out"}
2727
// BINDINGS: # "x86_64-apple-macosx10.9" - "dsymutil{{(\.exe)?}}", inputs: ["/build/advanced_output_file_map.out"], output: {dSYM: "/build/advanced_output_file_map.out.dSYM"}

test/Driver/merge-module.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
// MERGE_1: -o [[PARTIAL_MODULE_B]].swiftmodule
9494
// MERGE_1: {{bin(/|\\\\)swiftc?(\.EXE)?"?}} -frontend -merge-modules -emit-module [[PARTIAL_MODULE_A]].swiftmodule{{"?}} [[PARTIAL_MODULE_B]].swiftmodule
9595
// MERGE_1: -parse-as-library
96-
// MERGE_1: -emit-module-doc-path /tmp/modules.swiftdoc
96+
// MERGE_1: -emit-module-doc-path /tmp{{(/|\\\\)}}modules.swiftdoc
9797
// MERGE_1: -module-name merge
9898
// MERGE_1: -o /tmp/modules
9999

test/Driver/sourceinfo_file.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// RUN: mkdir -p %t/build/Private
33
// RUN: %swiftc_driver -driver-print-jobs -emit-module %s -emit-module-path %t/build/sourceinfo_file.swiftmodule -module-name sourceinfo_file | %FileCheck %s -check-prefix CHECK-PRIVATE
44

5-
// CHECK-PRIVATE: build/Private/sourceinfo_file.swiftsourceinfo
5+
// CHECK-PRIVATE: build{{[/\\]}}Private{{[/\\]}}sourceinfo_file.swiftsourceinfo
66

77
// RUN: %empty-directory(%t/build)
88
// RUN: %swiftc_driver -driver-print-jobs -emit-module %s -emit-module-path %t/build/sourceinfo_file.swiftmodule -module-name sourceinfo_file | %FileCheck %s -check-prefix CHECK-NOPRIVATE
99

1010
// CHECK-NOPRIVATE-NOT: Private/sourceinfo_file.swiftsourceinfo
11-
// CHECK-NOPRIVATE: build/sourceinfo_file.swiftsourceinfo
11+
// CHECK-NOPRIVATE: build{{[/\\]}}sourceinfo_file.swiftsourceinfo
1212

1313
// RUN: %empty-directory(%t/build)
1414
// RUN: %swiftc_driver -driver-print-jobs -emit-module %s -emit-module-path %t/build/sourceinfo_file.swiftmodule -module-name sourceinfo_file -emit-module-source-info-path %t/build/DriverPath.swiftsourceinfo | %FileCheck %s -check-prefix CHECK-DRIVER-OPT
1515

16-
// CHECK-DRIVER-OPT: build/DriverPath.swiftsourceinfo
16+
// CHECK-DRIVER-OPT: build{{[/\\]}}DriverPath.swiftsourceinfo

0 commit comments

Comments
 (0)