Skip to content

Commit c0fc0f3

Browse files
authored
Merge pull request #1168 from swiftwasm/master
[pull] swiftwasm from master
2 parents 16d3b33 + 7d4da10 commit c0fc0f3

File tree

148 files changed

+1990
-982
lines changed

Some content is hidden

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

148 files changed

+1990
-982
lines changed

docs/ABI/Mangling.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ mangled in to disambiguate.
589589
impl-function-type ::= type* 'I' FUNC-ATTRIBUTES '_'
590590
impl-function-type ::= type* generic-signature 'I' FUNC-ATTRIBUTES '_'
591591

592-
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? DIFFERENTIABILITY-KIND? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? (PARAM-CONVENTION PARAM-DIFFERENTIABILITY?)* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION)?
592+
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? DIFFERENTIABILITY-KIND? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? (PARAM-CONVENTION PARAM-DIFFERENTIABILITY?)* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION RESULT-DIFFERENTIABILITY?)?
593593

594594
PATTERN-SUBS ::= 's' // has pattern substitutions
595595
INVOCATION-SUB ::= 'I' // has invocation substitutions
@@ -634,6 +634,8 @@ mangled in to disambiguate.
634634
RESULT-CONVENTION ::= 'u' // unowned inner pointer
635635
RESULT-CONVENTION ::= 'a' // auto-released
636636

637+
RESULT-DIFFERENTIABILITY ::= 'w' // @noDerivative
638+
637639
For the most part, manglings follow the structure of formal language
638640
types. However, in some cases it is more useful to encode the exact
639641
implementation details of a function type.

