Skip to content

[pull] swiftwasm from master #1090

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 3 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ macro(configure_sdk_unix name architectures)

# If the module triple wasn't set explicitly, it's the same as the triple.
if(NOT SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE)
set(SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE "${SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE}")
set(SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE "${SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE}")
endif()
endforeach()

Expand Down Expand Up @@ -407,7 +407,7 @@ macro(configure_sdk_windows name environment architectures)
"${arch}-unknown-windows-${environment}")
endif()

set(SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE "${SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE}")
set(SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE "${SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE}")

# NOTE: set the path to / to avoid a spurious `--sysroot` from being passed
# to the driver -- rely on the `INCLUDE` AND `LIB` environment variables
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -2764,10 +2764,10 @@ WARNING(differentiable_nondiff_type_implicit_noderivative_fixit,none,
/*nominalCanDeriveAdditiveArithmetic*/ bool))
WARNING(differentiable_immutable_wrapper_implicit_noderivative_fixit,none,
"synthesis of the 'Differentiable.move(along:)' requirement for %1 "
"requires all stored properties not marked with `@noDerivative` to be "
"mutable; add an explicit '@noDerivative' attribute"
"requires 'wrappedValue' in property wrapper %0 to be mutable; "
"add an explicit '@noDerivative' attribute"
"%select{|, or conform %1 to 'AdditiveArithmetic'}2",
(/*wrapperType*/ StringRef, /*nominalName*/ Identifier,
(/*wrapperType*/ Identifier, /*nominalName*/ Identifier,
/*nominalCanDeriveAdditiveArithmetic*/ bool))
WARNING(differentiable_let_property_implicit_noderivative_fixit,none,
"synthesis of the 'Differentiable.move(along:)' requirement for %0 "
Expand Down
14 changes: 5 additions & 9 deletions lib/Sema/DerivedConformanceDifferentiable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ getStoredPropertiesForDifferentiation(NominalTypeDecl *nominal, DeclContext *DC,
if (auto *originalProperty = vd->getOriginalWrappedProperty()) {
// Skip immutable wrapped properties. `mutating func move(along:)` cannot
// be synthesized to update these properties.
auto mutability = originalProperty->getPropertyWrapperMutability();
assert(mutability.hasValue() && "Expected wrapped property mutability");
if (mutability->Setter != PropertyWrapperMutability::Value::Mutating)
if (!originalProperty->getAccessor(AccessorKind::Set))
continue;
// Use the original wrapped property.
vd = originalProperty;
Expand Down Expand Up @@ -508,19 +506,17 @@ static void checkAndDiagnoseImplicitNoDerivative(ASTContext &Context,
// Diagnose wrapped properties whose property wrappers do not define
// `wrappedValue.set`. `mutating func move(along:)` cannot be synthesized
// to update these properties.
auto *wrapperDecl =
vd->getInterfaceType()->getNominalOrBoundGenericNominal();
auto mutability = originalProperty->getPropertyWrapperMutability();
assert(mutability.hasValue() && "Expected wrapped property mutability");
if (mutability->Setter != PropertyWrapperMutability::Value::Mutating) {
if (!originalProperty->getAccessor(AccessorKind::Set)) {
auto *wrapperDecl =
vd->getInterfaceType()->getNominalOrBoundGenericNominal();
auto loc =
originalProperty->getAttributeInsertionLoc(/*forModifier*/ false);
Context.Diags
.diagnose(
loc,
diag::
differentiable_immutable_wrapper_implicit_noderivative_fixit,
wrapperDecl->getNameStr(), nominal->getName(),
wrapperDecl->getName(), nominal->getName(),
nominalCanDeriveAdditiveArithmetic)
.fixItInsert(loc, "@noDerivative ");
// Add an implicit `@noDerivative` attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,18 +541,29 @@ struct Wrapper<Value> {
var wrappedValue: Value
}

@propertyWrapper
class ClassWrapper<Value> {
var wrappedValue: Value
init(wrappedValue: Value) { self.wrappedValue = wrappedValue }
}

struct Generic<T> {}
extension Generic: Differentiable where T: Differentiable {}

class WrappedProperties: Differentiable {
// expected-warning @+1 {{synthesis of the 'Differentiable.move(along:)' requirement for 'WrappedProperties' requires all stored properties not marked with `@noDerivative` to be mutable; add an explicit '@noDerivative' attribute}}
// expected-warning @+1 {{synthesis of the 'Differentiable.move(along:)' requirement for 'WrappedProperties' requires 'wrappedValue' in property wrapper 'ImmutableWrapper' to be mutable; add an explicit '@noDerivative' attribute}}
@ImmutableWrapper var immutableInt: Generic<Int> = Generic()

// expected-warning @+1 {{stored property 'mutableInt' has no derivative because 'Generic<Int>' does not conform to 'Differentiable'; add an explicit '@noDerivative' attribute}}
@Wrapper var mutableInt: Generic<Int> = Generic()

@Wrapper var float: Generic<Float> = Generic()
@ClassWrapper var float2: Generic<Float> = Generic()
@noDerivative @ImmutableWrapper var nondiff: Generic<Int> = Generic()

static func testTangentMemberwiseInitializer() {
_ = TangentVector(float: .init(), float2: .init())
}
}

// Test derived conformances in disallowed contexts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,29 @@ struct Wrapper<Value> {
var wrappedValue: Value
}

@propertyWrapper
class ClassWrapper<Value> {
var wrappedValue: Value
init(wrappedValue: Value) { self.wrappedValue = wrappedValue }
}

struct Generic<T> {}
extension Generic: Differentiable where T: Differentiable {}

struct WrappedProperties: Differentiable {
// expected-warning @+1 {{synthesis of the 'Differentiable.move(along:)' requirement for 'WrappedProperties' requires all stored properties not marked with `@noDerivative` to be mutable; add an explicit '@noDerivative' attribute}}
// expected-warning @+1 {{synthesis of the 'Differentiable.move(along:)' requirement for 'WrappedProperties' requires 'wrappedValue' in property wrapper 'ImmutableWrapper' to be mutable; add an explicit '@noDerivative' attribute}}
@ImmutableWrapper var immutableInt: Generic<Int>

// expected-warning @+1 {{stored property 'mutableInt' has no derivative because 'Generic<Int>' does not conform to 'Differentiable'; add an explicit '@noDerivative' attribute}}
@Wrapper var mutableInt: Generic<Int>

@Wrapper var float: Generic<Float>
@ClassWrapper var float2: Generic<Float>
@noDerivative @ImmutableWrapper var nondiff: Generic<Int>

static func testTangentMemberwiseInitializer() {
_ = TangentVector(float: .init(), float2: .init())
}
}

// Verify that cross-file derived conformances are disallowed.
Expand Down