Skip to content

Commit cf93ebf

Browse files
Merge pull request #4945 from swiftwasm/main
[pull] swiftwasm from main
2 parents 3ee84e9 + 8491f52 commit cf93ebf

File tree

177 files changed

+1626
-553
lines changed

Some content is hidden

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

177 files changed

+1626
-553
lines changed

docs/CppInteroperability/CppInteroperabilityStatus.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ This status table describes which of the following Swift language features have
163163
| Copy and destroy semantics | Yes |
164164
| Creation | Yes |
165165
| Enums with associated values | Partially: only support structs and enums |
166-
| Enums with raw values | No |
166+
| Enums with raw values | Yes |
167167
| Indirect enums | No |
168168

169169
**Class types**
@@ -188,6 +188,7 @@ This status table describes which of the following Swift language features have
188188
| Getter accessors | Yes, via `get<name>`. Boolean properties that start with `is` or `has` are remapped directly to a getter method using their original name |
189189
| Setter accessors | Yes, via `set<name>` |
190190
| Mutation accessors | No |
191+
| Static property accessors | Yes |
191192

192193
**Generics**
193194

docs/SIL.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3804,7 +3804,7 @@ debug_value
38043804

38053805
::
38063806

3807-
sil-instruction ::= debug_value '[poison]'? '[moved]'? sil-operand (',' debug-var-attr)* advanced-debug-var-attr* (',' 'expr' debug-info-expr)?
3807+
sil-instruction ::= debug_value '[poison]'? '[moved]'? '[trace]'? sil-operand (',' debug-var-attr)* advanced-debug-var-attr* (',' 'expr' debug-info-expr)?
38083808

38093809
debug_value %1 : $Int
38103810

@@ -3910,6 +3910,8 @@ It is worth noting that a SIL DIExpression is similar to
39103910
info metadata. While LLVM represents ``!DIExpression`` are a list of 64-bit integers,
39113911
SIL DIExpression can have elements with various types, like AST nodes or strings.
39123912

3913+
The ``[trace]`` flag is available for compiler unit testing. It is not produced during normal compilation. It is used combination with internal logging and optimization controls to select specific values to trace or to transform. For example, liveness analysis combines all "traced" values into a single live range with multiple definitions. This exposes corner cases that cannot be represented by passing valid SIL through the pipeline.
3914+
39133915
Profiling
39143916
~~~~~~~~~
39153917

include/swift/AST/ASTScope.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
203203

