Skip to content
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

[SR-5766] Remove the warning Redundant conformance constraint ... #48336

Closed
swift-ci opened this issue Aug 24, 2017 · 8 comments
Closed

[SR-5766] Remove the warning Redundant conformance constraint ... #48336

swift-ci opened this issue Aug 24, 2017 · 8 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5766
Radar None
Original Reporter RampantLions (JIRA User)
Type Improvement
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: a677d712b6d8443b00064027da39c7e9

duplicates:

  • SR-5753 Remove "redundant same-type constraints" warnings

relates to:

  • SR-5753 Remove "redundant same-type constraints" warnings

Issue Description:

This may only be an issue with protocols with extensions.

Say we have two protocols and we call them protocol A and protocol B.

Protocol B inherits protocol A.

Now we have a class we will call C which implements protocol A and protocol B.

Class C has concrete requirements from both A and B.

During compilation, a warning of "Redundant conformance constraint 'Self': 'A'"

The warning doesn't necessarily make sense.

Protocol B may depend on protocol A, and class C limit the class definition to protocol B and implicitly get the benefits of protocol A.

If protocol B no longer requires protocol A (and removes A) all implementing classes will be affected. This is problematic if classes have a direct dependency on protocol A.

If a class explicitly need protocol A and B, (even if B implements A) the class should indicate that it implements A and B and not defer to using B propagating A in order to avoid warnings.

If class C does not directly require protocol A (but implements A), then only supplying protocol B in the class definition and transitively implementing protocol A makes sense.

@swift-ci
Copy link
Collaborator Author

Comment by Josh Wiechman (JIRA)

I have not been able to verify that this issue may also result in a compiling resulting in an Abort trap: 6, but here is the output on an example project called SpringboardUIComponents.

0 swift 0x000000010a8ba42a PrintStackTraceSignalHandler(void*) + 42

1 swift 0x000000010a8b9866 SignalHandler(int) + 662

2 libsystem_platform.dylib 0x00007fffb5b42b3a _sigtramp + 26

3 libsystem_platform.dylib 0x00000001156e1551 _sigtramp + 1606019633

4 libsystem_c.dylib 0x00007fffb59c7420 abort + 129

5 swift 0x0000000107fcf821 swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 5985

6 swift 0x0000000107fcf408 swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 4936

7 swift 0x0000000107fcf408 swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 4936

8 swift 0x0000000107fd244c swift::ModuleFile::loadAllConformances(swift::Decl const*, unsigned long long, llvm::SmallVectorImplswift::ProtocolConformance\*&) + 300

9 swift 0x000000010840f35c swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage, swift::LazyResolver*) + 1068

10 swift 0x000000010840f027 swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage, swift::LazyResolver*) + 247

11 swift 0x0000000108413201 swift::ConformanceLookupTable::lookupConformance(swift::ModuleDecl*, swift::NominalTypeDecl*, swift::ProtocolDecl*, swift::LazyResolver*, llvm::SmallVectorImplswift::ProtocolConformance\*&) + 49

12 swift 0x0000000107fce68e swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 1486

13 swift 0x0000000107fcf408 swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 4936

14 swift 0x0000000107fd244c swift::ModuleFile::loadAllConformances(swift::Decl const*, unsigned long long, llvm::SmallVectorImplswift::ProtocolConformance\*&) + 300

15 swift 0x000000010840f35c swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage, swift::LazyResolver*) + 1068

16 swift 0x000000010840f027 swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage, swift::LazyResolver*) + 247

17 swift 0x0000000108413201 swift::ConformanceLookupTable::lookupConformance(swift::ModuleDecl*, swift::NominalTypeDecl*, swift::ProtocolDecl*, swift::LazyResolver*, llvm::SmallVectorImplswift::ProtocolConformance\*&) + 49

18 swift 0x0000000107fce68e swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 1486

19 swift 0x0000000107fcf408 swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 4936

20 swift 0x0000000107fcf408 swift::ModuleFile::readConformance(llvm::BitstreamCursor&, swift::GenericEnvironment*) + 4936

21 swift 0x0000000107fd244c swift::ModuleFile::loadAllConformances(swift::Decl const*, unsigned long long, llvm::SmallVectorImplswift::ProtocolConformance\*&) + 300

