swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

"Meet operation was not commutative" compiler crash around existential extension #69740

Closed stephencelis closed 12 months ago

stephencelis commented 12 months ago

Description

I encountered a crash in the compiler.

Meet operation was not commutative:

LHS: [concrete: Reducer<τ_0_0.[Reducer:State], τ_0_0.[Reducer:Action]>]
RHS: [concrete: Reducer<τ_0_0.State, τ_0_0.Action>]
Abstract differences with LHS < RHS:
- τ_0_0.State (#0) -> τ_0_0.[Reducer:State]
Abstract differences with RHS < LHS:
Concrete differences with LHS < RHS:
Concrete differences with RHS < LHS:
Concrete conflicts:

LHS ∧ RHS: [concrete: Reducer<τ_0_0.[Reducer:State], τ_0_0.[Reducer:Action]>]
RHS ∧ LHS: [concrete: Reducer<τ_0_0.[Reducer:State], τ_0_0.Action>]

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
1.  Apple Swift version 5.9.2 (swiftlang-5.9.2.2.51 clang-1500.1.0.2.2)
2.  Compiling with the current language version
3.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/stephen/Developer/pointfreeco/swift-composable-architecture/Sources/ComposableArchitecture/Reducer.swift")
4.  While type-checking extension of Reducer (at /Users/stephen/Developer/pointfreeco/swift-composable-architecture/Sources/ComposableArchitecture/Reducer.swift:279:1)
5.  While evaluating request GenericSignatureRequest(extension of Reducer)
6.  While evaluating request InferredGenericSignatureRequest(<Self where Self : Reducer>, (null), extension of Reducer, {}, {}, 1)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000107b2cc40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107b2b9dc llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000103876668 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x0000000181fa1a24 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000181f72cc0 pthread_kill + 288
5  libsystem_c.dylib        0x0000000181e82a50 abort + 180
6  swift-frontend           0x0000000105a18b58 llvm::object::defaultWarningHandler(llvm::Twine const&) + 0
7  swift-frontend           0x00000001059c41d0 swift::rewriting::PropertyMap::unifyConcreteTypes(swift::rewriting::Term, llvm::Optional<swift::rewriting::Symbol>&, llvm::SmallVectorImpl<std::__1::pair<swift::rewriting::Symbol, unsigned int>>&, swift::rewriting::Symbol, unsigned int) + 760
8  swift-frontend           0x00000001059bf240 swift::rewriting::PropertyMap::buildPropertyMap() + 1632
9  swift-frontend           0x00000001059dd0d4 swift::rewriting::RequirementMachine::computeCompletion(swift::rewriting::RewriteSystem::ValidityPolicy) + 248
10 swift-frontend           0x00000001059dee64 swift::rewriting::RequirementMachine::initWithWrittenRequirements(llvm::ArrayRef<swift::GenericTypeParamType*>, llvm::ArrayRef<swift::StructuralRequirement>) + 812
11 swift-frontend           0x00000001059e6940 swift::InferredGenericSignatureRequest::evaluate(swift::Evaluator&, swift::GenericSignatureImpl const*, swift::GenericParamList*, swift::WhereClauseOwner, llvm::SmallVector<swift::Requirement, 2u>, llvm::SmallVector<swift::TypeLoc, 2u>, bool) const + 2344
12 swift-frontend           0x0000000107771e8c swift::SimpleRequest<swift::InferredGenericSignatureRequest, llvm::PointerIntPair<swift::GenericSignature, 3u, swift::OptionSet<swift::GenericSignatureErrorFlags, unsigned int>, llvm::PointerLikeTypeTraits<swift::GenericSignature>, llvm::PointerIntPairInfo<swift::GenericSignature, 3u, llvm::PointerLikeTypeTraits<swift::GenericSignature>>> (swift::GenericSignatureImpl const*, swift::GenericParamList*, swift::WhereClauseOwner, llvm::SmallVector<swift::Requirement, 2u>, llvm::SmallVector<swift::TypeLoc, 2u>, bool), (swift::RequestFlags)2>::evaluateRequest(swift::InferredGenericSignatureRequest const&, swift::Evaluator&) + 312
13 swift-frontend           0x0000000104956730 llvm::Expected<swift::InferredGenericSignatureRequest::OutputType> swift::Evaluator::getResultUncached<swift::InferredGenericSignatureRequest>(swift::InferredGenericSignatureRequest const&) + 700
14 swift-frontend           0x0000000107009434 llvm::Expected<swift::InferredGenericSignatureRequest::OutputType> swift::Evaluator::getResultCached<swift::InferredGenericSignatureRequest, (void*)0>(swift::InferredGenericSignatureRequest const&) + 600
15 swift-frontend           0x00000001074e93d0 swift::GenericSignatureRequest::evaluate(swift::Evaluator&, swift::GenericContext*) const + 4088
16 swift-frontend           0x00000001053872bc swift::GenericContext::getGenericSignature() const + 1620
17 swift-frontend           0x0000000107447dd8 (anonymous namespace)::DeclChecker::visit(swift::Decl*) (.llvm.5139545417519374486) + 12852
18 swift-frontend           0x0000000104b6d240 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 220
19 swift-frontend           0x0000000104dba428 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 432
20 swift-frontend           0x000000010796de14 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 664
21 swift-frontend           0x0000000107965420 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 228
22 swift-frontend           0x00000001053f04bc swift::CompilerInstance::performSema() + 160
23 swift-frontend           0x00000001073d572c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 464
24 swift-frontend           0x00000001073d9e6c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
25 swift-frontend           0x0000000107438864 swift::mainEntry(int, char const**) + 4408
26 dyld                     0x0000000181bf9058 start + 2224

Steps to reproduce

  1. Clone https://github.com/pointfreeco/swift-composable-architecture
  2. Add the following to the ComposableArchitecture target:
    extension Reducer where Body == any Reducer<State, Action> {
      @inlinable
      public func reduce(
        into state: inout Body.State, action: Body.Action
      ) -> Effect<Body.Action> {
        self.body.reduce(into: &state, action: action)
      }
    }
  3. Try to compile.

Expected behavior

It should compile, at the very least with an explicit open (below), or show a better error.

extension Reducer where Body == any Reducer<State, Action> {
  @inlinable
  public func reduce(
    into state: inout Body.State, action: Body.Action
  ) -> Effect<Body.Action> {
    func reduce(body: some Reducer<State, Action>) -> Effect<Action> {
      body.reduce(into: &state, action: action)
    }
    return reduce(body: self.body)
  }
}

Environment

stephencelis commented 12 months ago

/cc @hborla @slavapestov

slavapestov commented 12 months ago

Duplicate of #63410.