Skip to content

Commit 3ad073a

Browse files
Merge pull request #2727 from swiftwasm/main
[pull] swiftwasm from main
2 parents e368e9d + 55199f5 commit 3ad073a

File tree

95 files changed

+1737
-652
lines changed

Some content is hidden

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

95 files changed

+1737
-652
lines changed

CMakeLists.txt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(CMAKE_CXX_EXTENSIONS NO)
5050
# First include general CMake utilities.
5151
include(SwiftUtils)
5252
include(CheckSymbolExists)
53+
include(CMakeDependentOption)
5354

5455
#
5556
# User-configurable options that control the inclusion and default build
@@ -411,6 +412,24 @@ option(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
411412
"Enable experimental Swift concurrency model"
412413
FALSE)
413414

415+
option(SWIFT_ENABLE_DISPATCH
416+
"Enable use of libdispatch"
417+
TRUE)
418+
419+
cmake_dependent_option(SWIFT_BUILD_SYNTAXPARSERLIB
420+
"Build the Swift Syntax Parser library" TRUE
421+
"SWIFT_ENABLE_DISPATCH" FALSE)
422+
cmake_dependent_option(SWIFT_BUILD_ONLY_SYNTAXPARSERLIB
423+
"Only build the Swift Syntax Parser library" FALSE
424+
"SWIFT_BUILD_SYNTAXPARSERLIB" FALSE)
425+
426+
cmake_dependent_option(SWIFT_BUILD_SOURCEKIT
427+
"Build SourceKit" TRUE
428+
"SWIFT_ENABLE_DISPATCH" FALSE)
429+
cmake_dependent_option(SWIFT_ENABLE_SOURCEKIT_TESTS
430+
"Enable running SourceKit tests" TRUE
431+
"SWIFT_BUILD_SOURCEKIT" FALSE)
432+
414433
#
415434
# End of user-configurable options.
416435
#
@@ -434,11 +453,6 @@ if(CMAKE_C_COMPILER_ID MATCHES Clang)
434453
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Werror=gnu>)
435454
endif()
436455

437-
option(SWIFT_BUILD_SYNTAXPARSERLIB "Build the Swift Syntax Parser library" TRUE)
438-
option(SWIFT_BUILD_ONLY_SYNTAXPARSERLIB "Only build the Swift Syntax Parser library" FALSE)
439-
option(SWIFT_BUILD_SOURCEKIT "Build SourceKit" TRUE)
440-
option(SWIFT_ENABLE_SOURCEKIT_TESTS "Enable running SourceKit tests" ${SWIFT_BUILD_SOURCEKIT})
441-
442456
# Use dispatch as the system scheduler by default.
443457
# For convenience, we set this to false when concurrency is disabled.
444458
set(SWIFT_CONCURRENCY_USES_DISPATCH FALSE)
@@ -447,14 +461,12 @@ if(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY AND NOT SWIFT_STDLIB_SINGLE_THREADED_RU
447461
endif()
448462

449463
set(SWIFT_BUILD_HOST_DISPATCH FALSE)
450-
if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
451-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
464+
if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
465+
if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
452466
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
453467
endif()
454-
endif()
455468

456-
if(SWIFT_BUILD_HOST_DISPATCH OR SWIFT_CONCURRENCY_USES_DISPATCH)
457-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
469+
if(SWIFT_BUILD_HOST_DISPATCH OR SWIFT_CONCURRENCY_USES_DISPATCH)
458470
if(NOT EXISTS "${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}")
459471
message(SEND_ERROR "SyntaxParserLib, SourceKit, and concurrency require libdispatch on non-Darwin hosts. Please specify SWIFT_PATH_TO_LIBDISPATCH_SOURCE")
460472
endif()
@@ -996,7 +1008,9 @@ if (LLVM_ENABLE_DOXYGEN)
9961008
message(STATUS "Doxygen: enabled")
9971009
endif()
9981010

999-
include(Libdispatch)
1011+
if(SWIFT_ENABLE_DISPATCH)
1012+
include(Libdispatch)
1013+
endif()
10001014

10011015
# Add all of the subdirectories, where we actually do work.
10021016

docs/ABI/Mangling.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ types where the metadata itself has unknown layout.)
220220
global ::= global 'Tm' // merged function
221221
global ::= entity // some identifiable thing
222222
global ::= from-type to-type generic-signature? 'TR' // reabstraction thunk
223-
global ::= from-type to-type generic-signature? 'TR' // reabstraction thunk
224223
global ::= impl-function-type type 'Tz' // objc-to-swift-async completion handler block implementation
225224
global ::= impl-function-type type 'TZ' // objc-to-swift-async completion handler block implementation (predefined by runtime)
226225
global ::= from-type to-type self-type generic-signature? 'Ty' // reabstraction thunk with dynamic 'Self' capture
@@ -230,6 +229,9 @@ types where the metadata itself has unknown layout.)
230229
global ::= type generic-signature 'TH' // key path equality
231230
global ::= type generic-signature 'Th' // key path hasher
232231
global ::= global generic-signature? 'TJ' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // autodiff function
232+
global ::= from-type to-type 'TJO' AUTODIFF-FUNCTION-KIND // autodiff self-reordering reabstraction thunk
233+
global ::= from-type 'TJS' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' INDEX-SUBSET 'P' // autodiff linear map subset parameters thunk
234+
global ::= global to-type 'TJS' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' INDEX-SUBSET 'P' // autodiff derivative function subset parameters thunk
233235

