# Wrong "Redundant conformance constraint" warning

**URL:** <https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207>\
**Category:** Compiler\
**Created:** [March 24, 2022, 9:25pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207 "2022-03-24T21:25:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 24, 2022, 9:25pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/1 "2022-03-24T21:25:56Z")

</div>

## The problem

I'm working on [GitHub - RemiBardon/swift-geo: Generic geographical library for Swift](https://github.com/RemiBardon/swift-geo). I'm rewriting things to avoid code duplication, but I just stumbled upon a wrong Swift warning. You can see it at [swift-geo/Sources/GeoModels/Protocols/MultiPoint.swift at redundant-conformance-constraint-bug · RemiBardon/swift-geo · GitHub](https://github.com/RemiBardon/swift-geo/blob/redundant-conformance-constraint-bug/Sources/GeoModels/Protocols/MultiPoint.swift#L15).

Basically, I have:

```swift
associatedtype CoordinateSystem: GeoModels.CoordinateSystem
	where Self.CoordinateSystem.Point == Self.Point
associatedtype Point: GeoModels.Point // ⚠️ Redundant conformance constraint 'Self.Point' : 'Point'

```

When I comment out the constraint, my code does not compile anymore

```swift
associatedtype CoordinateSystem: GeoModels.CoordinateSystem
	where Self.CoordinateSystem.Point == Self.Point
associatedtype Point//: GeoModels.Point // ⚠️ Redundant conformance constraint 'Self.Point' : 'Point'

```

```swift
if points.last != points.first {
// 💥 Operator function '!=' requires that 
// 'NonEmpty<NonEmpty<Array<Self.CoordinateSystem.Point>>>.Element'
// (aka 'Self.CoordinateSystem.Point') conform to 'Equatable'

```

The type tree is quite complex, and I think the compiler has a hard time remembering all the constraints. I had a similar problem ([[SR-16024] Abort trap: 6 · Issue #58285 · swiftlang/swift · GitHub](https://bugs.swift.org/browse/SR-16024)) a few days ago, while working on [Nested `NonEmpty` by RemiBardon · Pull Request #46 · pointfreeco/swift-nonempty · GitHub](https://github.com/pointfreeco/swift-nonempty/pull/46), so I wouldn't be surprised.

Is there a compiler flag or an annotation I could use to silence those warnings? I'd prefer writing too many redundant constraints and help the compiler, rather than having an exponential compile time… and errors 🙄

If there is no simple answer, I'll take some time to write down my type tree and add more code samples. I just don't want to spend a lot of time on it if there is one 😌 I'm not even sure if I can create a minimal reproductible example, as the problem comes from a too complex type tree 😕

## My environment

- Xcode 13.3 (13E113)
- Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
- Target: x86\_64-apple-macosx12.0
- macOS 12.3 (21E230)

---

<div class="post-metadata">

**Author:** ![Jumhyn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jumhyn/32/3891_2.png) [@Jumhyn](https://forums.swift.org/u/Jumhyn)\
**Post date:** [March 24, 2022, 11:23pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/2 "2022-03-24T23:23:48Z")

</div>

This seems like it could an issue with the new generics implementation in Swift 5.6. You should be able to use the workaround [here](https://forums.swift.org/t/new-segmentation-fault-11-in-swift-5-6/56141/2) to see if disabling the new implementation fixes your problem.

---

<div class="post-metadata">

**Author:** ![hborla](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hborla/32/27563_2.png) [@hborla](https://forums.swift.org/u/hborla)\
**Post date:** [March 24, 2022, 11:35pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/3 "2022-03-24T23:35:20Z")

</div>

Redundancy warnings are emitted after generic signature minimization, and Swift 5.6 still uses the old generics implementation for signature minimization and requirement diagnostics. I actually just implemented redundancy diagnostics for the new implementation [on main](https://github.com/apple/swift/pull/41664), so you could try a development toolchain from [Swift.org - Download Swift](https://www.swift.org/download/#snapshots) and build with the flags `-Xfrontend -requirement-machine-protocol-signatures=on -Xfrontend -requirement-machine-inferred-signatures=on` to see if it's fixed with the new implementation. If not, I'll take a look!

---

<div class="post-metadata">

**Author:** ![hborla](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hborla/32/27563_2.png) [@hborla](https://forums.swift.org/u/hborla)\
**Post date:** [March 25, 2022, 1:05am UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/4 "2022-03-25T01:05:27Z")

</div>

> [@RemiBardon](#):
>
> I'd prefer writing too many redundant constraints and help the compiler, rather than having an exponential compile time…

Note that redundant requirements don't help the compiler (though I think they can help the programmer if the requirement isn't obvious!) - the compiler will always canonicalize generic signatures in order to type check calls to a generic function, etc, so this computation would be done even if the compiler did not report warnings for redundant requirements.

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [March 25, 2022, 1:57am UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/5 "2022-03-25T01:57:45Z")

</div>

As far as I can tell the requirement really is redundant, because it can be derived from `Self.Point == Self.BoundingBox.Point`. With `-Xfrontend -requirement-machine-protocol-signatures=on` the program builds both with and without the redundant requirement, so this bug will be fixed once this flag becomes the default.

This appears to be a bug in the GenericSignatureBuilder, and briefly looking at the code I see that the Point, BoundingBox, Line, CoordinateSystem, MultiPoint protocols are mutually inter-dependent. This is one of the scenarios the GSB did not handle very well.

I confirmed that in 5.6, `-Xfrontend -requirement-machine=off` does not fix the issue. As Holly already explained, the term rewriting engine is 'downstream' of the GenericSignatureBuilder in 5.6 so we would not expect behavior to change either way here.

The reduced test case is pretty cute:

```swift
protocol P1 {
  associatedtype A: P2 where Self.A.B == Self.B
  associatedtype B
}

protocol P2 {
  associatedtype B
  associatedtype C: P3 where Self.C.B == Self.B
}

protocol P3 {
  associatedtype B: P4
}

protocol P4 {
  associatedtype A: P2 where Self.A.B == Self
}

func takesP4<T : P4>(_: T.Type) {}

func testP1<T : P1>(_: T) {
  takesP4(T.B.self)
}

```

The call to `takesP4()` in 'testP1()` should succeed, but it fails in 5.6. It succeeds on main with the new minimization algorithm. I'll add it to our test suite.

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [March 25, 2022, 1:59am UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/6 "2022-03-25T01:59:42Z")

</div>

> [@RemiBardon](#):
>
> I had a similar problem ([[SR-16024] Abort trap: 6 - Swift ](https://bugs.swift.org/browse/SR-16024)) a few days ago, while working on [Nested `NonEmpty` by RemiBardon · Pull Request #46 · pointfreeco/swift-nonempty · GitHub](https://github.com/pointfreeco/swift-nonempty/pull/46), so I wouldn't be surprised.

I commented on that bug report. It is a different issue that can be fixed with a flag to increase the maximum term length. I put up a PR for the main branch to avoid having to set the flag in cases such as this one: [RequirementMachine: Tweak rule limit non-termination heuristic by slavapestov · Pull Request #42017 · apple/swift · GitHub](https://github.com/apple/swift/pull/42017)

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 25, 2022, 6:28pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/7 "2022-03-25T18:28:11Z")

</div>

Thank you all for your very quick replies ❤ I'll have a try and tell you if everything works 🙂

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 25, 2022, 8:29pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/8 "2022-03-25T20:29:04Z")

</div>

> [@hborla](#):
>
> you could try a development toolchain from [Swift.org - Download Swift](https://www.swift.org/download/#snapshots) and build with the flags `-Xfrontend -requirement-machine-protocol-signatures=on -Xfrontend -requirement-machine-inferred-signatures=on` to see if it's fixed with the new implementation.

Thank you very much for your work, it fixes my problem 😀  
( ~~Just a note: you pasted the arguments twice 😉~~ Edit: I just hadn't seen the difference (`protocol` / `inferred`) 🙈)

I am using a Swift Package, so for those searching a "copy-paste" solution, here is what I had to change:

```diff
.target(
	name: "GeoModels",
	dependencies: [/* … */],
+	swiftSettings: [
+ .unsafeFlags(["-Xfrontend", "-requirement-machine-inferred-signatures=on"]),
+	]
),

```

Once again, thank you everyone, I wasn't hoping for a solution in just a few hours 😍

---

<div class="post-metadata">

**Author:** ![hborla](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hborla/32/27563_2.png) [@hborla](https://forums.swift.org/u/hborla)\
**Post date:** [March 25, 2022, 8:31pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/9 "2022-03-25T20:31:11Z")

</div>

> [@RemiBardon](#):
>
> (Just a note: you pasted the arguments twice 😉)

They are two different frontend compiler flags 🙂 one is for generic function/type signatures and the other is for protocol requirement signatures.

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 25, 2022, 8:32pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/10 "2022-03-25T20:32:12Z")

</div>

My bad, I hadn't seen the subtle difference 🙈

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 25, 2022, 8:33pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/11 "2022-03-25T20:33:33Z")

</div>

> [@hborla](#):
>
> -Xfrontend -requirement-machine-protocol-signatures=on -Xfrontend -requirement-machine-inferred-signatures=on

Why do I need `-Xfrontend` twice then?

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 25, 2022, 8:48pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/12 "2022-03-25T20:48:22Z")

</div>

With `-Xfrontend -requirement-machine-inferred-signatures=on`, it compiles.  
With `-Xfrontend -requirement-machine-protocol-signatures=on`, I get `Abort trap: 6`.  
With the four of them, I get `Abort trap: 6` too.

Is it expected?

> [@hborla](#):
>
> If not, I'll take a look!

I'm afraid you'll have to 🙊

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 26, 2022, 3:30pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/13 "2022-03-26T15:30:02Z")

</div>

I managed to avoid needing `-Xfrontend -requirement-machine-inferred-signatures=on`, probably because I was able to simplify type checking.

However, my build time increased a lot (compared to Swift 5.5), taking around 140s for incremental build and 260s (for clean build) 😳

It stays stuck at one step for most of the time, but I don't know how to identify it. What could I do to debug it?

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 26, 2022, 4:15pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/14 "2022-03-26T16:15:33Z")

</div>

I just ran [GitHub - MobileNativeFoundation/XCLogParser: Tool to parse Xcode and xcodebuild logs stored in the xcactivitylog format](https://github.com/MobileNativeFoundation/XCLogParser) to see where were the issues.

Here is an outline:

- 125s to build target `NonEmpty`
- 153s to build target `GeoModels`
- 0.75s to build target `Turf`

I think [my pull request to `pointfreeco/swift-nonempty`](https://github.com/pointfreeco/swift-nonempty/pull/46) introduced too complex type checking. I will investigate 🧐

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 26, 2022, 4:22pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/15 "2022-03-26T16:22:42Z")

</div>

Well… I see the problem now 😳

| Duration (ms) | File | Function | Line | Column |
| --- | --- | --- | --- | --- |
| 120252.53 | file:///redacted/swift-nonempty/Sources/NonEmpty/NonEmpty.swift | initializer init(rawValue:) | 27 | 10 |
| 119193.35 | file:///redacted/swift-nonempty/Sources/NonEmpty/NonEmpty+SetAlgebra.swift | initializer init(_:_:) | 5 | 10 |
| 118939.86 | file:///redacted/swift-nonempty/Sources/NonEmpty/NonEmpty+Dictionary.swift | initializer init(_:_:) | 21 | 10 |

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [March 26, 2022, 5:06pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/16 "2022-03-26T17:06:51Z")

</div>

I believe @Slava_Pestov has already diagnosed and dealt with the issue:

> <https://twitter.com/slava_pestov/status/1507537318315450370?s=21&t=T5_AjWYVTCBhAJAbbrpHQg>

---

<div class="post-metadata">

**Author:** ![ben-cohen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ben-cohen/32/296_2.png) [@ben-cohen](https://forums.swift.org/u/ben-cohen)\
**Post date:** [March 26, 2022, 5:12pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/17 "2022-03-26T17:12:00Z")

</div>

> [@RemiBardon](#):
>
> Why do I need `-Xfrontend` twice then?

`-Xfrontend` is an instruction to the swift driver that says "pass the next command I give you on to the front end". You're passing two different flags to the front end so you need to us that command for each one.

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 26, 2022, 5:16pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/18 "2022-03-26T17:16:01Z")

</div>

Thank you, I found out after some research on this forum 🙂 I should have searched first 🙄

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [March 26, 2022, 7:31pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/19 "2022-03-26T19:31:59Z")

</div>

> [@RemiBardon](#):
>
> Well… I see the problem now 😳

Try `-Xfrontend -enable-requirement-machine-loop-normalization`. It addressed the slow build times for me. This flag will become the default shortly.

> [@RemiBardon](#):
>
> With `-Xfrontend -requirement-machine-inferred-signatures=on` , it compiles.  
> With `-Xfrontend -requirement-machine-protocol-signatures=on` , I get `Abort trap: 6` .  
> With the four of them, I get `Abort trap: 6` too.

Can you share the build log? I didn't see this issue when I was building your project.

EDIT: Are you using the developer toolchain from [swift.org](http://swift.org), or Swift 5.6 that shipped with Xcode? The latter had these flags because I was just starting to implement this functionality when the branch was cut, but it won't actually work. You need the latest toolchain.

---

<div class="post-metadata">

**Author:** ![RemiBardon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/remibardon/32/29422_2.png) [@RemiBardon](https://forums.swift.org/u/RemiBardon)\
**Post date:** [March 26, 2022, 7:40pm UTC](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207/20 "2022-03-26T19:40:06Z")

</div>

I downloaded the toolchain yesterday, as @hborla asked me to

> [@hborla](#):
>
> you could try a development toolchain from [Swift.org - Download Swift](https://www.swift.org/download/#snapshots)

[Next page](https://forums.swift.org/t/wrong-redundant-conformance-constraint-warning/56207.md?page=2)
