Skip to content

Commit aa6f357

Browse files
Merge pull request #1563 from swiftwasm/maxd/master-conflicts
Resolve conflicts with upstream `master`
2 parents 8668be2 + 164230a commit aa6f357

File tree

129 files changed

+2028
-965
lines changed

Some content is hidden

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

129 files changed

+2028
-965
lines changed

docs/ABI/Mangling.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,3 +1047,63 @@ Some kinds need arguments, which precede ``Tf``.
10471047
If the first character of the string literal is a digit ``[0-9]`` or an
10481048
underscore ``_``, the identifier for the string literal is prefixed with an
10491049
additional underscore ``_``.
1050+
1051+
Conventions for foreign symbols
1052+
-------------------------------
1053+
1054+
Swift interoperates with multiple other languages - C, C++, Objective-C, and
1055+
Objective-C++. Each of these languages defines their own mangling conventions,
1056+
so Swift must take care to follow them. However, these conventions do not cover
1057+
Swift-specific symbols like Swift type metadata for foreign types, so Swift uses
1058+
its own mangling scheme for those symbols.
1059+
1060+
Importing C and C++ structs
1061+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
1062+
1063+
Types imported from C and C++ are imported as if they are located in the ``__C``
1064+
module, regardless of the actual Clang module that they are coming from. This
1065+
can be observed when mangling a Swift function that accepts a C/C++ struct as a
1066+
parameter:
1067+
1068+
C++ module ``CxxStructModule``:
1069+
1070+
.. code-block:: c++
1071+
1072+
struct CxxStruct {};
1073+
1074+
inline void cxxFunction(CxxStruct s) {}
1075+
1076+
Swift module ``main`` that imports ``CxxStructModule``:
1077+
1078+
.. code-block:: swift
1079+
1080+
import CxxStructModule
1081+
1082+
public func swiftFunction(_ s: CxxStruct) {}
1083+
1084+
Resulting symbols (showing only Itanium-mangled C++ symbols for brevity):
1085+
1086+
.. code::
1087+
1088+
_Z11cxxFunction9CxxStruct // -> cxxFunction(CxxStruct)
1089+
s4main13swiftFunctionyySo9CxxStructVF // -> main.swiftFunction(__C.CxxStruct) -> ()
1090+
1091+
The reason for ignoring the Clang module and always putting C and C++ types into
1092+
``__C`` at the Swift ABI level is that the Clang module is not a part of the C
1093+
or C++ ABI. When owners of C and C++ Clang modules decide what changes are
1094+
ABI-compatible or not, they will likely take into account C and C++ ABI, but not
1095+
the Swift ABI. Therefore, Swift ABI can only encode information about a C or C++
1096+
type that the C and C++ ABI already encodes in order to remain compatible with
1097+
future versions of libraries that evolve according to C and C++ ABI
1098+
compatibility principles.
1099+
1100+
The C/C++ compiler does not generate Swift metadata symbols and value witness
1101+
tables for C and C++ types. To make a foreign type usable in Swift in the same
1102+
way as a native type, the Swift compiler must generate these symbols.
1103+
Specifically, each Swift module that uses a given C or C++ type generates the
1104+
necessary Swift symbols. For the example above the Swift compiler will generate following
1105+
nominal type descriptor symbol for ``CxxStruct`` while compiling the ``main`` module:
1106+
1107+
.. code::
1108+
1109+
sSo9CxxStructVMn // -> nominal type descriptor for __C.CxxStruct

