Skip to content

Commit 5d1eeac

Browse files
Resolving conflicts
2 parents 638d702 + eb0b307 commit 5d1eeac

File tree

127 files changed

+1513
-861
lines changed

Some content is hidden

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

127 files changed

+1513
-861
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ CHANGELOG
2626
Swift 5.2
2727
---------
2828

29+
* [SR-2189][]:
30+
31+
The compiler now supports local functions whose default arguments capture
32+
values from outer scopes.
33+
34+
```swift
35+
func outer(x: Int) -> (Int, Int) {
36+
func inner(y: Int = x) -> Int {
37+
return y
38+
}
39+
40+
return (inner(), inner(y: 0))
41+
}
42+
```
43+
2944
* [SR-11429][]:
3045

3146
The compiler will now correctly strip argument labels from function references
@@ -7803,6 +7818,7 @@ Swift 1.0
78037818
[SR-1529]: <https://bugs.swift.org/browse/SR-1529>
78047819
[SR-2131]: <https://bugs.swift.org/browse/SR-2131>
78057820
[SR-2176]: <https://bugs.swift.org/browse/SR-2176>
7821+
[SR-2189]: <https://bugs.swift.org/browse/SR-2189>
78067822
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
78077823
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
78087824
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>

cmake/modules/SwiftHandleGybSources.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
121121
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/DeclNodes.py"
122122
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/ExprNodes.py"
123123
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/GenericNodes.py"
124+
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/NodeSerializationCodes.py"
124125
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/PatternNodes.py"
125126
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/StmtNodes.py"
126127
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/TypeNodes.py"

include/swift/AST/Decl.h

-4
Original file line numberDiff line numberDiff line change
@@ -5834,10 +5834,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
58345834
}
58355835

58365836
public:
5837-
/// Compute the interface type of this function declaration from the
5838-
/// parameter types.
5839-
void computeType(AnyFunctionType::ExtInfo Info = FunctionType::ExtInfo());
5840-
58415837
/// Retrieve the source range of the function body.
58425838
SourceRange getBodySourceRange() const;
58435839

include/swift/AST/DiagnosticsSIL.def

+13-4
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,33 @@ ERROR(capture_before_declaration_defer,none,
130130
NOTE(captured_value_declared_here,none,
131131
"captured value declared here", ())
132132

133+
#define SELECT_ESCAPING_CLOSURE_KIND "escaping %select{local function|closure}0"
134+
133135
// Invalid escaping capture diagnostics.
134136
ERROR(escaping_inout_capture,none,
135-
"escaping closure captures 'inout' parameter %0", (Identifier))
137+
SELECT_ESCAPING_CLOSURE_KIND
138+
" captures 'inout' parameter %1",
139+
(unsigned, Identifier))
136140
NOTE(inout_param_defined_here,none,
137141
"parameter %0 is declared 'inout'", (Identifier))
138142
ERROR(escaping_mutable_self_capture,none,
139-
"escaping closure captures mutating 'self' parameter", ())
143+
SELECT_ESCAPING_CLOSURE_KIND
144+
" captures mutating 'self' parameter", (unsigned))
140145

141146
ERROR(escaping_noescape_param_capture,none,
142-
"escaping closure captures non-escaping parameter %0", (Identifier))
147+
SELECT_ESCAPING_CLOSURE_KIND
148+
" captures non-escaping parameter %1", (unsigned, Identifier))
143149
NOTE(noescape_param_defined_here,none,
144150
"parameter %0 is implicitly non-escaping", (Identifier))
145151

146152
ERROR(escaping_noescape_var_capture,none,
147-
"escaping closure captures non-escaping value", ())
153+
SELECT_ESCAPING_CLOSURE_KIND
154+
" captures non-escaping value", (unsigned))
148155

149156
NOTE(value_captured_here,none,"captured here", ())
150157

158+
#undef SELECT_ESCAPING_CLOSURE_KIND
159+
151160
NOTE(value_captured_transitively,none,
152161
"captured indirectly by this call", ())
153162

include/swift/AST/DiagnosticsSema.def

+5
Original file line numberDiff line numberDiff line change
@@ -3401,6 +3401,11 @@ ERROR(unresolved_label_corrected,none,
34013401
"use of unresolved label %0; did you mean %1?",
34023402
(Identifier, Identifier))
34033403

3404+
ERROR(foreach_sequence_does_not_conform_to_expected_protocol,none,
3405+
"for-in loop requires %0 to conform to %1"
3406+
"%select{|; did you mean to unwrap optional?}2",
3407+
(Type, Type, bool))
3408+
34043409
// Switch Stmt
34053410
ERROR(no_match_operator,none,
34063411
"no binary '~=' operator available for 'switch' statement", ())

