swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-11588]Warn about derived Hashable implementation if there’s a custom Equatable

Open JGiola opened this issue 6 years ago • 18 comments

This is a first approach to add the desired warning for custom Equatable implementation during Hashable synthesis.

It’s working for struct just fine but it crashes when running test/Sema/implementation-only-import-in-decls.swift for some reason it don’t like enum types.

Other improvements before merging are increase the test coverage in test/Sema/diag_custom_equatable_syntheszied_hashable.swift and replicate the same warning in the opposite direction for custom Hashable implementation during Equatable synthesis.

Resolves SR-11588.

JGiola avatar Oct 20 '19 21:10 JGiola

Please run clang-format as well to ensure your changes fit within the 80-column limit!

It’s working for struct just fine but it crashes when running test/Sema/implementation-only-import-in-decls.swift for some reason it don’t like enum types.

Can you share the stack trace?

theblixguy avatar Oct 20 '19 23:10 theblixguy

cc @lorentey

stephentyrone avatar Oct 21 '19 17:10 stephentyrone

Please run clang-format as well to ensure your changes fit within the 80-column limit!

I’ve run it on the file but it has changed a lot of formatting in the file apart the block I’ve added. It’s okay to add all the changes or is better to revert all the other changes and keep only my formatted block?

JGiola avatar Oct 21 '19 19:10 JGiola

Can you share the stack trace?

Here it is.

1.      Swift version 5.1.1-dev (LLVM f4c2b4eca6, Swift 32c1b05168)
2.      While type-checking protocol conformance to 'Hashable' (in module 'Swift') for type 'TestRawType' (declared at [/swift-source/swift/test/Sema/implementation-only-import-in-decls.swift:65:8 - line:68:1] RangeText="enum TestRawType: IntLike { // expected-error {{cannot use struct 'IntLike' here; 'BADLibrary' has been imported as implementation-only}}
  case x = 1
  // FIXME: expected-error@-1 {{cannot use conformance of 'IntLike' to 'Equatable' here; 'BADLibrary' has been imported as implementation-only}}
")
0  swiftc                   0x000000010d1be0c5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swiftc                   0x000000010d1bd355 llvm::sys::RunSignalHandlers() + 85
2  swiftc                   0x000000010d1be6b8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff57d2bb5d _sigtramp + 29
4  libsystem_platform.dylib 0x00007ffee841d608 _sigtramp + 2423200456
5  libsystem_c.dylib        0x00007fff57be56a6 abort + 127
6  libsystem_c.dylib        0x00007fff57bae20d basename_r + 0
7  swiftc                   0x0000000109fb1b77 swift::RootProtocolConformance::getWitnessDeclRef(swift::ValueDecl*) const + 167
8  swiftc                   0x0000000109fb03dd swift::ProtocolConformance::getWitnessDeclRef(swift::ValueDecl*) const + 93
9  swiftc                   0x0000000109fb0366 swift::ProtocolConformanceRef::getWitnessByName(swift::Type, swift::DeclName) const + 198
10 swiftc                   0x0000000109117245 swift::DerivedConformance::deriveHashable(swift::ValueDecl*) + 1093
11 swiftc                   0x00000001093205bb swift::TypeChecker::deriveProtocolRequirement(swift::DeclContext*, swift::NominalTypeDecl*, swift::ValueDecl*) + 315
12 swiftc                   0x0000000109320323 swift::ConformanceChecker::resolveWitnessViaDerivation(swift::ValueDecl*) + 275
13 swiftc                   0x0000000109320f11 swift::ConformanceChecker::resolveWitnessTryingAllStrategies(swift::ValueDecl*) + 289
14 swiftc                   0x00000001093221e1 swift::ConformanceChecker::resolveValueWitnesses() + 401
15 swiftc                   0x000000010931a8a9 swift::ConformanceChecker::checkConformance(swift::MissingWitnessDiagnosisKind) + 553
16 swiftc                   0x00000001093185dc swift::MultiConformanceChecker::checkIndividualConformance(swift::NormalProtocolConformance*, bool) + 3292
17 swiftc                   0x0000000109317620 swift::MultiConformanceChecker::checkAllConformances() + 144
18 swiftc                   0x00000001093242fb swift::TypeChecker::checkConformancesInContext(swift::DeclContext*, swift::IterableDeclContext*) + 1035
19 swiftc                   0x0000000109479cc6 typeCheckFunctionsAndExternalDecls(swift::SourceFile&, swift::TypeChecker&) + 470
20 swiftc                   0x000000010947a459 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1017
21 swiftc                   0x0000000107e68735 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 965
22 swiftc                   0x0000000107e66bd0 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 384
23 swiftc                   0x0000000107e66007 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 807
24 swiftc                   0x0000000107e6606a swift::CompilerInstance::performSema() + 26
25 swiftc                   0x00000001078f3509 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 457
26 swiftc                   0x00000001078f2589 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2121
27 swiftc                   0x00000001077dfee4 run_driver(llvm::StringRef, llvm::ArrayRef<char const*>) + 292
28 swiftc                   0x00000001077df1f3 main + 1875
29 libdyld.dylib            0x00007fff57b403d5 start + 1
30 libdyld.dylib            0x0000000000000013 start + 2823552063

JGiola avatar Oct 21 '19 19:10 JGiola

@DougGregor sorry to ping, but I've read in the CODE_OWNERS file that you are associated with the Sema. Do you know how can I catch that the equality conformance is implemented in another module and that I cannot get the witness for it?

I‘ve tried to look everywhere but I’m not seeing anything useful for a check against it :(

JGiola avatar Dec 06 '19 20:12 JGiola

@swift-ci please smoke test

beccadax avatar May 12 '20 23:05 beccadax

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

shahmishal avatar Oct 01 '20 06:10 shahmishal

@beccadax hi, sorry to ping you, I've finally solved the issue and on my mac all the tests are running fine. There is more changes I have to do?

JGiola avatar Jun 04 '21 07:06 JGiola

@swift-ci please test

beccadax avatar Jun 06 '21 07:06 beccadax

Build failed Swift Test Linux Platform Git Sha - 3778c30ec33b56fd6a73050c0ebba5fd803a53a0

swift-ci avatar Jun 06 '21 09:06 swift-ci

Build failed Swift Test OS X Platform Git Sha - 3778c30ec33b56fd6a73050c0ebba5fd803a53a0

swift-ci avatar Jun 06 '21 11:06 swift-ci

I've rebased the repo and run all the tests with utils/run-test --lit ../llvm-project/llvm/utils/lit/lit.py ../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)/test-macosx-$(uname -m) and nothing is breaking this time.

JGiola avatar Aug 24 '21 19:08 JGiola

@swift-ci please test

xwu avatar Aug 25 '21 04:08 xwu

Build failed Swift Test Linux Platform Git Sha - bdc68ea659ec34c482f1c26facfb65fc90c7750e

swift-ci avatar Aug 25 '21 06:08 swift-ci

Build failed Swift Test OS X Platform Git Sha - bdc68ea659ec34c482f1c26facfb65fc90c7750e

swift-ci avatar Aug 25 '21 06:08 swift-ci

@swift-ci please smoke test

WowbaggersLiquidLunch avatar Jan 09 '22 12:01 WowbaggersLiquidLunch

@swift-ci please smoke test

WowbaggersLiquidLunch avatar Jan 10 '22 06:01 WowbaggersLiquidLunch

@swift-ci please test

WowbaggersLiquidLunch avatar Oct 14 '22 01:10 WowbaggersLiquidLunch