include/swift/AST/ASTWalker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ class ASTWalker {
216216
virtual bool shouldWalkIntoLazyInitializers() { return true; }
217217

218218
/// This method configures whether the walker should visit the body of a
219-
/// non-single expression closure.
219+
/// closure that was checked separately from its enclosing expression.
220220
///
221221
/// For work that is performed for every top-level expression, this should
222222
/// be overridden to return false, to avoid duplicating work or visiting
223223
/// bodies of closures that have not yet been type checked.
224-
virtual bool shouldWalkIntoNonSingleExpressionClosure(ClosureExpr *) {
224+
virtual bool shouldWalkIntoSeparatelyCheckedClosure(ClosureExpr *) {
225225
return true;
226226
}
227227

include/swift/AST/AnyFunctionRef.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,6 @@ class AnyFunctionRef {
8989
return TheFunction.get<AbstractClosureExpr *>()->getSingleExpressionBody();
9090
}
9191

92-
void setSingleExpressionBody(Expr *expr) {
93-
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
94-
AFD->setSingleExpressionBody(expr);
95-
return;
96-
}
97-
98-
auto ACE = TheFunction.get<AbstractClosureExpr *>();
99-
if (auto CE = dyn_cast<ClosureExpr>(ACE)) {
100-
CE->setSingleExpressionBody(expr);
101-
} else {
102-
cast<AutoClosureExpr>(ACE)->setBody(expr);
103-
}
104-
}
105-
10692
Type getType() const {
10793
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
10894
return AFD->getInterfaceType();

include/swift/AST/AutoDiff.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,21 @@ enum class AutoDiffGeneratedDeclarationKind : uint8_t {
173173
};
174174

175175
/// SIL-level automatic differentiation indices. Consists of:
176-
/// - Parameter indices: indices of parameters to differentiate with respect to.
177-
/// - Result index: index of the result to differentiate from.
176+
/// - The differentiability parameter indices.
177+
/// - The differentiability result indices.
178178
// TODO(TF-913): Remove `SILAutoDiffIndices` in favor of `AutoDiffConfig`.
179-
// `AutoDiffConfig` supports multiple result indices.
179+
// `AutoDiffConfig` additionally stores a derivative generic signature.
180180
struct SILAutoDiffIndices {
181-
/// The index of the dependent result to differentiate from.
182-
unsigned source;
183-
/// The indices for independent parameters to differentiate with respect to.
181+
/// The indices of independent parameters to differentiate with respect to.
184182
IndexSubset *parameters;
183+
/// The indices of dependent results to differentiate from.
184+
IndexSubset *results;
185185

186-
/*implicit*/ SILAutoDiffIndices(unsigned source, IndexSubset *parameters)
187-
: source(source), parameters(parameters) {}
186+
/*implicit*/ SILAutoDiffIndices(IndexSubset *parameters, IndexSubset *results)
187+
: parameters(parameters), results(results) {
188+
assert(parameters && "Parameter indices must be non-null");
189+
assert(results && "Result indices must be non-null");
190+
}
188191

189192
bool operator==(const SILAutoDiffIndices &other) const;
190193

@@ -202,7 +205,12 @@ struct SILAutoDiffIndices {
202205
SWIFT_DEBUG_DUMP;
203206

204207
std::string mangle() const {
205-
std::string result = "src_" + llvm::utostr(source) + "_wrt_";
208+
std::string result = "src_";
209+
interleave(
210+
results->getIndices(),
211+
[&](unsigned idx) { result += llvm::utostr(idx); },
212+
[&] { result += '_'; });
213+
result += "_wrt_";
206214
llvm::interleave(
207215
parameters->getIndices(),
208216
[&](unsigned idx) { result += llvm::utostr(idx); },

include/swift/AST/Evaluator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class Evaluator {
439439
!Request::isDependencySink>::type * = nullptr>
440440
void reportEvaluatedResult(const Request &r,
441441
const typename Request::OutputType &o) {
442-
recorder.replay(ActiveRequest(r));
442+
recorder.replay(activeRequests, ActiveRequest(r));
443443
}
444444

445445
// Report the result of evaluating a request that is a dependency sink.

include/swift/AST/EvaluatorDependencies.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,16 @@ struct DependencyRecorder {
267267
void realize(const DependencyCollector::Reference &ref);
268268

269269
public:
270-
void replay(const swift::ActiveRequest &req);
270+
void replay(const llvm::SetVector<swift::ActiveRequest> &stack,
271+
const swift::ActiveRequest &req);
271272
void record(const llvm::SetVector<swift::ActiveRequest> &stack,
272273
llvm::function_ref<void(DependencyCollector &)> rec);
273274

275+
private:
276+
void
277+
unionNearestCachedRequest(ArrayRef<swift::ActiveRequest> stack,
278+
const DependencyCollector::ReferenceSet &scratch);
279+
274280
public:
275281
using ReferenceEnumerator =
276282
llvm::function_ref<void(const DependencyCollector::Reference &)>;
@@ -298,7 +304,12 @@ struct DependencyRecorder {
298304
SourceFile *getActiveDependencySourceOrNull() const {
299305
if (dependencySources.empty())
300306
return nullptr;
301-
return dependencySources.back().getPointer();
307+
switch (mode) {
308+
case Mode::StatusQuo:
309+
return dependencySources.back().getPointer();
310+
case Mode::ExperimentalPrivateDependencies:
311+
return dependencySources.front().getPointer();
312+
}
302313
}
303314

304315
public:
@@ -331,14 +342,6 @@ struct DependencyRecorder {
331342
};
332343

333344
private:
334-
/// Returns the first dependency source registered with the tracker, or
335-
/// \c nullptr if no dependency sources have been registered.
336-
SourceFile *getFirstDependencySourceOrNull() const {
337-
if (dependencySources.empty())
338-
return nullptr;
339-
return dependencySources.front().getPointer();
340-
}
341-
342345
/// Returns \c true if the scope of the current active source cascades.
343346
///
344347
/// If there is no active scope, the result always cascades.

include/swift/AST/Expr.h

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,10 +3770,7 @@ class ClosureExpr : public AbstractClosureExpr {
37703770
/// the CaptureListExpr which would normally maintain this sort of
37713771
/// information about captured variables), we need to have some way to access
37723772
/// this information directly on the ClosureExpr.
3773-
///
3774-
/// The bit indicates whether this closure has had a function builder
3775-
/// applied to it.
3776-
llvm::PointerIntPair<VarDecl *, 1, bool> CapturedSelfDeclAndAppliedBuilder;
3773+
VarDecl * CapturedSelfDecl;
37773774

37783775
/// The location of the "throws", if present.
37793776
SourceLoc ThrowsLoc;
@@ -3787,7 +3784,7 @@ class ClosureExpr : public AbstractClosureExpr {
37873784

37883785
/// The explicitly-specified result type.
37893786
llvm::PointerIntPair<TypeExpr *, 1, bool>
3790-
ExplicitResultTypeAndEnclosingChecked;
3787+
ExplicitResultTypeAndSeparatelyChecked;
37913788

37923789
/// The body of the closure, along with a bit indicating whether it
37933790
/// was originally just a single expression.
@@ -3800,9 +3797,9 @@ class ClosureExpr : public AbstractClosureExpr {
38003797
: AbstractClosureExpr(ExprKind::Closure, Type(), /*Implicit=*/false,
38013798
discriminator, parent),
38023799
BracketRange(bracketRange),
3803-
CapturedSelfDeclAndAppliedBuilder(capturedSelfDecl, false),
3800+
CapturedSelfDecl(capturedSelfDecl),
38043801
ThrowsLoc(throwsLoc), ArrowLoc(arrowLoc), InLoc(inLoc),
3805-
ExplicitResultTypeAndEnclosingChecked(explicitResultType, false),
3802+
ExplicitResultTypeAndSeparatelyChecked(explicitResultType, false),
38063803
Body(nullptr) {
38073804
setParameterList(params);
38083805
Bits.ClosureExpr.HasAnonymousClosureVars = false;
@@ -3857,14 +3854,14 @@ class ClosureExpr : public AbstractClosureExpr {
38573854

38583855
Type getExplicitResultType() const {
38593856
assert(hasExplicitResultType() && "No explicit result type");
3860-
return ExplicitResultTypeAndEnclosingChecked.getPointer()
3857+
return ExplicitResultTypeAndSeparatelyChecked.getPointer()
38613858
->getInstanceType();
38623859
}
38633860
void setExplicitResultType(Type ty);
38643861

38653862
TypeRepr *getExplicitResultTypeRepr() const {
38663863
assert(hasExplicitResultType() && "No explicit result type");
3867-
return ExplicitResultTypeAndEnclosingChecked.getPointer()
3864+
return ExplicitResultTypeAndSeparatelyChecked.getPointer()
38683865
->getTypeRepr();
38693866
}
38703867

@@ -3894,42 +3891,27 @@ class ClosureExpr : public AbstractClosureExpr {
38943891
/// Only valid when \c hasSingleExpressionBody() is true.
38953892
Expr *getSingleExpressionBody() const;
38963893

3897-
/// Set the body for a closure that has a single expression as its
3898-
/// body.
3899-
///
3900-
/// This routine cannot change whether a closure has a single expression as
3901-
/// its body; it can only update that expression.
3902-
void setSingleExpressionBody(Expr *NewBody);
3903-
39043894
/// Is this a completely empty closure?
39053895
bool hasEmptyBody() const;
39063896

39073897
/// VarDecl captured by this closure under the literal name \c self , if any.
39083898
VarDecl *getCapturedSelfDecl() const {
3909-
return CapturedSelfDeclAndAppliedBuilder.getPointer();
3899+
return CapturedSelfDecl;
39103900
}
39113901

39123902
/// Whether this closure captures the \c self param in its body in such a
39133903
/// way that implicit \c self is enabled within its body (i.e. \c self is
39143904
/// captured non-weakly).
39153905
bool capturesSelfEnablingImplictSelf() const;
39163906

3917-
bool hasAppliedFunctionBuilder() const {
3918-
return CapturedSelfDeclAndAppliedBuilder.getInt();
3919-
}
3920-
3921-
void setAppliedFunctionBuilder(bool flag = true) {
3922-
CapturedSelfDeclAndAppliedBuilder.setInt(flag);
3923-
}
3924-
3925-
/// Whether this closure's body was type checked within the enclosing
3926-
/// context.
3927-
bool wasTypeCheckedInEnclosingContext() const {
3928-
return ExplicitResultTypeAndEnclosingChecked.getInt();
3907+
/// Whether this closure's body was type checked separately from its
3908+
/// enclosing expression.
3909+
bool wasSeparatelyTypeChecked() const {
3910+
return ExplicitResultTypeAndSeparatelyChecked.getInt();
39293911
}
39303912

3931-
void setTypeCheckedInEnclosingContext(bool flag = true) {
3932-
ExplicitResultTypeAndEnclosingChecked.setInt(flag);
3913+
void setSeparatelyTypeChecked(bool flag = true) {
3914+
ExplicitResultTypeAndSeparatelyChecked.setInt(flag);
39333915
}
39343916

39353917
static bool classof(const Expr *E) {

include/swift/AST/IRGenOptions.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ enum class IRGenDebugInfoFormat : unsigned {
6565
CodeView
6666
};
6767

68+
enum class IRGenLLVMLTOKind : unsigned {
69+
None,
70+
Thin,
71+
Full
72+
};
73+
6874
enum class IRGenEmbedMode : unsigned {
6975
None,
7076
EmbedMarker,
@@ -217,6 +223,8 @@ class IRGenOptions {
217223
/// Whether we should embed the bitcode file.
218224
IRGenEmbedMode EmbedMode : 2;
219225

226+
IRGenLLVMLTOKind LLVMLTOKind: 2;
227+
220228
/// Add names to LLVM values.
221229
unsigned HasValueNamesSetting : 1;
222230
unsigned ValueNames : 1;
@@ -318,6 +326,7 @@ class IRGenOptions {
318326
DisableSwiftSpecificLLVMOptzns(false), DisableLLVMSLPVectorizer(false),
319327
Playground(false), EmitStackPromotionChecks(false),
320328
FunctionSections(false), PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
329+
LLVMLTOKind(IRGenLLVMLTOKind::None),
321330
HasValueNamesSetting(false), ValueNames(false),
322331
EnableReflectionMetadata(true), EnableReflectionNames(true),
323332
EnableAnonymousContextMangledNames(false), ForcePublicLinkage(false),

include/swift/AST/NameLookupRequests.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ class LookupInModuleRequest
447447
QualifiedLookupResult(
448448
const DeclContext *, DeclName, NLKind,
449449
namelookup::ResolutionKind, const DeclContext *),
450-
RequestFlags::Uncached> {
450+
RequestFlags::Uncached | RequestFlags::DependencySink> {
451451
public:
452452
using SimpleRequest::SimpleRequest;
453453

@@ -459,6 +459,11 @@ class LookupInModuleRequest
459459
evaluate(Evaluator &evaluator, const DeclContext *moduleOrFile, DeclName name,
460460
NLKind lookupKind, namelookup::ResolutionKind resolutionKind,
461461
const DeclContext *moduleScopeContext) const;
462+
463+
public:
464+
// Incremental dependencies
465+
void writeDependencySink(evaluator::DependencyCollector &tracker,
466+
QualifiedLookupResult l) const;
462467
};
463468

464469
/// Perform \c AnyObject lookup for a given member.

0 commit comments

Comments
 (0)