Skip to content

Commit 570eaf3

Browse files
authored
[AutoDiff] Fix false Differentiable derived conformances warning. (#32527)
Fix false `Differentiable` derived conformances warning on `@differentiable` property-wrapped properties. Check property mutability using `VarDecl::isSettable` instead of `VarDecl::getAccessor(AccessorKind::Set)`. Some settable properties do not have setters, depending on the underlying `WriteImplKind`. Resolves SR-13071.
1 parent c825d79 commit 570eaf3

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/Sema/DerivedConformanceDifferentiable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ getStoredPropertiesForDifferentiation(NominalTypeDecl *nominal, DeclContext *DC,
4545
if (auto *originalProperty = vd->getOriginalWrappedProperty()) {
4646
// Skip immutable wrapped properties. `mutating func move(along:)` cannot
4747
// be synthesized to update these properties.
48-
if (!originalProperty->getAccessor(AccessorKind::Set))
48+
if (!originalProperty->isSettable(DC))
4949
continue;
5050
// Use the original wrapped property.
5151
vd = originalProperty;
@@ -791,7 +791,7 @@ static void checkAndDiagnoseImplicitNoDerivative(ASTContext &Context,
791791
// Diagnose wrapped properties whose property wrappers do not define
792792
// `wrappedValue.set`. `mutating func move(along:)` cannot be synthesized
793793
// to update these properties.
794-
if (!originalProperty->getAccessor(AccessorKind::Set)) {
794+
if (!originalProperty->isSettable(DC)) {
795795
auto *wrapperDecl =
796796
vd->getInterfaceType()->getNominalOrBoundGenericNominal();
797797
auto loc =

test/AutoDiff/Sema/DerivedConformances/class_differentiable.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ class SR_12793: Differentiable {
525525
}
526526

527527
// Test property wrappers.
528-
// TF-1190: Test `@noDerivative` warning for property wrapper backing storage properties.
529528

530529
@propertyWrapper
531530
struct ImmutableWrapper<Value> {
@@ -559,10 +558,13 @@ class WrappedProperties: Differentiable {
559558

560559
@Wrapper var float: Generic<Float> = Generic()
561560
@ClassWrapper var float2: Generic<Float> = Generic()
561+
// SR-13071: Test `@differentiable` wrapped property.
562+
@differentiable @Wrapper var float3: Generic<Float> = Generic()
563+
562564
@noDerivative @ImmutableWrapper var nondiff: Generic<Int> = Generic()
563565

564566
static func testTangentMemberwiseInitializer() {
565-
_ = TangentVector(float: .init(), float2: .init())
567+
_ = TangentVector(float: .init(), float2: .init(), float3: .init())
566568
}
567569
}
568570

test/AutoDiff/Sema/DerivedConformances/struct_differentiable.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ struct SR_12793: Differentiable {
341341
}
342342

343343
// Test property wrappers.
344-
// TF-1190: Test `@noDerivative` warning for property wrapper backing storage properties.
345344

346345
@propertyWrapper
347346
struct ImmutableWrapper<Value> {
@@ -372,10 +371,13 @@ struct WrappedProperties: Differentiable {
372371

373372
@Wrapper var float: Generic<Float>
374373
@ClassWrapper var float2: Generic<Float>
374+
// SR-13071: Test `@differentiable` wrapped property.
375+
@differentiable @Wrapper var float3: Generic<Float>
376+
375377
@noDerivative @ImmutableWrapper var nondiff: Generic<Int>
376378

377379
static func testTangentMemberwiseInitializer() {
378-
_ = TangentVector(float: .init(), float2: .init())
380+
_ = TangentVector(float: .init(), float2: .init(), float3: .init())
379381
}
380382
}
381383

0 commit comments

Comments
 (0)