docs/DifferentiableProgramming.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,15 @@ extension Perceptron {
893893

894894
### `@differentiable` function types
895895

896-
A subtype of normal function types with a different runtime representation,
897-
which stores metadata that allows their values to be differentiated anywhere.
896+
Differentiable functions are first-class values, identified by a
897+
`@differentiable` attribute in the function type. A `@differentiable` function
898+
type is a subtype of its corresponding normal function type (i.e. without a
899+
`@differentiable` attribute) with an extended ABI, which stores metadata that
900+
allows their values to be differentiated anywhere the function is passed. A
901+
`@differentiable(linear)` function type is a subtype of its corresponding
902+
`@differentiable` function type. A normal function can be implicitly converted
903+
to a `@differentiable` or `@differentiable(linear)` function with appropriate
904+
compile-time checks.
898905

899906
```swift
900907
func addOne(_ x: Float) -> Float { x + 1 }
@@ -920,8 +927,9 @@ func _(_ x: Float) -> (value: Float,
920927

921928
### Differential operators
922929

923-
Standard library differentiation APIs that take `@differentiable` functions and
924-
return derivative functions or compute derivative values.
930+
Differential operators are APIs defined in the standard library that take
931+
`@differentiable` functions and return derivative functions or compute
932+
derivative values.
925933

926934
```swift
927935
// In the standard library:
@@ -2318,7 +2326,7 @@ As shown in the
23182326
subsection, a `@differentiable` function value's runtime representation contains
23192327
the original function along with extra information that allows the function to
23202328
be differentiated (or transposed, if it is `@differentiable(linear)`). A
2321-
@differentiable or `@differentiable(linear)` function value can be called like a
2329+
`@differentiable` or `@differentiable(linear)` function value can be called like a
23222330
non-`@differentiable` function. A `@differentiable(linear)` function value can
23232331
be implicitly converted to a `@differentiable` one, which can be implicitly
23242332
converted to a non-`@differentiable` one.

include/swift/SIL/SILValue.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class SILLocation;
4141
class DeadEndBlocks;
4242
class ValueBaseUseIterator;
4343
class ValueUseIterator;
44+
class SILValue;
4445

4546
/// An enumeration which contains values for all the concrete ValueBase
4647
/// subclasses.
@@ -188,6 +189,12 @@ struct ValueOwnershipKind {
188189
return merge(other).hasValue();
189190
}
190191

192+
/// Returns isCompatibleWith(other.getOwnershipKind()).
193+
///
194+
/// Definition is inline after SILValue is defined to work around circular
195+
/// dependencies.
196+
bool isCompatibleWith(SILValue other) const;
197+
191198
template <typename RangeTy>
192199
static Optional<ValueOwnershipKind> merge(RangeTy &&r) {
193200
auto initial = Optional<ValueOwnershipKind>(ValueOwnershipKind::None);
@@ -440,6 +447,10 @@ class SILValue {
440447
void verifyOwnership(DeadEndBlocks *DEBlocks = nullptr) const;
441448
};
442449

450+
inline bool ValueOwnershipKind::isCompatibleWith(SILValue other) const {
451+
return isCompatibleWith(other.getOwnershipKind());
452+
}
453+
443454
/// A map from a ValueOwnershipKind that an operand can accept to a
444455
/// UseLifetimeConstraint that describes the effect that the operand's use has
445456
/// on the underlying value. If a ValueOwnershipKind is not in this map then

include/swift/SILOptimizer/Utils/SILSSAUpdater.h

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
#include "swift/SIL/SILValue.h"
1919

2020
namespace llvm {
21-
template<typename T> class SSAUpdaterTraits;
22-
template<typename T> class SmallVectorImpl;
23-
}
21+
22+
template <typename T>
23+
class SSAUpdaterTraits;
24+
25+
template <typename T>
26+
class SmallVectorImpl;
27+
28+
} // namespace llvm
2429

2530
namespace swift {
2631

@@ -31,7 +36,7 @@ class SILUndef;
3136

3237
/// Independent utility that canonicalizes BB arguments by reusing structurally
3338
/// equivalent arguments and replacing the original arguments with casts.
34-
SILValue replaceBBArgWithCast(SILPhiArgument *Arg);
39+
SILValue replaceBBArgWithCast(SILPhiArgument *arg);
3540

3641
/// This class updates SSA for a set of SIL instructions defined in multiple
3742
/// blocks.
@@ -40,38 +45,38 @@ class SILSSAUpdater {
4045

4146
// A map of basic block to available phi value.
4247
using AvailableValsTy = llvm::DenseMap<SILBasicBlock *, SILValue>;
43-
std::unique_ptr<AvailableValsTy> AV;
48+
std::unique_ptr<AvailableValsTy> blockToAvailableValueMap;
4449

45-
SILType ValType;
50+
SILType type;
4651

4752
// The SSAUpdaterTraits specialization uses this sentinel to mark 'new' phi
4853
// nodes (all the incoming edge arguments have this sentinel set).
49-
std::unique_ptr<SILUndef, void(*)(SILUndef *)> PHISentinel;
54+
std::unique_ptr<SILUndef, void (*)(SILUndef *)> phiSentinel;
5055

5156
// If not null updated with inserted 'phi' nodes (SILArgument).
52-
SmallVectorImpl<SILPhiArgument *> *InsertedPHIs;
57+
SmallVectorImpl<SILPhiArgument *> *insertedPhis;
5358

5459
// Not copyable.
5560
void operator=(const SILSSAUpdater &) = delete;
5661
SILSSAUpdater(const SILSSAUpdater &) = delete;
5762

5863
public:
5964
explicit SILSSAUpdater(
60-
SmallVectorImpl<SILPhiArgument *> *InsertedPHIs = nullptr);
65+
SmallVectorImpl<SILPhiArgument *> *insertedPhis = nullptr);
6166
~SILSSAUpdater();
6267

63-
void setInsertedPhis(SmallVectorImpl<SILPhiArgument *> *insertedPhis) {
64-
InsertedPHIs = insertedPhis;
68+
void setInsertedPhis(SmallVectorImpl<SILPhiArgument *> *inputInsertedPhis) {
69+
insertedPhis = inputInsertedPhis;
6570
}
6671

6772
/// Initialize for a use of a value of type.
68-
void Initialize(SILType T);
73+
void initialize(SILType type);
6974

70-
bool HasValueForBlock(SILBasicBlock *BB) const;
71-
void AddAvailableValue(SILBasicBlock *BB, SILValue V);
75+
bool hasValueForBlock(SILBasicBlock *block) const;
76+
void addAvailableValue(SILBasicBlock *block, SILValue value);
7277

7378
/// Construct SSA for a value that is live at the *end* of a basic block.
74-
SILValue GetValueAtEndOfBlock(SILBasicBlock *BB);
79+
SILValue getValueAtEndOfBlock(SILBasicBlock *block);
7580

7681
/// Construct SSA for a value that is live in the middle of a block.
7782
/// This handles the case where the use is before a definition of the value.
@@ -85,15 +90,15 @@ class SILSSAUpdater {
8590
///
8691
/// In this case we need to insert a 'PHI' node at the beginning of BB2
8792
/// merging val_1 and val_2.
88-
SILValue GetValueInMiddleOfBlock(SILBasicBlock *BB);
93+
SILValue getValueInMiddleOfBlock(SILBasicBlock *block);
8994

90-
void RewriteUse(Operand &Op);
95+
void rewriteUse(Operand &operand);
9196

92-
void *allocate(unsigned Size, unsigned Align) const;
93-
static void deallocateSentinel(SILUndef *U);
94-
private:
97+
void *allocate(unsigned size, unsigned align) const;
98+
static void deallocateSentinel(SILUndef *undef);
9599

96-
SILValue GetValueAtEndOfBlockInternal(SILBasicBlock *BB);
100+
private:
101+
SILValue getValueAtEndOfBlockInternal(SILBasicBlock *block);
97102
};
98103

99104
/// Utility to wrap 'Operand's to deal with invalidation of
@@ -112,15 +117,15 @@ class SILSSAUpdater {
112117
/// identify the use allowing us to reconstruct the use after the branch has
113118
/// been changed.
114119
class UseWrapper {
115-
Operand *U;
116-
SILBasicBlock *Parent;
120+
Operand *wrappedUse;
121+
SILBasicBlock *parent;
117122
enum {
118123
kRegularUse,
119124
kBranchUse,
120125
kCondBranchUseTrue,
121126
kCondBranchUseFalse
122-
} Type;
123-
unsigned Idx;
127+
} type;
128+
unsigned index;
124129

125130
public:
126131

@@ -131,7 +136,7 @@ class UseWrapper {
131136
/// (ValueUseIterator) become invalid as they point to freed operands.
132137
/// Instead we store the branch's parent and the idx so that we can
133138
/// reconstruct the use.
134-
UseWrapper(Operand *Use);
139+
UseWrapper(Operand *use);
135140

136141
Operand *getOperand();
137142

0 commit comments

Comments
 (0)