234236
global ::= protocol 'TL' // protocol requirements base descriptor
235237
global ::= assoc-type-name 'Tl' // associated type descriptor

include/swift/AST/ASTMangler.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ class ASTMangler : public Mangler {
192192
AutoDiffLinearMapKind kind,
193193
AutoDiffConfig config);
194194

195+
/// Mangle the linear map self parameter reordering thunk the given:
196+
/// - Mangled original function declaration.
197+
/// - Linear map kind.
198+
/// - Derivative function configuration: parameter/result indices and
199+
/// derivative generic signature.
200+
std::string mangleAutoDiffSelfReorderingReabstractionThunk(
201+
CanType fromType, CanType toType, GenericSignature signature,
202+
AutoDiffLinearMapKind linearMapKind);
203+
195204
/// Mangle the AutoDiff generated declaration for the given:
196205
/// - Generated declaration kind: linear map struct or branching trace enum.
197206
/// - Mangled original function name.

include/swift/AST/Attr.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(async, Async,
602602
106)
603603

604604
SIMPLE_DECL_ATTR(concurrent, Concurrent,
605-
OnFunc | OnConstructor | OnAccessor | ConcurrencyOnly |
606-
ABIStableToAdd | ABIStableToRemove |
605+
OnFunc | OnConstructor | OnAccessor |
606+
ABIBreakingToAdd | ABIBreakingToRemove |
607607
APIBreakingToAdd | APIBreakingToRemove,
608608
107)
609609

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,8 +2938,8 @@ ERROR(dynamic_self_non_method,none,
29382938
"%select{global|local}0 function cannot return 'Self'", (bool))
29392939