22 swift 0x000000010840f35c swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage, swift::LazyResolver*) + 1068

23 swift 0x000000010840f027 swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage, swift::LazyResolver*) + 247

24 swift 0x000000010840f09c swift::ConformanceLookupTable::updateLookupTable(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceStage, swift::LazyResolver*) + 364

25 swift 0x0000000108413bd7 swift::ConformanceLookupTable::getAllProtocols(swift::NominalTypeDecl*, swift::LazyResolver*, llvm::SmallVectorImplswift::ProtocolDecl\*&) + 39

26 swift 0x0000000107b9ec2d (anonymous namespace)::NominalTypeWalker::walkToDeclPre(swift::Decl*) + 205

27 swift 0x00000001083f9f98 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 280

28 swift 0x0000000107c82cdf swift::SILPassManager::SILPassManager(swift::SILModule*, llvm::StringRef) + 1807

29 swift 0x0000000107c8931f swift::runSILDiagnosticPasses(swift::SILModule&) + 175

30 swift 0x000000010722eb14 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13844

31 swift 0x0000000107229c94 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716

32 swift 0x00000001071debb8 main + 12248

33 libdyld.dylib 0x00007fffb5933235 start + 1

Stack dump:

  1. Program arguments: /Users/wiechman/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-module -filelist /var/folders/x7/g4pnz2sx7rj94j8h1_ft0v75mxwktq/T/inputs-c8ee37 -parse-as-library -target x86_64-apple-ios9.0 -enable-objc-interop -sdk /Users/wiechman/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.0.sdk -I /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Products/Debug-iphonesimulator -F /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Products/Debug-iphonesimulator -F /Users/wiechman/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -F /Users/wiechman/Downloads/Xcode-beta.app/Contents/Developer/Library/Frameworks -enable-testing -g -import-underlying-module -module-cache-path /Users/wiechman/Library/Developer/Xcode/DerivedData/ModuleCache -profile-generate -profile-coverage-mapping -swift-version 4 -enforce-exclusivity=checked -D DEBUG -D TRACE_RESOURCES -D DEBUG -serialize-debugging-options -Xcc -I/Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/SpringboardUIComponents-generated-files.hmap -Xcc -I/Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/SpringboardUIComponents-own-target-headers.hmap -Xcc -I/Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/SpringboardUIComponents-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/SpringboardUIComponents-project-headers.hmap -Xcc -I/Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/DerivedSources/x86_64 -Xcc -I/Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -ivfsoverlay -Xcc /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/wiechman/Sandboxes/Verify/Testing/SpringboardUIComponents -emit-module-doc-path /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/Objects-normal/x86_64/SpringboardUIComponents.swiftdoc -module-name SpringboardUIComponents -emit-objc-header-path /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/Objects-normal/x86_64/Users/wiechman/Sandboxes/Verify/Testing/SpringboardUIComponents/Sources/iOS/SpringboardUIComponents-Swift.h -o /Users/wiechman/Library/Developer/Xcode/DerivedData/Lassen-bwvufqubkilqfpgimhylnfczubmu/Build/Intermediates.noindex/SpringboardUIComponents.build/Debug-iphonesimulator/SpringboardUIComponents-iOS.build/Objects-normal/x86_64/SpringboardUIComponents.swiftmodule

  2. While loading conformances for 'SpringboardInstances' in module 'SpringboardUIComponents'

  3. While reading conformance for type 'SpringboardInstances'

  4. While ... to 'HasApplicationProperty' in module 'SpringboardUIComponents'

  5. While reading conformance for type 'SpringboardInstances'

  6. While ... to 'HasBootstrap' in module 'SpringboardUIComponents'

  7. While cross-referencing conformance for 'SpringboardBootstrap' in module 'SpringboardUIComponents'

  8. While ... to 'IsBootstrap' in module 'SpringboardUIComponents'

  9. While loading conformances for 'SpringboardBootstrap' in module 'SpringboardUIComponents'

  10. While reading conformance for type 'SpringboardBootstrap'

  11. While ... to 'HasApplicationType' in module 'SpringboardUIComponents'

  12. While cross-referencing conformance for 'SpringboardApplication' in module 'SpringboardUIComponents'

  13. While ... to 'IsApplicationFlag' in module 'SpringboardUIComponents'

  14. While loading conformances for 'SpringboardApplication' in module 'SpringboardUIComponents'

  15. While reading conformance for type 'SpringboardApplication'

  16. While ... to 'HasConfigurationsProperty' in module 'SpringboardUIComponents'

  17. While reading conformance for type 'SpringboardApplication'

  18. While ... to 'HasBootstrap' in module 'SpringboardUIComponents'

  19. While cross-referencing conformance for 'SpringboardBootstrap' in module 'SpringboardUIComponents'

  20. While ... to 'IsBootstrap' in module 'SpringboardUIComponents'

  21. If you're seeing a crash here, check that your SDK and dependencies are at least as new as the versions used to build 'SpringboardUIComponents'