204204
#pragma mark common queries
205205
public:
206-
virtual NullablePtr<ClosureExpr> getClosureIfClosureScope() const;
206+
virtual NullablePtr<AbstractClosureExpr> getClosureIfClosureScope() const;
207207
virtual ASTContext &getASTContext() const;
208208
virtual NullablePtr<Decl> getDeclIfAny() const { return nullptr; };
209209
virtual NullablePtr<Stmt> getStmtIfAny() const { return nullptr; };
@@ -1032,17 +1032,17 @@ class CaptureListScope final : public ASTScopeImpl {
10321032
/// For a closure with named parameters, this scope does the local bindings.
10331033
class ClosureParametersScope final : public ASTScopeImpl {
10341034
public:
1035-
ClosureExpr *const closureExpr;
1035+
AbstractClosureExpr *const closureExpr;
10361036

1037-
ClosureParametersScope(ClosureExpr *closureExpr)
1037+
ClosureParametersScope(AbstractClosureExpr *closureExpr)
10381038
: closureExpr(closureExpr) {}
10391039
virtual ~ClosureParametersScope() {}
10401040

10411041
std::string getClassName() const override;
10421042
SourceRange
10431043
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
10441044

1045-
NullablePtr<ClosureExpr> getClosureIfClosureScope() const override {
1045+
NullablePtr<AbstractClosureExpr> getClosureIfClosureScope() const override {
10461046
return closureExpr;
10471047
}
10481048
NullablePtr<Expr> getExprIfAny() const override { return closureExpr; }
@@ -1541,7 +1541,7 @@ class BraceStmtScope final : public AbstractStmtScope {
15411541
SourceRange
15421542
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
15431543

1544-
NullablePtr<ClosureExpr> parentClosureIfAny() const; // public??
1544+
NullablePtr<AbstractClosureExpr> parentClosureIfAny() const; // public??
15451545
Stmt *getStmt() const override { return stmt; }
15461546

15471547
protected:

include/swift/AST/Expr.h

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,10 +4144,10 @@ class CaptureListExpr final : public Expr,
41444144
private llvm::TrailingObjects<CaptureListExpr, CaptureListEntry> {
41454145
friend TrailingObjects;
41464146

4147-
ClosureExpr *closureBody;
4147+
AbstractClosureExpr *closureBody;
41484148

41494149
CaptureListExpr(ArrayRef<CaptureListEntry> captureList,
4150-
ClosureExpr *closureBody)
4150+
AbstractClosureExpr *closureBody)
41514151
: Expr(ExprKind::CaptureList, /*Implicit=*/false, Type()),
41524152
closureBody(closureBody) {
41534153
Bits.CaptureListExpr.NumCaptures = captureList.size();
@@ -4158,16 +4158,16 @@ class CaptureListExpr final : public Expr,
41584158
public:
41594159
static CaptureListExpr *create(ASTContext &ctx,
41604160
ArrayRef<CaptureListEntry> captureList,
4161-
ClosureExpr *closureBody);
4161+
AbstractClosureExpr *closureBody);
41624162

41634163
ArrayRef<CaptureListEntry> getCaptureList() {
41644164
return {getTrailingObjects<CaptureListEntry>(),
41654165
Bits.CaptureListExpr.NumCaptures};
41664166
}
4167-
ClosureExpr *getClosureBody() { return closureBody; }
4168-
const ClosureExpr *getClosureBody() const { return closureBody; }
4167+
AbstractClosureExpr *getClosureBody() { return closureBody; }
4168+
const AbstractClosureExpr *getClosureBody() const { return closureBody; }
41694169

4170-
void setClosureBody(ClosureExpr *body) { closureBody = body; }
4170+
void setClosureBody(AbstractClosureExpr *body) { closureBody = body; }
41714171

41724172
/// This is a bit weird, but the capture list is lexically contained within
41734173
/// the closure, so the ClosureExpr has the full source range.
@@ -5389,10 +5389,6 @@ class KeyPathExpr : public Expr {
53895389
/// a contextual root type.
53905390
bool HasLeadingDot = false;
53915391

5392-
/// When we parse a key path literal, we claim a closure discriminator for it, since it may be used as
5393-
/// a closure value in function type context.
5394-
unsigned ClosureDiscriminator;
5395-
53965392
public:
53975393
/// A single stored component, which will be one of:
53985394
/// - an unresolved DeclNameRef, which has to be type-checked
@@ -5724,12 +5720,11 @@ class KeyPathExpr : public Expr {
57245720

57255721
KeyPathExpr(SourceLoc startLoc, Expr *parsedRoot, Expr *parsedPath,
57265722
SourceLoc endLoc, bool hasLeadingDot, bool isObjC,
5727-
bool isImplicit, unsigned closureDiscriminator);
5723+
bool isImplicit);
57285724

57295725
/// Create a key path with unresolved root and path expressions.
57305726
KeyPathExpr(SourceLoc backslashLoc, Expr *parsedRoot, Expr *parsedPath,
5731-
bool hasLeadingDot, bool isImplicit,
5732-
unsigned closureDiscriminator);
5727+
bool hasLeadingDot, bool isImplicit);
57335728

57345729
/// Create a key path with components.
57355730
KeyPathExpr(ASTContext &ctx, SourceLoc startLoc,
@@ -5740,8 +5735,7 @@ class KeyPathExpr : public Expr {
57405735
/// Create a new parsed Swift key path expression.
57415736
static KeyPathExpr *createParsed(ASTContext &ctx, SourceLoc backslashLoc,
57425737
Expr *parsedRoot, Expr *parsedPath,
5743-
bool hasLeadingDot,
5744-
unsigned closureDiscriminator = AbstractClosureExpr::InvalidDiscriminator);
5738+
bool hasLeadingDot);
57455739

57465740
/// Create a new parsed #keyPath expression.
57475741
static KeyPathExpr *createParsedPoundKeyPath(ASTContext &ctx,
@@ -5836,9 +5830,6 @@ class KeyPathExpr : public Expr {
58365830
/// True if this key path expression has a leading dot.
58375831
bool expectsContextualRoot() const { return HasLeadingDot; }
58385832

5839-
/// Return the discriminator to use if this key path becomes a closure.
5840-
unsigned getClosureDiscriminator() const { return ClosureDiscriminator; }
5841-
58425833
static bool classof(const Expr *E) {
58435834
return E->getKind() == ExprKind::KeyPath;
58445835
}

include/swift/AST/Module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@ class ModuleDecl
841841
return EntryPointInfo.hasEntryPoint();
842842
}
843843

844+
NominalTypeDecl *getMainTypeDecl() const;
845+
844846
/// Returns the associated clang module if one exists.
845847
const clang::Module *findUnderlyingClangModule() const;
846848

include/swift/AST/PlatformKind.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ StringRef platformString(PlatformKind platform);
4141
/// or None if such a platform kind does not exist.
4242
Optional<PlatformKind> platformFromString(StringRef Name);
4343

44-
/// Returns a valid platform string if the candidate string would be a valid
45-
/// platform string if its case were adjusted (e.g. "macos" -> "macOS").
46-
Optional<StringRef> caseCorrectedPlatformString(StringRef candidate);
44+
/// Returns a valid platform string that is closest to the candidate string
45+
/// based on edit distance. Returns \c None if the closest valid platform
46+
/// distance is not within a minimum threshold.
47+
Optional<StringRef> closestCorrectedPlatformString(StringRef candidate);
4748

4849
/// Returns a human-readable version of the platform name as a string, suitable
4950
/// for emission in diagnostics (e.g., "macOS").

include/swift/AST/Types.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4676,6 +4676,17 @@ class SILFunctionType final
46764676
/// differentiability from all parameters.
46774677
CanSILFunctionType getWithoutDifferentiability();
46784678

4679+
/// Given that `this` is a `@differentiable` function type, returns the type
4680+
/// of the given `@differentiable` function type component.
4681+
CanSILFunctionType getDifferentiableComponentType(
4682+
NormalDifferentiableFunctionTypeComponent component, SILModule &module);
4683+
4684+
/// Given that `this` is a `@differentiable(linear)` function type, returns
4685+
/// the type of the given `@differentiable(linear)` function type component.
4686+
CanSILFunctionType
4687+
getLinearComponentType(LinearDifferentiableFunctionTypeComponent component,
4688+
SILModule &module);
4689+
46794690
/// Returns the type of the derivative function for the given parameter
46804691
/// indices, result indices, derivative function kind, derivative function
46814692
/// generic signature (optional), and other auxiliary parameters.

include/swift/IDE/Utils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,8 @@ class NameMatcher: public ASTWalker {
287287
PreWalkResult<Expr *> walkToExprPre(Expr *E) override;
288288
PostWalkResult<Expr *> walkToExprPost(Expr *E) override;
289289
PreWalkAction walkToDeclPre(Decl *D) override;
290-
PostWalkAction walkToDeclPost(Decl *D) override;
291290
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override;
292-
PostWalkResult<Stmt *> walkToStmtPost(Stmt *S) override;
293291
PreWalkAction walkToTypeReprPre(TypeRepr *T) override;
294-
PostWalkAction walkToTypeReprPost(TypeRepr *T) override;
295292
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override;
296293
bool shouldWalkIntoGenericParams() override { return true; }
297294

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//===--- NodeDatastructures.h -----------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines efficient data structures for working with Nodes.
14+
//
15+
// TODO: Add an InstructionWorklist similar to BasicBlockWorklist.
16+
//
17+
//===----------------------------------------------------------------------===//
18+
19+
#ifndef SWIFT_SIL_NODEDATASTRUCTURES_H
20+
#define SWIFT_SIL_NODEDATASTRUCTURES_H
21+
22+
#include "swift/SIL/NodeBits.h"
23+
#include "swift/SIL/StackList.h"
24+
25+
namespace swift {
26+
27+
/// An implementation of `llvm::SetVector<SILNode *,
28+
/// StackList<SILNode *>,
29+
/// NodeSet>`.
30+
///
31+
/// Unfortunately it's not possible to use `llvm::SetVector` directly because
32+
/// the ValueSet and StackList constructors needs a `SILFunction` argument.
33+
///
34+
/// Note: This class does not provide a `remove` method intentionally, because
35+
/// it would have a O(n) complexity.
36+
class NodeSetVector {
37+
StackList<SILNode *> vector;
38+
NodeSet set;
39+
40+
public:
41+
using iterator = typename StackList<SILNode *>::iterator;
42+
43+
NodeSetVector(SILFunction *function) : vector(function), set(function) {}
44+
45+
iterator begin() const { return vector.begin(); }
46+
iterator end() const { return vector.end(); }
47+
48+
llvm::iterator_range<iterator> getRange() const {
49+
return llvm::make_range(begin(), end());
50+
}
51+
52+
bool empty() const { return vector.empty(); }
53+
54+
bool contains(SILNode *node) const { return set.contains(node); }
55+
56+
/// Returns true if \p value was not contained in the set before inserting.
57+
bool insert(SILNode *node) {
58+
if (set.insert(node)) {
59+
vector.push_back(node);
60+
return true;
61+
}
62+
return false;
63+
}
64+
};
65+
66+
/// An implementation of `llvm::SetVector<SILValue,
67+
/// StackList<SILValue>,
68+
/// ValueSet>`.
69+
///
70+
/// Unfortunately it's not possible to use `llvm::SetVector` directly because
71+
/// the ValueSet and StackList constructors needs a `SILFunction` argument.
72+
///
73+
/// Note: This class does not provide a `remove` method intentionally, because
74+
/// it would have a O(n) complexity.
75+
class ValueSetVector {
76+
StackList<SILValue> vector;
77+
ValueSet set;
78+
79+
public:
80+
using iterator = typename StackList<SILValue>::iterator;
81+
82+
ValueSetVector(SILFunction *function) : vector(function), set(function) {}
83+
84+
iterator begin() const { return vector.begin(); }
85+
iterator end() const { return vector.end(); }
86+
87+
llvm::iterator_range<iterator> getRange() const {
88+
return llvm::make_range(begin(), end());
89+
}
90+
91+
bool empty() const { return vector.empty(); }
92+
93+
bool contains(SILValue value) const { return set.contains(value); }
94+
95+
/// Returns true if \p value was not contained in the set before inserting.
96+
bool insert(SILValue value) {
97+
if (set.insert(value)) {
98+
vector.push_back(value);
99+
return true;
100+
}
101+
return false;
102+
}
103+
};
104+
105+
} // namespace swift
106+
107+
#endif

include/swift/SIL/SILBasicBlock.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,26 @@ template <> struct DenseMapInfo<swift::PhiValue> {
659659

660660
} // end namespace llvm
661661

662+
//===----------------------------------------------------------------------===//
663+
// Inline SILInstruction implementations
664+
//===----------------------------------------------------------------------===//
665+
666+
namespace swift {
667+
668+
inline SILFunction *SILInstruction::getFunction() const {
669+
return getParent()->getParent();
670+
}
671+
672+
inline SILInstruction *SILInstruction::getPreviousInstruction() {
673+
auto pos = getIterator();
674+
return pos == getParent()->begin() ? nullptr : &*std::prev(pos);
675+
}
676+
677+
inline SILInstruction *SILInstruction::getNextInstruction() {
678+
auto nextPos = std::next(getIterator());
679+
return nextPos == getParent()->end() ? nullptr : &*nextPos;
680+
}
681+
682+
} // end swift namespace
683+
662684
#endif

include/swift/SIL/SILBuilder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,10 +957,12 @@ class SILBuilder {
957957
DebugValueInst *createDebugValue(SILLocation Loc, SILValue src,
958958
SILDebugVariable Var,
959959
bool poisonRefs = false,
960-
bool wasMoved = false);
960+
bool wasMoved = false,
961+
bool trace = false);
961962
DebugValueInst *createDebugValueAddr(SILLocation Loc, SILValue src,
962963
SILDebugVariable Var,
963-
bool wasMoved = false);
964+
bool wasMoved = false,
965+
bool trace = false);
964966

965967
/// Create a debug_value according to the type of \p src
966968
SILInstruction *emitDebugDescription(SILLocation Loc, SILValue src,

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ SILCloner<ImplClass>::visitDebugValueInst(DebugValueInst *Inst) {
12831283
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
12841284
auto *NewInst = getBuilder().createDebugValue(
12851285
Inst->getLoc(), getOpValue(Inst->getOperand()), VarInfo,
1286-
Inst->poisonRefs(), Inst->getWasMoved());
1286+
Inst->poisonRefs(), Inst->getWasMoved(), Inst->hasTrace());
12871287
remapDebugVarInfo(DebugVarCarryingInst(NewInst));
12881288
recordClonedInstruction(Inst, NewInst);
12891289
}

include/swift/SIL/SILFunction.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,20 @@ public ilist_node_traits<::swift::SILFunction> {
14611461

14621462
} // end llvm namespace
14631463

1464+
//===----------------------------------------------------------------------===//
1465+
// Inline SIL implementations
1466+
//===----------------------------------------------------------------------===//
1467+
1468+
namespace swift {
1469+
1470+
inline bool SILBasicBlock::isEntry() const {
1471+
return this == &*getParent()->begin();
1472+
}
1473+
1474+
inline SILModule &SILInstruction::getModule() const {
1475+
return getFunction()->getModule();
1476+
}
1477+
1478+
} // end swift namespace
1479+
14641480
#endif

0 commit comments

Comments
 (0)