Skip to content

[pull] swiftwasm from main #2345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8472616
Make python_format script executable
keith Oct 19, 2020
22b34e8
[CSBindings] Let producer record a binding for a hole
xedin Dec 10, 2020
8e4207e
[ConstraintSystem] NFC: Simplify type var producer/step by referencin…
xedin Dec 11, 2020
0e6a0b8
Add debug info support for function arguments in async functions.
adrian-prantl Dec 9, 2020
9ac3b0e
[Runtime] Add a disabled workaround for protocol conformance checking…
mikeash Dec 8, 2020
e23f0ab
[concurrency] patch hole in typechecking ordinary functions for globa…
kavon Dec 11, 2020
dbd5b27
Add -sil-verify-all and -sil-verify-none to the sil-opt tool.
atrick Dec 11, 2020
296ab5f
Merge pull request #35044 from xedin/refactor-hole-binding
xedin Dec 14, 2020
08da9cf
Check stderr when looking for incremental remarks.
Dec 14, 2020
9671dbf
Merge pull request #35028 from adrian-prantl/71866936
adrian-prantl Dec 14, 2020
af58ed4
Fix another test
Dec 11, 2020
d7b813b
[sourcekit] Identify xpc service by toolchain instead of sdk
benlangmuir Dec 14, 2020
aac942c
Merge pull request #35061 from mikeash/protocol-conformance-iteration…
mikeash Dec 14, 2020
8d86140
[AudoDiff] NFC: Replace 'SILAutoDiffIndices' with 'AutoDiffConfig'. (…
rxwei Dec 14, 2020
0557e74
Merge pull request #34351 from keith/ks/make-python_format-script-exe…
CodaFi Dec 14, 2020
16bb57e
Merge pull request #35083 from atrick/sil-verify-none
atrick Dec 14, 2020
e8dcc97
fix-it regression coverage for notes suggesting 'async', '@asyncHandl…
kavon Dec 14, 2020
3c26585
Merge pull request #35087 from davidungar/fixing-tests-2
Dec 15, 2020
04ec96e
Merge pull request #35086 from benlangmuir/rdar72310494
benlangmuir Dec 15, 2020
1eb810f
Merge pull request #35048 from kavon/typechecking-unspecified-isolati…
swift-ci Dec 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 30 additions & 51 deletions include/swift/AST/AutoDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,80 +173,59 @@ enum class AutoDiffGeneratedDeclarationKind : uint8_t {
BranchingTraceEnum
};

/// SIL-level automatic differentiation indices. Consists of:
/// - The differentiability parameter indices.
/// - The differentiability result indices.
// TODO(TF-913): Remove `SILAutoDiffIndices` in favor of `AutoDiffConfig`.
// `AutoDiffConfig` additionally stores a derivative generic signature.
struct SILAutoDiffIndices {
/// The indices of independent parameters to differentiate with respect to.
IndexSubset *parameters;
/// The indices of dependent results to differentiate from.
IndexSubset *results;

/*implicit*/ SILAutoDiffIndices(IndexSubset *parameters, IndexSubset *results)
: parameters(parameters), results(results) {
assert(parameters && "Parameter indices must be non-null");
assert(results && "Result indices must be non-null");
}

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

bool operator!=(const SILAutoDiffIndices &other) const {
return !(*this == other);
};
/// Identifies an autodiff derivative function configuration:
/// - Parameter indices.
/// - Result indices.
/// - Derivative generic signature (optional).
struct AutoDiffConfig {
IndexSubset *parameterIndices;
IndexSubset *resultIndices;
GenericSignature derivativeGenericSignature;

/*implicit*/ AutoDiffConfig(
IndexSubset *parameterIndices, IndexSubset *resultIndices,
GenericSignature derivativeGenericSignature = GenericSignature())
: parameterIndices(parameterIndices), resultIndices(resultIndices),
derivativeGenericSignature(derivativeGenericSignature) {}

/// Returns true if `parameterIndex` is a differentiability parameter index.
bool isWrtParameter(unsigned parameterIndex) const {
return parameterIndex < parameters->getCapacity() &&
parameters->contains(parameterIndex);
return parameterIndex < parameterIndices->getCapacity() &&
parameterIndices->contains(parameterIndex);
}

void print(llvm::raw_ostream &s = llvm::outs()) const;
SWIFT_DEBUG_DUMP;
/// Returns true if `resultIndex` is a differentiability result index.
bool isWrtResult(unsigned resultIndex) const {
return resultIndex < resultIndices->getCapacity() &&
resultIndices->contains(resultIndex);
}

AutoDiffConfig withGenericSignature(GenericSignature signature) const {
return AutoDiffConfig(parameterIndices, resultIndices, signature);
}

// TODO(SR-13506): Use principled mangling for AD-generated symbols.
std::string mangle() const {
std::string result = "src_";
interleave(
results->getIndices(),
resultIndices->getIndices(),
[&](unsigned idx) { result += llvm::utostr(idx); },
[&] { result += '_'; });
result += "_wrt_";
llvm::interleave(
parameters->getIndices(),
parameterIndices->getIndices(),
[&](unsigned idx) { result += llvm::utostr(idx); },
[&] { result += '_'; });
return result;
}
};

/// Identifies an autodiff derivative function configuration:
/// - Parameter indices.
/// - Result indices.
/// - Derivative generic signature (optional).
struct AutoDiffConfig {
IndexSubset *parameterIndices;
IndexSubset *resultIndices;
GenericSignature derivativeGenericSignature;

/*implicit*/ AutoDiffConfig(IndexSubset *parameterIndices,
IndexSubset *resultIndices,
GenericSignature derivativeGenericSignature)
: parameterIndices(parameterIndices), resultIndices(resultIndices),
derivativeGenericSignature(derivativeGenericSignature) {}

/// Returns the `SILAutoDiffIndices` corresponding to this config's indices.
// TODO(TF-913): This is a temporary shim for incremental removal of
// `SILAutoDiffIndices`. Eventually remove this.
SILAutoDiffIndices getSILAutoDiffIndices() const;

void print(llvm::raw_ostream &s = llvm::outs()) const;
SWIFT_DEBUG_DUMP;
};

inline llvm::raw_ostream &operator<<(llvm::raw_ostream &s,
const SILAutoDiffIndices &indices) {
indices.print(s);
const AutoDiffConfig &config) {
config.print(s);
return s;
}

Expand Down
12 changes: 8 additions & 4 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -4132,6 +4132,10 @@ NOTE(note_add_async_to_function,none,
"add 'async' to function %0 to make it asynchronous", (DeclName))
NOTE(note_add_asynchandler_to_function,none,
"add '@asyncHandler' to function %0 to create an implicit asynchronous context", (DeclName))
NOTE(note_add_globalactor_to_function,none,
"add '@%0' to make %1 %2 part of global actor %3",
(StringRef, DescriptiveDeclKind, DeclName, Type))
FIXIT(insert_globalactor_attr, "@%0 ", (Type))
ERROR(not_objc_function_async,none,
"'async' function cannot be represented in Objective-C", ())
NOTE(not_objc_function_type_async,none,
Expand Down Expand Up @@ -4217,10 +4221,10 @@ ERROR(global_actor_from_other_global_actor_context,none,
"%0 %1 isolated to global actor %2 can not be referenced from "
"different global actor %3",
(DescriptiveDeclKind, DeclName, Type, Type))
ERROR(global_actor_from_independent_context,none,
"%0 %1 isolated to global actor %2 can not be referenced from an "
"'@actorIndependent' context",
(DescriptiveDeclKind, DeclName, Type))
ERROR(global_actor_from_nonactor_context,none,
"%0 %1 isolated to global actor %2 can not be referenced from "
"%select{this|an '@actorIndependent'}3 context",
(DescriptiveDeclKind, DeclName, Type, bool))
ERROR(actor_isolated_partial_apply,none,
"actor-isolated %0 %1 can not be partially applied",
(DescriptiveDeclKind, DeclName))
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/IndexSubset.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class IndexSubset : public llvm::FoldingSetNode {
/// Returns the number of bit words used to store the index subset.
// Note: Use `getCapacity()` to get the total index subset capacity.
// This is public only for unit testing
// (in unittests/AST/SILAutoDiffIndices.cpp).
// (in unittests/AST/IndexSubsetTests.cpp).
unsigned getNumBitWords() const {
return numBitWords;
}
Expand Down
31 changes: 31 additions & 0 deletions include/swift/Runtime/Bincompat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===--- Bincompat.h - Binary compatibility checks. -------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Checks for enabling binary compatibility workarounds.
//
//===----------------------------------------------------------------------===//

namespace swift {

namespace runtime {

namespace bincompat {

/// Whether protocol conformance iteration should be reversed, to prefer
/// conformances from images that are later in the list over earlier ones.
bool workaroundProtocolConformanceReverseIteration();

} // namespace bincompat

} // namespace runtime

} // namespace swift
5 changes: 0 additions & 5 deletions include/swift/SIL/SILDifferentiabilityWitness.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ class SILDifferentiabilityWitness
bool isSerialized() const { return IsSerialized; }
const DeclAttribute *getAttribute() const { return Attribute; }

/// Returns the `SILAutoDiffIndices` corresponding to this config's indices.
// TODO(TF-893): This is a temporary shim for incremental removal of
// `SILAutoDiffIndices`. Eventually remove this.
SILAutoDiffIndices getSILAutoDiffIndices() const;

/// Verify that the differentiability witness is well-formed.
void verify(const SILModule &module) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,47 @@ class DifferentiableActivityInfo {
/// (dependent variable) indices.
bool isUseful(SILValue value, IndexSubset *dependentVariableIndices) const;

/// Returns true if the given value is active for the given
/// `SILAutoDiffIndices` (parameter indices and result index).
bool isActive(SILValue value, const SILAutoDiffIndices &indices) const;
/// Returns true if the given value is active for the given parameter indices
/// and result indices.
bool isActive(SILValue value,
IndexSubset *parameterIndices,
IndexSubset *resultIndices) const;

/// Returns true if the given value is active for the given config.
bool isActive(SILValue value, AutoDiffConfig config) const {
return isActive(value, config.parameterIndices, config.resultIndices);
}

/// Returns the activity of the given value for the given config.
Activity getActivity(SILValue value,
IndexSubset *parameterIndices,
IndexSubset *resultIndices) const;

/// Returns the activity of the given value for the given `SILAutoDiffIndices`
/// (parameter indices and result index).
Activity getActivity(SILValue value, const SILAutoDiffIndices &indices) const;
/// Returns the activity of the given value for the given config.
Activity getActivity(SILValue value, AutoDiffConfig config) const {
return getActivity(value, config.parameterIndices, config.resultIndices);
}

/// Prints activity information for the `indices` of the given `value`.
void dump(SILValue value, const SILAutoDiffIndices &indices,
/// Prints activity information for the config of the given value.
void dump(SILValue value,
IndexSubset *parameterIndices, IndexSubset *resultIndices,
llvm::raw_ostream &s = llvm::dbgs()) const;

/// Prints activity information for the given `indices`.
void dump(SILAutoDiffIndices indices,
/// Prints activity information for the config of the given value.
void dump(SILValue value, AutoDiffConfig config,
llvm::raw_ostream &s = llvm::dbgs()) const {
return dump(value, config.parameterIndices, config.resultIndices, s);
}

/// Prints all activity information for the given parameter indices and result
/// indices.
void dump(IndexSubset *parameterIndices, IndexSubset *resultIndices,
llvm::raw_ostream &s = llvm::dbgs()) const;

/// Prints all activity information for the given config.
void dump(AutoDiffConfig config, llvm::raw_ostream &s = llvm::dbgs()) const {
return dump(config.parameterIndices, config.resultIndices, s);
}
};

class DifferentiableActivityCollection {
Expand Down
7 changes: 5 additions & 2 deletions include/swift/SILOptimizer/Differentiation/ADContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ namespace autodiff {

/// Stores `apply` instruction information calculated by VJP generation.
struct NestedApplyInfo {
/// The differentiation indices that are used to differentiate this `apply`
/// The differentiation config that is used to differentiate this `apply`
/// instruction.
SILAutoDiffIndices indices;
AutoDiffConfig config;
/// The original pullback type before reabstraction. `None` if the pullback
/// type is not reabstracted.
Optional<CanSILFunctionType> originalPullbackType;
Expand Down Expand Up @@ -120,6 +120,9 @@ class ADContext {
/// Construct an ADContext for the given module.
explicit ADContext(SILModuleTransform &transform);

// No copying.
ADContext(const ADContext &) = delete;

//--------------------------------------------------------------------------//
// General utilities
//--------------------------------------------------------------------------//
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Differentiation/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void collectAllActualResultsInTypeOrder(
/// - The set of minimal parameter and result indices for differentiating the
/// `apply` instruction.
void collectMinimalIndicesForFunctionCall(
ApplyInst *ai, SILAutoDiffIndices parentIndices,
ApplyInst *ai, AutoDiffConfig parentConfig,
const DifferentiableActivityInfo &activityInfo,
SmallVectorImpl<SILValue> &results, SmallVectorImpl<unsigned> &paramIndices,
SmallVectorImpl<unsigned> &resultIndices);
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SILOptimizer/Differentiation/LinearMapInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class LinearMapInfo {
SILLoopInfo *loopInfo;

/// Differentiation indices of the function.
const SILAutoDiffIndices indices;
const AutoDiffConfig config;

/// Mapping from original basic blocks to linear map structs.
llvm::DenseMap<SILBasicBlock *, StructDecl *> linearMapStructs;
Expand Down Expand Up @@ -149,7 +149,7 @@ class LinearMapInfo {

explicit LinearMapInfo(ADContext &context, AutoDiffLinearMapKind kind,
SILFunction *original, SILFunction *derivative,
SILAutoDiffIndices indices,
AutoDiffConfig config,
const DifferentiableActivityInfo &activityInfo,
SILLoopInfo *loopInfo);

Expand Down
6 changes: 3 additions & 3 deletions include/swift/SILOptimizer/Differentiation/Thunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ SILValue reabstractFunction(
std::pair<SILFunction *, SubstitutionMap>
getOrCreateSubsetParametersThunkForDerivativeFunction(
SILOptFunctionBuilder &fb, SILValue origFnOperand, SILValue derivativeFn,
AutoDiffDerivativeFunctionKind kind, SILAutoDiffIndices desiredIndices,
SILAutoDiffIndices actualIndices);
AutoDiffDerivativeFunctionKind kind, AutoDiffConfig desiredConfig,
AutoDiffConfig actualConfig);

/// Get or create a derivative function parameter index subset thunk from
/// `actualIndices` to `desiredIndices` for the given associated function
Expand All @@ -119,7 +119,7 @@ getOrCreateSubsetParametersThunkForLinearMap(
SILOptFunctionBuilder &fb, SILFunction *assocFn,
CanSILFunctionType origFnType, CanSILFunctionType linearMapType,
CanSILFunctionType targetType, AutoDiffDerivativeFunctionKind kind,
SILAutoDiffIndices desiredIndices, SILAutoDiffIndices actualIndices);
AutoDiffConfig desiredConfig, AutoDiffConfig actualConfig);

} // end namespace autodiff

Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Differentiation/VJPCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class VJPCloner final {
SILFunction &getVJP() const;
SILFunction &getPullback() const;
SILDifferentiabilityWitness *getWitness() const;
const SILAutoDiffIndices getIndices() const;
AutoDiffConfig getConfig() const;
DifferentiationInvoker getInvoker() const;
LinearMapInfo &getPullbackInfo() const;
SILLoopInfo *getLoopInfo() const;
Expand Down
Loading