include/swift/AST/IndexSubset.h

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class IndexSubset : public llvm::FoldingSetNode {
5757
/// The number of bit words in the index subset.
5858
unsigned numBitWords;
5959

60+
static unsigned getNumBytesNeededForCapacity(unsigned capacity) {
61+
return getNumBitWordsNeededForCapacity(capacity) * bitWordSize;
62+
}
63+
6064
BitWord *getBitWordsData() {
6165
return reinterpret_cast<BitWord *>(this + 1);
6266
}

include/swift/Frontend/Frontend.h

+13-19
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ namespace Lowering {
6060
class TypeConverter;
6161
}
6262

63+
struct ModuleBuffers {
64+
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
65+
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
66+
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
67+
ModuleBuffers(std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer,
68+
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer = nullptr,
69+
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer = nullptr):
70+
ModuleBuffer(std::move(ModuleBuffer)),
71+
ModuleDocBuffer(std::move(ModuleDocBuffer)),
72+
ModuleSourceInfoBuffer(std::move(ModuleSourceInfoBuffer)) {}
73+
};
74+
6375
/// The abstract configuration of the compiler, including:
6476
/// - options for all stages of translation,
6577
/// - information about the build environment,
@@ -392,15 +404,9 @@ class CompilerInstance {
392404
/// Contains buffer IDs for input source code files.
393405
std::vector<unsigned> InputSourceCodeBufferIDs;
394406

395-
struct PartialModuleInputs {
396-
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
397-
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
398-
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
399-
};
400-
401407
/// Contains \c MemoryBuffers for partial serialized module files and
402408
/// corresponding partial serialized module documentation files.
403-
std::vector<PartialModuleInputs> PartialModules;
409+
std::vector<ModuleBuffers> PartialModules;
404410

405411
enum : unsigned { NO_SUCH_BUFFER = ~0U };
406412
unsigned MainBufferID = NO_SUCH_BUFFER;
@@ -556,18 +562,6 @@ class CompilerInstance {
556562

557563
Optional<unsigned> getRecordedBufferID(const InputFile &input, bool &failed);
558564

559-
struct ModuleBuffers {
560-
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
561-
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
562-
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
563-
ModuleBuffers(std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer,
564-
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer = nullptr,
565-
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer = nullptr):
566-
ModuleBuffer(std::move(ModuleBuffer)),
567-
ModuleDocBuffer(std::move(ModuleDocBuffer)),
568-
ModuleSourceInfoBuffer(std::move(ModuleSourceInfoBuffer)) {}
569-
};
570-
571565
/// Given an input file, return a buffer to use for its contents,
572566
/// and a buffer for the corresponding module doc file if one exists.
573567
/// On failure, return a null pointer for the first element of the returned

include/swift/Parse/ParsedRawSyntaxNode.h

+36-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ParsedRawSyntaxNode {
5252
};
5353
struct DeferredLayoutNode {
5454
MutableArrayRef<ParsedRawSyntaxNode> Children;
55+
CharSourceRange Range;
5556
};
5657
struct DeferredTokenNode {
5758
const ParsedTriviaPiece *TriviaPieces;
@@ -72,9 +73,9 @@ class ParsedRawSyntaxNode {
7273
/// Primary used for capturing a deferred missing token.
7374
bool IsMissing = false;
7475

75-
ParsedRawSyntaxNode(syntax::SyntaxKind k,
76+
ParsedRawSyntaxNode(syntax::SyntaxKind k, CharSourceRange r,
7677
MutableArrayRef<ParsedRawSyntaxNode> deferredNodes)
77-
: DeferredLayout({deferredNodes}),
78+
: DeferredLayout({deferredNodes, r}),
7879
SynKind(uint16_t(k)), TokKind(uint16_t(tok::unknown)),
7980
DK(DataKind::DeferredLayout) {
8081
assert(getKind() == k && "Syntax kind with too large value!");
@@ -109,10 +110,12 @@ class ParsedRawSyntaxNode {
109110
}
110111

111112
ParsedRawSyntaxNode(syntax::SyntaxKind k, tok tokKind,
112-
CharSourceRange r, OpaqueSyntaxNode n)
113+
CharSourceRange r, OpaqueSyntaxNode n,
114+
bool IsMissing = false)
113115
: RecordedData{n, r},
114116
SynKind(uint16_t(k)), TokKind(uint16_t(tokKind)),
115-
DK(DataKind::Recorded) {
117+
DK(DataKind::Recorded),
118+
IsMissing(IsMissing) {
116119
assert(getKind() == k && "Syntax kind with too large value!");
117120
assert(getTokenKind() == tokKind && "Token kind with too large value!");
118121
}
@@ -209,9 +212,20 @@ class ParsedRawSyntaxNode {
209212
return copy;
210213
}
211214

215+
CharSourceRange getDeferredRange() const {
216+
switch (DK) {
217+
case DataKind::DeferredLayout:
218+
return getDeferredLayoutRange();
219+
case DataKind::DeferredToken:
220+
return getDeferredTokenRangeWithTrivia();
221+
default:
222+
llvm_unreachable("node not deferred");
223+
}
224+
}
225+
212226
// Recorded Data ===========================================================//
213227

214-
CharSourceRange getRange() const {
228+
CharSourceRange getRecordedRange() const {
215229
assert(isRecorded());
216230
return RecordedData.Range;
217231
}
@@ -228,6 +242,10 @@ class ParsedRawSyntaxNode {
228242

229243
// Deferred Layout Data ====================================================//
230244

245+
CharSourceRange getDeferredLayoutRange() const {
246+
assert(DK == DataKind::DeferredLayout);
247+
return DeferredLayout.Range;
248+
}
231249
ArrayRef<ParsedRawSyntaxNode> getDeferredChildren() const {
232250
assert(DK == DataKind::DeferredLayout);
233251
return DeferredLayout.Children;
@@ -259,6 +277,19 @@ class ParsedRawSyntaxNode {
259277

260278
// Deferred Token Data =====================================================//
261279

280+
CharSourceRange getDeferredTokenRangeWithTrivia() const {
281+
assert(DK == DataKind::DeferredToken);
282+
auto leadTriviaPieces = getDeferredLeadingTriviaPieces();
283+
auto trailTriviaPieces = getDeferredTrailingTriviaPieces();
284+
285+
auto leadTriviaLen = ParsedTriviaPiece::getTotalLength(leadTriviaPieces);
286+
auto trailTriviaLen = ParsedTriviaPiece::getTotalLength(trailTriviaPieces);
287+
288+
SourceLoc begin = DeferredToken.TokLoc.getAdvancedLoc(-leadTriviaLen);
289+
unsigned len = leadTriviaLen + DeferredToken.TokLength + trailTriviaLen;
290+
291+
return CharSourceRange{begin, len};
292+
}
262293
CharSourceRange getDeferredTokenRange() const {
263294
assert(DK == DataKind::DeferredToken);
264295
return CharSourceRange{DeferredToken.TokLoc, DeferredToken.TokLength};

include/swift/Parse/ParsedRawSyntaxRecorder.h

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class ParsedRawSyntaxRecorder {
7373
/// Used for incremental re-parsing.
7474
ParsedRawSyntaxNode lookupNode(size_t lexerOffset, SourceLoc loc,
7575
syntax::SyntaxKind kind);
76+
77+
#ifndef NDEBUG
78+
static void verifyElementRanges(ArrayRef<ParsedRawSyntaxNode> elements);
79+
#endif
7680
};
7781

7882
} // end namespace swift

include/swift/Parse/ParsedSyntaxBuilders.h.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public:
6262
% end
6363

6464
Parsed${node.name} build();
65-
Parsed${node.name} makeDeferred();
6665

6766
private:
67+
Parsed${node.name} makeDeferred();
6868
Parsed${node.name} record();
6969
void finishLayout(bool deferred);
7070
};

include/swift/Parse/ParsedSyntaxRecorder.h.gyb

+6-7
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,22 @@ struct ParsedSyntaxRecorder {
4343
% end
4444
% child_params = ', '.join(child_params)
4545
private:
46-
static Parsed${node.name} record${node.syntax_kind}(${child_params},
46+
static Parsed${node.name} record${node.syntax_kind}(MutableArrayRef<ParsedRawSyntaxNode> layout,
4747
ParsedRawSyntaxRecorder &rec);
48-
public:
49-
static Parsed${node.name} defer${node.syntax_kind}(${child_params},
48+
static Parsed${node.name} defer${node.syntax_kind}(MutableArrayRef<ParsedRawSyntaxNode> layout,
5049
SyntaxParsingContext &SPCtx);
50+
public:
5151
static Parsed${node.name} make${node.syntax_kind}(${child_params},
5252
SyntaxParsingContext &SPCtx);
5353
% elif node.is_syntax_collection():
5454
private:
5555
static Parsed${node.name} record${node.syntax_kind}(
56-
MutableArrayRef<Parsed${node.collection_element_type}> elts,
56+
MutableArrayRef<ParsedRawSyntaxNode> layout,
5757
ParsedRawSyntaxRecorder &rec);
58-
59-
public:
6058
static Parsed${node.name} defer${node.syntax_kind}(
61-
MutableArrayRef<Parsed${node.collection_element_type}> elts,
59+
MutableArrayRef<ParsedRawSyntaxNode> layout,
6260
SyntaxParsingContext &SPCtx);
61+
public:
6362
static Parsed${node.name} make${node.syntax_kind}(
6463
MutableArrayRef<Parsed${node.collection_element_type}> elts,
6564
SyntaxParsingContext &SPCtx);

include/swift/Parse/Parser.h

+4
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ class Parser {
532532
return consumeToken();
533533
}
534534

535+
SourceLoc leadingTriviaLoc() {
536+
return Tok.getLoc().getAdvancedLoc(-LeadingTrivia.getLength());
537+
}
538+
535539
SourceLoc consumeIdentifier(Identifier *Result = nullptr,
536540
bool allowDollarIdentifier = false) {
537541
assert(Tok.isAny(tok::identifier, tok::kw_self, tok::kw_Self));

include/swift/Remote/MetadataReader.h

+7
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,13 @@ class MetadataReader {
26132613
if (!Reader->readInteger(RemoteAddress(dataPtr + OffsetToROPtr), &dataPtr))
26142614
return StoredPointer();
26152615

2616+
// Newer Objective-C runtimes implement a size optimization where the RO
2617+
// field is a tagged union. If the low-bit is set, then the pointer needs
2618+
// to be dereferenced once more to yield the real class_ro_t pointer.
2619+
if (dataPtr & 1)
2620+
if (!Reader->readInteger(RemoteAddress(dataPtr^1), &dataPtr))
2621+
return StoredPointer();
2622+
26162623
return dataPtr;
26172624
}
26182625

include/swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h

+19-8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class CalleeList {
5454
: CalleeFunctions(llvm::makeArrayRef(List.begin(), List.end())),
5555
IsIncomplete(IsIncomplete) {}
5656

57+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
58+
"Only for use in the debugger");
59+
60+
void print(llvm::raw_ostream &os) const;
61+
5762
/// Return an iterator for the beginning of the list.
5863
ArrayRef<SILFunction *>::iterator begin() const {
5964
return CalleeFunctions.begin();
@@ -67,7 +72,7 @@ class CalleeList {
6772
bool isIncomplete() const { return IsIncomplete; }
6873

6974
/// Returns true if all callees are known and not external.
70-
bool allCalleesVisible();
75+
bool allCalleesVisible() const;
7176
};
7277

7378
/// CalleeCache is a helper class that builds lists of potential
@@ -106,16 +111,16 @@ class CalleeCache {
106111
/// given instruction. E.g. it could be destructors.
107112
CalleeList getCalleeList(SILInstruction *I) const;
108113

114+
CalleeList getCalleeList(SILDeclRef Decl) const;
115+
109116
private:
110117
void enumerateFunctionsInModule();
111118
void sortAndUniqueCallees();
112119
CalleesAndCanCallUnknown &getOrCreateCalleesForMethod(SILDeclRef Decl);
113-
void computeClassMethodCalleesForClass(ClassDecl *CD);
114-
void computeClassMethodCallees(ClassDecl *CD, SILDeclRef Method);
120+
void computeClassMethodCallees();
115121
void computeWitnessMethodCalleesForWitnessTable(SILWitnessTable &WT);
116122
void computeMethodCallees();
117123
SILFunction *getSingleCalleeForWitnessMethod(WitnessMethodInst *WMI) const;
118-
CalleeList getCalleeList(SILDeclRef Decl) const;
119124
CalleeList getCalleeList(WitnessMethodInst *WMI) const;
120125
CalleeList getCalleeList(ClassMethodInst *CMI) const;
121126
CalleeList getCalleeListForCalleeKind(SILValue Callee) const;
@@ -162,17 +167,23 @@ class BasicCalleeAnalysis : public SILAnalysis {
162167
Cache.reset();
163168
}
164169

165-
CalleeList getCalleeList(FullApplySite FAS) {
170+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
171+
"Only for use in the debugger");
172+
173+
void print(llvm::raw_ostream &os) const;
174+
175+
void updateCache() {
166176
if (!Cache)
167177
Cache = llvm::make_unique<CalleeCache>(M);
178+
}
168179

180+
CalleeList getCalleeList(FullApplySite FAS) {
181+
updateCache();
169182
return Cache->getCalleeList(FAS);
170183
}
171184

172185
CalleeList getCalleeList(SILInstruction *I) {
173-
if (!Cache)
174-
Cache = llvm::make_unique<CalleeCache>(M);
175-
186+
updateCache();
176187
return Cache->getCalleeList(I);
177188
}
178189
};

0 commit comments

Comments
 (0)