Skip to content

[pull] swiftwasm from master #1284

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 17 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1560d65
Fixes example snippet in Sequence.swift
valeriyvan Jun 21, 2020
1052d3c
[AutoDiff] Simplify basic block active value collection.
dan-zheng Jun 18, 2020
f163072
[AutoDiff] Add TangentStoredPropertyRequest.
dan-zheng Jun 22, 2020
c690ac8
[AutoDiff] Improve invalid stored property projection diagnostics.
dan-zheng Jun 22, 2020
130a02e
tests: loosen overly-restrictive test patterns
compnerd Jun 22, 2020
2c6d7d7
[Runtime] Add entry point to compare type context descriptors.
nate-chandler Jun 19, 2020
3d3a3c2
[verifier] Do not use llvm::report_fatal_error since it swallows Pret…
gottesmm Jun 22, 2020
a3b093a
Merge pull request #32486 from valeriyvan/FixExampleSnippetSequence
CodaFi Jun 22, 2020
aa5d671
Merge pull request #32498 from compnerd/separator-spelling
compnerd Jun 22, 2020
ecad335
Merge pull request #32476 from nate-chandler/runtime/add-swift_compar…
swift-ci Jun 22, 2020
865224a
Merge pull request #32500 from gottesmm/pr-5bf52cd2656f1b9313339bfb9c…
swift-ci Jun 22, 2020
4cd754e
[DepScan] NFC: Remove check for OnoneSupport
hamishknight Jun 22, 2020
1d4f617
Extend AllocBoxToStack to handle apply (#31974)
meg-gupta Jun 22, 2020
6d0c34c
[Runtime] Add entry point to compare conformance descriptors.
nate-chandler Jun 19, 2020
0717ba4
Merge pull request #32497 from dan-zheng/autodiff-tangent-stored-prop…
dan-zheng Jun 22, 2020
79c38b2
Merge pull request #32501 from hamishknight/scan-none
hamishknight Jun 23, 2020
236237f
Merge pull request #32471 from nate-chandler/runtime/add-swift_compar…
swift-ci Jun 23, 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
9 changes: 9 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ class ASTContext final {
/// metadata.
AvailabilityContext getPrespecializedGenericMetadataAvailability();

/// Get the runtime availability of the swift_compareTypeContextDescriptors
/// for the target platform.
AvailabilityContext getCompareTypeContextDescriptorsAvailability();

/// Get the runtime availability of the
/// swift_compareProtocolConformanceDescriptors entry point for the target
/// platform.
AvailabilityContext getCompareProtocolConformanceDescriptorsAvailability();

/// Get the runtime availability of features introduced in the Swift 5.2
/// compiler for the target platform.
AvailabilityContext getSwift52Availability();
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/ASTTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SWIFT_TYPEID(PropertyWrapperTypeInfo)
SWIFT_TYPEID(Requirement)
SWIFT_TYPEID(ResilienceExpansion)
SWIFT_TYPEID(FragileFunctionKind)
SWIFT_TYPEID(TangentPropertyInfo)
SWIFT_TYPEID(Type)
SWIFT_TYPEID(TypePair)
SWIFT_TYPEID(TypeWitnessAndDecl)
Expand Down
9 changes: 5 additions & 4 deletions include/swift/AST/ASTTypeIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "swift/Basic/LLVM.h"
#include "swift/Basic/TypeID.h"

namespace swift {

class AbstractFunctionDecl;
Expand Down Expand Up @@ -58,14 +59,14 @@ class Requirement;
enum class ResilienceExpansion : unsigned;
struct FragileFunctionKind;
class SourceFile;
struct TangentPropertyInfo;
class Type;
class ValueDecl;
class VarDecl;
class Witness;
class TypeAliasDecl;
class Type;
struct TypePair;
struct TypeWitnessAndDecl;
class ValueDecl;
class VarDecl;
class Witness;
enum class AncestryFlags : uint8_t;
enum class ImplicitMemberAction : uint8_t;
struct FingerprintAndMembers;
Expand Down
94 changes: 94 additions & 0 deletions include/swift/AST/AutoDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AnyFunctionType;
class SourceFile;
class SILFunctionType;
class TupleType;
class VarDecl;

/// A function type differentiability kind.
enum class DifferentiabilityKind : uint8_t {
Expand Down Expand Up @@ -459,6 +460,99 @@ class DerivativeFunctionTypeError
}
};

/// Describes the "tangent stored property" corresponding to an original stored
/// property in a `Differentiable`-conforming type.
///
/// The tangent stored property is the stored property in the `TangentVector`
/// struct of the `Differentiable`-conforming type, with the same name as the
/// original stored property and with the original stored property's
/// `TangentVector` type.
struct TangentPropertyInfo {
struct Error {
enum class Kind {
/// The original property is `@noDerivative`.
NoDerivativeOriginalProperty,
/// The nominal parent type does not conform to `Differentiable`.
NominalParentNotDifferentiable,
/// The original property's type does not conform to `Differentiable`.
OriginalPropertyNotDifferentiable,
/// The parent `TangentVector` type is not a struct.
ParentTangentVectorNotStruct,
/// The parent `TangentVector` struct does not declare a stored property
/// with the same name as the original property.
TangentPropertyNotFound,
/// The tangent property's type is not equal to the original property's
/// `TangentVector` type.
TangentPropertyWrongType,
/// The tangent property is not a stored property.
TangentPropertyNotStored
};

/// The error kind.
Kind kind;

private:
union Value {
Type type;
Value(Type type) : type(type) {}
Value() {}
} value;

public:
Error(Kind kind) : kind(kind), value() {
assert(kind == Kind::NoDerivativeOriginalProperty ||
kind == Kind::NominalParentNotDifferentiable ||
kind == Kind::OriginalPropertyNotDifferentiable ||
kind == Kind::ParentTangentVectorNotStruct ||
kind == Kind::TangentPropertyNotFound ||
kind == Kind::TangentPropertyNotStored);
};

Error(Kind kind, Type type) : kind(kind), value(type) {
assert(kind == Kind::TangentPropertyWrongType);
};

Type getType() const {
assert(kind == Kind::TangentPropertyWrongType);
return value.type;
}

friend bool operator==(const Error &lhs, const Error &rhs);
};

/// The tangent stored property.
VarDecl *tangentProperty = nullptr;

/// An optional error.
Optional<Error> error = None;

private:
TangentPropertyInfo(VarDecl *tangentProperty, Optional<Error> error)
: tangentProperty(tangentProperty), error(error) {}

public:
TangentPropertyInfo(VarDecl *tangentProperty)
: TangentPropertyInfo(tangentProperty, None) {}

TangentPropertyInfo(Error::Kind errorKind)
: TangentPropertyInfo(nullptr, Error(errorKind)) {}

TangentPropertyInfo(Error::Kind errorKind, Type errorType)
: TangentPropertyInfo(nullptr, Error(errorKind, errorType)) {}

/// Returns `true` iff this tangent property info is valid.
bool isValid() const { return tangentProperty && !error; }

explicit operator bool() const { return isValid(); }

friend bool operator==(const TangentPropertyInfo &lhs,
const TangentPropertyInfo &rhs) {
return lhs.tangentProperty == rhs.tangentProperty && lhs.error == rhs.error;
}
};

void simple_display(llvm::raw_ostream &OS, TangentPropertyInfo info);

/// The key type used for uniquing `SILDifferentiabilityWitness` in
/// `SILModule`: original function name, parameter indices, result indices, and
/// derivative generic signature.
Expand Down
21 changes: 19 additions & 2 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,26 @@ NOTE(autodiff_loadable_value_addressonly_tangent_unsupported,none,
"properties", (Type, Type))
NOTE(autodiff_enums_unsupported,none,
"differentiating enum values is not yet supported", ())
NOTE(autodiff_stored_property_parent_not_differentiable,none,
"cannot differentiate access to property '%0.%1' because '%0' does not "
"conform to 'Differentiable'", (StringRef, StringRef))
NOTE(autodiff_stored_property_not_differentiable,none,
"cannot differentiate access to property '%0.%1' because property type %2 "
"does not conform to 'Differentiable'", (StringRef, StringRef, Type))
NOTE(autodiff_stored_property_tangent_not_struct,none,
"cannot differentiate access to property '%0.%1' because "
"'%0.TangentVector' is not a struct", (StringRef, StringRef))
NOTE(autodiff_stored_property_no_corresponding_tangent,none,
"property cannot be differentiated because '%0.TangentVector' does not "
"have a member named '%1'", (StringRef, StringRef))
"cannot differentiate access to property '%0.%1' because "
"'%0.TangentVector' does not have a stored property named '%1'",
(StringRef, StringRef))
NOTE(autodiff_tangent_property_wrong_type,none,
"cannot differentiate access to property '%0.%1' because "
"'%0.TangentVector.%1' does not have expected type %2",
(StringRef, StringRef, /*originalPropertyTanType*/ Type))
NOTE(autodiff_tangent_property_not_stored,none,
"cannot differentiate access to property '%0.%1' because "
"'%0.TangentVector.%1' is not a stored property", (StringRef, StringRef))
NOTE(autodiff_coroutines_not_supported,none,
"differentiation of coroutine calls is not yet supported", ())
NOTE(autodiff_cannot_differentiate_writes_to_global_variables,none,
Expand Down
21 changes: 21 additions & 0 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,27 @@ class DerivativeAttrOriginalDeclRequest
bool isCached() const { return true; }
};

/// Resolves the "tangent stored property" corresponding to an original stored
/// property in a `Differentiable`-conforming type.
class TangentStoredPropertyRequest
: public SimpleRequest<TangentStoredPropertyRequest,
TangentPropertyInfo(VarDecl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

// Evaluation.
TangentPropertyInfo evaluate(Evaluator &evaluator,
VarDecl *originalField) const;

public:
// Caching.
bool isCached() const { return true; }
};

/// Checks whether a type eraser has a viable initializer.
class TypeEraserHasViableInitRequest
: public SimpleRequest<TypeEraserHasViableInitRequest,
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ SWIFT_REQUEST(TypeChecker, SuperclassTypeRequest,
SWIFT_REQUEST(TypeChecker, SynthesizeAccessorRequest,
AccessorDecl *(AbstractStorageDecl *, AccessorKind),
SeparatelyCached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, TangentStoredPropertyRequest,
llvm::Expected<VarDecl *>(VarDecl *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, TypeCheckFunctionBodyRequest,
bool(AbstractFunctionDecl *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, TypeCheckFunctionBodyAtLocRequest,
Expand Down
29 changes: 29 additions & 0 deletions include/swift/Runtime/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ const
/// the same context.
bool equalContexts(const ContextDescriptor *a, const ContextDescriptor *b);

/// Determines whether two type context descriptors describe the same type
/// context.
///
/// Runtime availability: Swift 5.4.
///
/// \param lhs The first type context descriptor to compare.
/// \param rhs The second type context descriptor to compare.
///
/// \returns true if both describe the same type context, false otherwise.
SWIFT_RUNTIME_EXPORT
SWIFT_CC(swift)
bool swift_compareTypeContextDescriptors(const TypeContextDescriptor *lhs,
const TypeContextDescriptor *rhs);

/// Compute the bounds of class metadata with a resilient superclass.
ClassMetadataBounds getResilientMetadataBounds(
const ClassDescriptor *descriptor);
Expand Down Expand Up @@ -409,6 +423,21 @@ const WitnessTable *swift_getAssociatedConformanceWitness(
const ProtocolRequirement *reqBase,
const ProtocolRequirement *assocConformance);

/// Determine whether two protocol conformance descriptors describe the same
/// conformance of a type to a protocol.
///
/// Runtime availability: Swift 5.4
///
/// \param lhs The first protocol conformance descriptor to compare.
/// \param rhs The second protocol conformance descriptor to compare.
///
/// \returns true if both describe the same conformance, false otherwise.
SWIFT_RUNTIME_EXPORT
SWIFT_CC(swift)
bool swift_compareProtocolConformanceDescriptors(
const ProtocolConformanceDescriptor *lhs,
const ProtocolConformanceDescriptor *rhs);

/// Fetch a uniqued metadata for a function type.
SWIFT_RUNTIME_EXPORT
const FunctionTypeMetadata *
Expand Down
24 changes: 24 additions & 0 deletions include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,18 @@ FUNCTION(GetForeignTypeMetadata, swift_getForeignTypeMetadata,
ARGS(SizeTy, TypeMetadataPtrTy),
ATTRS(NoUnwind, ReadNone)) // only writes to runtime-private fields

// SWIFT_RUNTIME_EXPORT
// SWIFT_CC(swift)
// bool swift_compareTypeContextDescriptors(const TypeContextDescriptor *lhs,
// const TypeContextDescriptor *rhs);
FUNCTION(CompareTypeContextDescriptors,
swift_compareTypeContextDescriptors, SwiftCC,
CompareTypeContextDescriptorsAvailability,
RETURNS(Int1Ty),
ARGS(TypeContextDescriptorPtrTy,
TypeContextDescriptorPtrTy),
ATTRS(NoUnwind, ReadNone))

// MetadataResponse swift_getSingletonMetadata(MetadataRequest request,
// TypeContextDescriptor *type);
FUNCTION(GetSingletonMetadata, swift_getSingletonMetadata,
Expand Down Expand Up @@ -723,6 +735,18 @@ FUNCTION(GetAssociatedConformanceWitness,
ProtocolRequirementStructTy->getPointerTo()),
ATTRS(NoUnwind, ReadNone))

// SWIFT_RUNTIME_EXPORT
// SWIFT_CC(swift) bool swift_compareProtocolConformanceDescriptors(
// const ProtocolConformanceDescriptor *lhs,
// const ProtocolConformanceDescriptor *rhs);
FUNCTION(CompareProtocolConformanceDescriptors,
swift_compareProtocolConformanceDescriptors, SwiftCC,
CompareProtocolConformanceDescriptorsAvailability,
RETURNS(Int1Ty),
ARGS(ProtocolConformanceDescriptorPtrTy,
ProtocolConformanceDescriptorPtrTy),
ATTRS(NoUnwind, ReadNone))

// Metadata *swift_getMetatypeMetadata(Metadata *instanceTy);
FUNCTION(GetMetatypeMetadata, swift_getMetatypeMetadata, C_CC, AlwaysAvailable,
RETURNS(TypeMetadataPtrTy),
Expand Down
7 changes: 7 additions & 0 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -5758,6 +5758,13 @@ class FieldIndexCacheBase : public SingleValueInstruction {
return s;
}

static bool classof(const SILNode *node) {
SILNodeKind kind = node->getKind();
return kind == SILNodeKind::StructExtractInst ||
kind == SILNodeKind::StructElementAddrInst ||
kind == SILNodeKind::RefElementAddrInst;
}

private:
unsigned cacheFieldIndex();
};
Expand Down
8 changes: 2 additions & 6 deletions include/swift/SILOptimizer/Differentiation/ADContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,9 @@ ADContext::emitNondifferentiabilityError(SILValue value,
getADDebugStream() << "For value:\n" << value;
getADDebugStream() << "With invoker:\n" << invoker << '\n';
});
auto valueLoc = value.getLoc().getSourceLoc();
// If instruction does not have a valid location, use the function location
// as a fallback. Improves diagnostics in some cases.
if (valueLoc.isInvalid())
valueLoc = value->getFunction()->getLocation().getSourceLoc();
auto valueLoc = getValidLocation(value).getSourceLoc();
return emitNondifferentiabilityError(valueLoc, invoker, diag,
std::forward<U>(args)...);
}
Expand All @@ -272,12 +270,10 @@ ADContext::emitNondifferentiabilityError(SILInstruction *inst,
getADDebugStream() << "For instruction:\n" << *inst;
getADDebugStream() << "With invoker:\n" << invoker << '\n';
});
auto instLoc = inst->getLoc().getSourceLoc();
// If instruction does not have a valid location, use the function location
// as a fallback. Improves diagnostics for `ref_element_addr` generated in
// synthesized stored property getters.
if (instLoc.isInvalid())
instLoc = inst->getFunction()->getLocation().getSourceLoc();
auto instLoc = getValidLocation(inst).getSourceLoc();
return emitNondifferentiabilityError(instLoc, invoker, diag,
std::forward<U>(args)...);
}
Expand Down
Loading