@belkadan
Copy link
Contributor

There's no source-compatible way for protocol B to "no longer require protocol A", because anyone could have written code assuming that B implies A. If you don't want this assumption, you should make A and B separate protocols, but provide default implementations of B's operations in terms of A using a constrained extension of B.

@swift-ci
Copy link
Collaborator Author

Comment by Josh Wiechman (JIRA)

You make the assumption people can control how protocols are implemented vs. used from a third party. 'There's no source-compatible way for protocol B to "no longer require protocol A"' Exactly, my point. If I am using third party protocols, and I know my class needs A & B, I should be able to leverage both without a warning, even if B already inherits A. If the provider of the protocol makes changes, the impact to local code would not be affected. Is this approach ideal, no, but is it realistic, yes.

The current implementation couples the protocols (which isn't the direct issue). The issue is providing a warning because a class implements two protocols when one of the protocols implements the other.

A warning should not occur because a protocol constraint is applied directly and indirectly to the same class.

@swift-ci
Copy link
Collaborator Author

Comment by Josh Wiechman (JIRA)

Only considering code that is directly owned by the programmer is not a realist constraint in the real world.

A warning occurring with protocols are double applied stressing a redundant of conformance leads to noise for legitimate warnings.

@swift-ci
Copy link
Collaborator Author

Comment by Fae Charlton (JIRA)

I'm getting a ton of these errors in my project right now, so here's how it's turning up in one practical scenario.

I'm working with coordinate geometry:

class Coords2d<R: Ring> {...}

where "Ring" is a protocol requiring various arithmetic operations.

At the same time, I have a bunch of functions that act on Coords2d in various ways, for example:

func PathBoundaries<R: Ring>(center: Coords2d<R>) -> [Coords2d<R>] {...}

Now, PathBoundaries explicitly requires R to be a Ring. But PathBoundaries doesn't care whether Coords2d also requires its parameter to be a Ring – some day it may not, maybe it will change to some other more general protocol. But if it does, PathBoundaries will still require its parameter to conform to Ring. But right now I'm getting a bunch of warnings for specifying this intentional, not-really-redundant constraint.

Besides which, even if the constraint can be inferred one way or another, I want my functions that require Rings to explicitly say so in their declarations – as far as I'm concerned that's part of their documentation and linking it to an indirect inference rule in a semi-related class will lead to confusing compiler errors at best and breakages at worst.

@DougGregor
Copy link
Member

Josh Wiechman, do you happen to have a project that you can share that demonstrates the compiler crash? Independent of the usefulness of the warning, we'd like to reproduce that crash so we can fix it.

The warning itself is discussed in https://bugs.swift.org/browse/SR-5753.

@swift-ci
Copy link
Collaborator Author

Comment by Josh Wiechman (JIRA)

Hi Doug, I discovered the main error from my first comment was an issue when using Xcode 9 where the command line utilities was set to 8.3.3. Once I updated the Xcode CLT to 9, the issue magically resolved.

As for the discussion in SR-5753, I can move my comments to the other ticket, but I have one question.

Is there a value statement why the warning exists?

I understand what the warning is saying, but not the intended value.

I do see the git pull on GH. I like the idea of opting in to seeing these warnings.

I think understand the value proposition in the context of a warning would help facilitate the discussion.

@DougGregor
Copy link
Member

Let's dupe to SR-5753 and have discussion there.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

3 participants