Skip to content

Commit 4499dd3

Browse files
Merge pull request #1090 from swiftwasm/master
[pull] swiftwasm from master
2 parents 6b21aa1 + 65d66da commit 4499dd3

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ macro(configure_sdk_unix name architectures)
374374

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

@@ -407,7 +407,7 @@ macro(configure_sdk_windows name environment architectures)
407407
"${arch}-unknown-windows-${environment}")
408408
endif()
409409

410-
set(SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE "${SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE}")
410+
set(SWIFT_SDK_${prefix}_ARCH_${arch}_MODULE "${SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE}")
411411

412412
# NOTE: set the path to / to avoid a spurious `--sysroot` from being passed
413413
# to the driver -- rely on the `INCLUDE` AND `LIB` environment variables

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,10 +2764,10 @@ WARNING(differentiable_nondiff_type_implicit_noderivative_fixit,none,
27642764
/*nominalCanDeriveAdditiveArithmetic*/ bool))
27652765
WARNING(differentiable_immutable_wrapper_implicit_noderivative_fixit,none,
27662766
"synthesis of the 'Differentiable.move(along:)' requirement for %1 "
2767-
"requires all stored properties not marked with `@noDerivative` to be "
2768-
"mutable; add an explicit '@noDerivative' attribute"
2767+
"requires 'wrappedValue' in property wrapper %0 to be mutable; "
2768+
"add an explicit '@noDerivative' attribute"
27692769
"%select{|, or conform %1 to 'AdditiveArithmetic'}2",
2770-
(/*wrapperType*/ StringRef, /*nominalName*/ Identifier,
2770+
(/*wrapperType*/ Identifier, /*nominalName*/ Identifier,
27712771
/*nominalCanDeriveAdditiveArithmetic*/ bool))
27722772
WARNING(differentiable_let_property_implicit_noderivative_fixit,none,
27732773
"synthesis of the 'Differentiable.move(along:)' requirement for %0 "

lib/Sema/DerivedConformanceDifferentiable.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ getStoredPropertiesForDifferentiation(NominalTypeDecl *nominal, DeclContext *DC,
4444
if (auto *originalProperty = vd->getOriginalWrappedProperty()) {
4545
// Skip immutable wrapped properties. `mutating func move(along:)` cannot
4646
// be synthesized to update these properties.
47-
auto mutability = originalProperty->getPropertyWrapperMutability();
48-
assert(mutability.hasValue() && "Expected wrapped property mutability");
49-
if (mutability->Setter != PropertyWrapperMutability::Value::Mutating)
47+
if (!originalProperty->getAccessor(AccessorKind::Set))
5048
continue;
5149
// Use the original wrapped property.
5250
vd = originalProperty;
@@ -508,19 +506,17 @@ static void checkAndDiagnoseImplicitNoDerivative(ASTContext &Context,
508506
// Diagnose wrapped properties whose property wrappers do not define
509507
// `wrappedValue.set`. `mutating func move(along:)` cannot be synthesized
510508
// to update these properties.
511-
auto *wrapperDecl =
512-
vd->getInterfaceType()->getNominalOrBoundGenericNominal();
513-
auto mutability = originalProperty->getPropertyWrapperMutability();
514-
assert(mutability.hasValue() && "Expected wrapped property mutability");
515-
if (mutability->Setter != PropertyWrapperMutability::Value::Mutating) {
509+
if (!originalProperty->getAccessor(AccessorKind::Set)) {
510+
auto *wrapperDecl =
511+
vd->getInterfaceType()->getNominalOrBoundGenericNominal();
516512
auto loc =
517513
originalProperty->getAttributeInsertionLoc(/*forModifier*/ false);
518514
Context.Diags
519515
.diagnose(
520516
loc,
521517
diag::
522518
differentiable_immutable_wrapper_implicit_noderivative_fixit,
523-
wrapperDecl->getNameStr(), nominal->getName(),
519+
wrapperDecl->getName(), nominal->getName(),
524520
nominalCanDeriveAdditiveArithmetic)
525521
.fixItInsert(loc, "@noDerivative ");
526522
// Add an implicit `@noDerivative` attribute.

test/AutoDiff/Sema/DerivedConformances/class_differentiable.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,29 @@ struct Wrapper<Value> {
541541
var wrappedValue: Value
542542
}
543543

544+
@propertyWrapper
545+
class ClassWrapper<Value> {
546+
var wrappedValue: Value
547+
init(wrappedValue: Value) { self.wrappedValue = wrappedValue }
548+
}
549+
544550
struct Generic<T> {}
545551
extension Generic: Differentiable where T: Differentiable {}
546552

547553
class WrappedProperties: Differentiable {
548-
// 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}}
554+
// 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}}
549555
@ImmutableWrapper var immutableInt: Generic<Int> = Generic()
550556

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

554560
@Wrapper var float: Generic<Float> = Generic()
561+
@ClassWrapper var float2: Generic<Float> = Generic()
555562
@noDerivative @ImmutableWrapper var nondiff: Generic<Int> = Generic()
563+
564+
static func testTangentMemberwiseInitializer() {
565+
_ = TangentVector(float: .init(), float2: .init())
566+
}
556567
}
557568

558569
// Test derived conformances in disallowed contexts.

test/AutoDiff/Sema/DerivedConformances/struct_differentiable.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,29 @@ struct Wrapper<Value> {
354354
var wrappedValue: Value
355355
}
356356

357+
@propertyWrapper
358+
class ClassWrapper<Value> {
359+
var wrappedValue: Value
360+
init(wrappedValue: Value) { self.wrappedValue = wrappedValue }
361+
}
362+
357363
struct Generic<T> {}
358364
extension Generic: Differentiable where T: Differentiable {}
359365

360366
struct WrappedProperties: Differentiable {
361-
// 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}}
367+
// 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}}
362368
@ImmutableWrapper var immutableInt: Generic<Int>
363369

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

367373
@Wrapper var float: Generic<Float>
374+
@ClassWrapper var float2: Generic<Float>
368375
@noDerivative @ImmutableWrapper var nondiff: Generic<Int>
376+
377+
static func testTangentMemberwiseInitializer() {
378+
_ = TangentVector(float: .init(), float2: .init())
379+
}
369380
}
370381

371382
// Verify that cross-file derived conformances are disallowed.

0 commit comments

Comments
 (0)