29402940
ERROR(dynamic_self_invalid,none,
2941-
"covariant 'Self' can only appear as the type of a property, subscript or method result; "
2942-
"did you mean '%0'?", (StringRef))
2941+
"covariant 'Self' can only appear as the possibly optional type of a "
2942+
"property, subscript or method result; did you mean '%0'?", (StringRef))
29432943
ERROR(dynamic_self_in_mutable_property,none,
29442944
"mutable property cannot have covariant 'Self' type", ())
29452945
ERROR(dynamic_self_in_stored_property,none,

include/swift/AST/SILOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ class SILOptions {
153153
/// Emit extra exclusvity markers for memory access and verify coverage.
154154
bool VerifyExclusivity = false;
155155

156+
/// When building the stdlib with opts should we lower ownership after
157+
/// serialization? Otherwise we do before. Only set to true on Darwin for now.
158+
///
159+
bool SerializeStdlibWithOwnershipWithOpts = false;
160+
156161
/// Calls to the replaced method inside of the replacement method will call
157162
/// the previous implementation.
158163
///

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ LANGUAGE_FEATURE(StaticAssert, 0, "#assert", langOpts.EnableExperimentalStaticAs
3838
LANGUAGE_FEATURE(AsyncAwait, 296, "async/await", true)
3939
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol", true)
4040
LANGUAGE_FEATURE(Actors, 0, "actors", langOpts.EnableExperimentalConcurrency)
41+
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions", true)
4142

4243
#undef LANGUAGE_FEATURE

include/swift/Demangling/DemangleNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ NODE(CanonicalPrespecializedGenericTypeCachingOnceToken)
310310
NODE(AsyncFunctionPointer)
311311
CONTEXT_NODE(AutoDiffFunction)
312312
NODE(AutoDiffFunctionKind)
313+
NODE(AutoDiffSelfReorderingReabstractionThunk)
314+
NODE(AutoDiffSubsetParametersThunk)
313315
NODE(IndexSubset)
314316

315317
#undef CONTEXT_NODE

include/swift/Demangling/Demangler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,10 @@ class Demangler : public NodeFactory {
569569

570570
NodePointer demangleTypeMangling();
571571
NodePointer demangleSymbolicReference(unsigned char rawKind);
572+
NodePointer demangleAutoDiffFunction();
572573
NodePointer demangleAutoDiffFunctionKind();
574+
NodePointer demangleAutoDiffSubsetParametersThunk();
575+
NodePointer demangleAutoDiffSelfReorderingReabstractionThunk();
573576
NodePointer demangleIndexSubset();
574577

575578
bool demangleBoundGenerics(Vector<NodePointer> &TypeListList,

include/swift/SIL/SILBitfield.h renamed to include/swift/SIL/BasicBlockBits.h

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- SILBitField.h - Defines the bitfield utilities ---------*- C++ -*-===//
1+
//===--- BasicBlockBits.h - SILBasicBlock bit utilities ---------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines the BasicBlockBitfield and BasicBlockFlag utilities.
13+
// This file defines utilities for BasicBlock bit fields and sets.
1414
//
1515
//===----------------------------------------------------------------------===//
1616

@@ -211,6 +211,63 @@ template <unsigned N> class BasicBlockSetVector {
211211
}
212212
};
213213

214+
/// A utility for processing basic blocks in a worklist.
215+
///
216+
/// It is basically a combination of a block vector and a block set. It can be
217+
/// used for typical worklist-processing algorithms.
218+
template <unsigned N> class BasicBlockWorklist {
219+
llvm::SmallVector<SILBasicBlock *, N> worklist;
220+
BasicBlockSet visited;
221+
222+
public:
223+
/// Construct an empty worklist.
224+
BasicBlockWorklist(SILFunction *function) : visited(function) {}
225+
226+
/// Initialize the worklist with \p initialBlock.
227+
BasicBlockWorklist(SILBasicBlock *initialBlock)
228+
: visited(initialBlock->getParent()) {
229+
push(initialBlock);
230+
}
231+
232+
/// Pops the last added element from the worklist or returns null, if the
233+
/// worklist is empty.
234+
SILBasicBlock *pop() {
235+
if (worklist.empty())
236+
return nullptr;
237+
return worklist.pop_back_val();
238+
}
239+
240+
/// Pushes \p block onto the worklist if \p block has never been push before.
241+
bool pushIfNotVisited(SILBasicBlock *block) {
242+
if (visited.insert(block)) {
243+
worklist.push_back(block);
244+
return true;
245+
}
246+
return false;
247+
}
248+
249+
/// Like `pushIfNotVisited`, but requires that \p block has never been on the
250+
/// worklist before.
251+
void push(SILBasicBlock *block) {
252+
assert(!visited.contains(block));
253+
visited.insert(block);
254+
worklist.push_back(block);
255+
}
256+
257+
/// Like `pop`, but marks the returned block as "unvisited". This means, that
258+
/// the block can be pushed onto the worklist again.
259+
SILBasicBlock *popAndForget() {
260+
if (worklist.empty())
261+
return nullptr;
262+
SILBasicBlock *block = worklist.pop_back_val();
263+
visited.erase(block);
264+
return block;
265+
}
266+
267+
/// Returns true if \p block was visited, i.e. has been added to the worklist.
268+
bool isVisited(SILBasicBlock *block) const { return visited.contains(block); }
269+
};
270+
214271
} // namespace swift
215272

216273
#endif

include/swift/SIL/BasicBlockUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define SWIFT_SIL_BASICBLOCKUTILS_H
1515

1616
#include "swift/SIL/SILValue.h"
17-
#include "swift/SIL/SILBitfield.h"
17+
#include "swift/SIL/BasicBlockBits.h"
1818
#include "llvm/ADT/SetVector.h"
1919
#include "llvm/ADT/SmallPtrSet.h"
2020
#include "llvm/ADT/SmallVector.h"

include/swift/SIL/LinearLifetimeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "swift/SIL/SILFunction.h"
2222
#include "swift/SIL/SILValue.h"
2323
#include "swift/SIL/BasicBlockUtils.h"
24-
#include "swift/SIL/SILBitfield.h"
24+
#include "swift/SIL/BasicBlockBits.h"
2525
#include "llvm/ADT/SmallPtrSet.h"
2626

2727
namespace swift {

include/swift/SIL/SILArgument.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ class SILPhiArgument : public SILArgument {
215215
/// this will be guaranteed to return a valid SILValue.
216216
SILValue getIncomingPhiValue(SILBasicBlock *predBlock) const;
217217

218+
/// If this argument is a true phi, return the operand in the \p predBLock
219+
/// associated with an incoming value.
220+
///
221+
/// \returns the operand or nullptr if this is not a true phi.
222+
Operand *getIncomingPhiOperand(SILBasicBlock *predBlock) const;
223+
218224
/// If this argument is a phi, populate `OutArray` with the incoming phi
219225
/// values for each predecessor BB. If this argument is not a phi, return
220226
/// false.

include/swift/SILOptimizer/Utils/BasicBlockOptUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define SWIFT_SILOPTIMIZER_UTILS_BASICBLOCKOPTUTILS_H
2424

2525
#include "swift/SIL/SILBasicBlock.h"
26-
#include "swift/SIL/SILBitfield.h"
26+
#include "swift/SIL/BasicBlockBits.h"
2727
#include "swift/SIL/SILCloner.h"
2828
#include "swift/SIL/SILInstruction.h"
2929
#include "swift/SILOptimizer/Utils/InstOptUtils.h"

include/swift/SILOptimizer/Utils/DifferentiationMangler.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,29 @@ class DifferentiationMangler : public ASTMangler {
2727
public:
2828
DifferentiationMangler() {}
2929
/// Returns the mangled name for a differentiation function of the given kind.
30-
std::string mangle(SILFunction *originalFunction,
31-
Demangle::AutoDiffFunctionKind kind,
32-
AutoDiffConfig config);
30+
std::string mangleAutoDiffFunction(StringRef originalName,
31+
Demangle::AutoDiffFunctionKind kind,
32+
AutoDiffConfig config);
3333
/// Returns the mangled name for a derivative function of the given kind.
34-
std::string mangleDerivativeFunction(SILFunction *originalFunction,
34+
std::string mangleDerivativeFunction(StringRef originalName,
3535
AutoDiffDerivativeFunctionKind kind,
3636
AutoDiffConfig config);
3737
/// Returns the mangled name for a linear map of the given kind.
38-
std::string mangleLinearMap(SILFunction *originalFunction,
38+
std::string mangleLinearMap(StringRef originalName,
3939
AutoDiffLinearMapKind kind,
4040
AutoDiffConfig config);
41+
/// Returns the mangled name for a derivative function subset parameters
42+
/// thunk.
43+
std::string mangleDerivativeFunctionSubsetParametersThunk(
44+
StringRef originalName, CanType toType,
45+
AutoDiffDerivativeFunctionKind linearMapKind,
46+
IndexSubset *fromParamIndices, IndexSubset *fromResultIndices,
47+
IndexSubset *toParamIndices);
48+
/// Returns the mangled name for a linear map subset parameters thunk.
49+
std::string mangleLinearMapSubsetParametersThunk(
50+
CanType fromType, AutoDiffLinearMapKind linearMapKind,
51+
IndexSubset *fromParamIndices, IndexSubset *fromResultIndices,
52+
IndexSubset *toParamIndices);
4153
};
4254

4355
} // end namespace Mangle

include/swift/SILOptimizer/Utils/ValueLifetime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "swift/Basic/STLExtras.h"
2121
#include "swift/SIL/SILBuilder.h"
2222
#include "swift/SIL/SILInstruction.h"
23-
#include "swift/SIL/SILBitfield.h"
23+
#include "swift/SIL/BasicBlockBits.h"
2424
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
2525

2626
namespace swift {

lib/AST/ASTMangler.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,19 @@ void ASTMangler::appendAutoDiffFunctionParts(char functionKindCode,
448448
appendOperator("r");
449449
}
450450

451+
std::string ASTMangler::mangleAutoDiffSelfReorderingReabstractionThunk(
452+
CanType fromType, CanType toType, GenericSignature signature,
453+
AutoDiffLinearMapKind linearMapKind) {
454+
beginMangling();
455+
appendType(fromType);
456+
appendType(toType);
457+
if (signature)
458+
appendGenericSignature(signature);
459+
auto kindCode = (char)getAutoDiffFunctionKind(linearMapKind);
460+
appendOperator("TJO", StringRef(&kindCode, 1));
461+
return finalize();
462+
}
463+
451464
/// Mangle the index subset.
452465
void ASTMangler::appendIndexSubset(IndexSubset *indices) {
453466
Buffer << indices->getString();

lib/AST/ASTPrinter.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,32 @@ static bool usesFeatureActors(Decl *decl) {
25092509
return false;
25102510
}
25112511

2512+
static bool usesFeatureConcurrentFunctions(Decl *decl) {
2513+
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
2514+
if (func->isConcurrent())
2515+
return true;
2516+
}
2517+
2518+
// Check for concurrent functions in the types of declarations.
2519+
if (auto value = dyn_cast<ValueDecl>(decl)) {
2520+
if (Type type = value->getInterfaceType()) {
2521+
bool hasConcurrent = type.findIf([](Type type) {
2522+
if (auto fnType = type->getAs<AnyFunctionType>()) {
2523+
if (fnType->isConcurrent())
2524+
return true;
2525+
}
2526+
2527+
return false;
2528+
});
2529+
2530+
if (hasConcurrent)
2531+
return true;
2532+
}
2533+
}
2534+
2535+
return false;
2536+
}
2537+
25122538
/// Determine the set of "new" features used on a given declaration.
25132539
///
25142540
/// Note: right now, all features we check for are "new". At some point, we'll

0 commit comments

Comments
 (0)