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

Regression: "Cannot build interface type for term" crash during compilation #61192

Closed
stephencelis opened this issue Sep 19, 2022 · 6 comments · Fixed by #61199
Closed

Regression: "Cannot build interface type for term" crash during compilation #61192

stephencelis opened this issue Sep 19, 2022 · 6 comments · Fixed by #61199
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types

Comments

@stephencelis
Copy link
Contributor

Describe the bug

A project that built fine in Xcode 14.0 crashes during compilation in Xcode 14.1.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Clone the repo and check out the affected tag:

    git clone https://github.com/pointfreeco/swift-url-routing
    cd swift-url-routing
    git checkout 0.3.0
  2. Open in Xcode 14.1.

  3. Build the URLRouting target.

Expected behavior

It builds.

Actual behavior

Cannot build interface type for term τ_0_0.[Parser:Input]
Prefix term does not not have a nested type named Input: τ_0_0
Property map entry: τ_0_0 => { concrete_type: [concrete: Parsers.MapConversion<Parsers.ReplaceError<Rest<Data>>, τ_1_0>] }

Property map: {
  [Conversion] => { conforms_to: [Conversion] }
  τ_0_0 => { concrete_type: [concrete: Parsers.MapConversion<Parsers.ReplaceError<Rest<Data>>, τ_1_0>] }
  τ_1_0 => { conforms_to: [Conversion] }
  τ_0_0.[Parser:Input] => { concrete_type: [concrete: Data] }
  τ_1_0.[Conversion:Input] => { concrete_type: [concrete: Data] }
}
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode-14.1.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types swift-url-routing/Sources/URLRouting/Body.swift swift-url-routing/Sources/URLRouting/Builders/Variadics.swift swift-url-routing/Sources/URLRouting/Client/Client.swift swift-url-routing/Sources/URLRouting/Cookies.swift swift-url-routing/Sources/URLRouting/Exports.swift swift-url-routing/Sources/URLRouting/Field.swift swift-url-routing/Sources/URLRouting/FormData.swift swift-url-routing/Sources/URLRouting/Headers.swift swift-url-routing/Sources/URLRouting/Internal/AnyEquatable.swift swift-url-routing/Sources/URLRouting/Internal/Breakpoint.swift swift-url-routing/Sources/URLRouting/Internal/Deprecations.swift swift-url-routing/Sources/URLRouting/Method.swift swift-url-routing/Sources/URLRouting/Parsing/Parse.swift swift-url-routing/Sources/URLRouting/Parsing/ParserPrinter.swift swift-url-routing/Sources/URLRouting/Path.swift swift-url-routing/Sources/URLRouting/PathBuilder.swift swift-url-routing/Sources/URLRouting/Printing.swift swift-url-routing/Sources/URLRouting/Query.swift swift-url-routing/Sources/URLRouting/Route.swift swift-url-routing/Sources/URLRouting/RoutingError.swift swift-url-routing/Sources/URLRouting/Scheme.swift swift-url-routing/Sources/URLRouting/URLRequestData+Foundation.swift swift-url-routing/Sources/URLRouting/URLRequestData.swift -target arm64-apple-macos10.15 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-14.1.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -I ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Products/Debug -I /Applications/Xcode-14.1.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Products/Debug/PackageFrameworks -F ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Products/Debug/PackageFrameworks -F ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Products/Debug/PackageFrameworks -F ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Products/Debug -F /Applications/Xcode-14.1.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path ~/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -empty-abi-descriptor -Xcc -working-directory -Xcc swift-url-routing -resource-dir /Applications/Xcode-14.1.0-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/swift-overrides.hmap -Xcc -I~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Products/Debug/include -Xcc -I~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/DerivedSources-normal/arm64 -Xcc -I~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/DerivedSources/arm64 -Xcc -I~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name URLRouting -disable-clang-spi -target-sdk-version 13.0 -emit-module-doc-path ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/Objects-normal/arm64/URLRouting.swiftdoc -emit-module-source-info-path ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/Objects-normal/arm64/URLRouting.swiftsourceinfo -emit-objc-header-path ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/Objects-normal/arm64/URLRouting-Swift.h -serialize-diagnostics-path ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/Objects-normal/arm64/URLRouting-master-emit-module.dia -emit-dependencies-path ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/Objects-normal/arm64/URLRouting-master-emit-module.d -o ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/Objects-normal/arm64/URLRouting.swiftmodule -emit-abi-descriptor-path ~/Library/Developer/Xcode/DerivedData/swift-url-routing-dvewwdaiiprpffexcbfpavtjtqap/Build/Intermediates.noindex/swift-url-routing.build/Debug/URLRouting.build/Objects-normal/arm64/URLRouting.abi.json
1.	Apple Swift version 5.7.1 (swiftlang-5.7.1.131.4 clang-1400.0.29.51)
2.	Compiling with the current language version
3.	While evaluating request TypeCheckSourceFileRequest(source_file "swift-url-routing/Sources/URLRouting/Body.swift")
4.	While type-checking 'Body' (at swift-url-routing/Sources/URLRouting/Body.swift:4:8)
5.	While type-checking 'init(_:)' (at swift-url-routing/Sources/URLRouting/Body.swift:28:10)
6.	While evaluating request InterfaceTypeRequest(URLRouting.(file).Body.init(_:)@swift-url-routing/Sources/URLRouting/Body.swift:28:10)
7.	While evaluating request GenericSignatureRequest(URLRouting.(file).Body.init(_:)@swift-url-routing/Sources/URLRouting/Body.swift:28:10)
8.	While evaluating request InferredGenericSignatureRequest(URLRouting, <Bytes where Bytes : Parser, Bytes.Input == Data>, <C>, URLRouting.(file).Body.init(_:)@swift-url-routing/Sources/URLRouting/Body.swift:28:10, {}, {(C, C)}, 0)
9.	While evaluating request InferredGenericSignatureRequestRQM(<Bytes where Bytes : Parser, Bytes.Input == Data>, <C>, URLRouting.(file).Body.init(_:)@swift-url-routing/Sources/URLRouting/Body.swift:28:10, {}, {(C, C)}, 0)
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           0x0000000108d57780 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000108d56784 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000108d57e04 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x000000019523f4a4 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000195227ee0 pthread_kill + 288
5  libsystem_c.dylib        0x0000000195162340 abort + 168
6  swift-frontend           0x00000001056ec578 swift::rewriting::RewriteContext::getRelativeTermForType(swift::CanType, llvm::ArrayRef<swift::rewriting::Term>) + 0
7  swift-frontend           0x00000001056ff04c swift::rewriting::RequirementMachine::buildRequirementsFromRules(llvm::ArrayRef<unsigned int>, llvm::ArrayRef<unsigned int>, swift::ArrayRefView<swift::Type, swift::GenericTypeParamType*, swift::GenericTypeParamType* swift::staticCastHelper<swift::GenericTypeParamType>(swift::Type const&), true>, bool, std::__1::vector<swift::Requirement, std::__1::allocator<swift::Requirement> >&, std::__1::vector<swift::ProtocolTypeAlias, std::__1::allocator<swift::ProtocolTypeAlias> >&) const + 548
8  swift-frontend           0x000000010570d2b0 swift::rewriting::RequirementMachine::computeMinimalGenericSignature(bool) + 220
9  swift-frontend           0x000000010570f674 swift::InferredGenericSignatureRequestRQM::evaluate(swift::Evaluator&, swift::GenericSignatureImpl const*, swift::GenericParamList*, swift::WhereClauseOwner, llvm::SmallVector<swift::Requirement, 2u>, llvm::SmallVector<swift::TypeLoc, 2u>, bool) const + 2740
10 swift-frontend           0x00000001051b5690 swift::SimpleRequest<swift::InferredGenericSignatureRequestRQM, 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::InferredGenericSignatureRequestRQM const&, swift::Evaluator&) + 316
11 swift-frontend           0x000000010564c0c8 llvm::Expected<swift::InferredGenericSignatureRequestRQM::OutputType> swift::Evaluator::getResultCached<swift::InferredGenericSignatureRequestRQM, (void*)0>(swift::InferredGenericSignatureRequestRQM const&) + 1900
12 swift-frontend           0x000000010563e220 swift::InferredGenericSignatureRequest::evaluate(swift::Evaluator&, swift::ModuleDecl*, swift::GenericSignatureImpl const*, swift::GenericParamList*, swift::WhereClauseOwner, llvm::SmallVector<swift::Requirement, 2u>, llvm::SmallVector<swift::TypeLoc, 2u>, bool) const + 388
13 swift-frontend           0x00000001051b5508 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::ModuleDecl*, 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&) + 368
14 swift-frontend           0x000000010509ca30 llvm::Expected<swift::InferredGenericSignatureRequest::OutputType> swift::Evaluator::getResultUncached<swift::InferredGenericSignatureRequest>(swift::InferredGenericSignatureRequest const&) + 680
15 swift-frontend           0x000000010509c690 llvm::Expected<swift::InferredGenericSignatureRequest::OutputType> swift::Evaluator::getResultCached<swift::InferredGenericSignatureRequest, (void*)0>(swift::InferredGenericSignatureRequest const&) + 620
16 swift-frontend           0x00000001051573fc swift::GenericSignatureRequest::evaluate(swift::Evaluator&, swift::GenericContext*) const + 2336
17 swift-frontend           0x000000010551b52c swift::GenericContext::getGenericSignature() const + 1640
18 swift-frontend           0x00000001050f4dec swift::InterfaceTypeRequest::evaluate(swift::Evaluator&, swift::ValueDecl*) const + 296
19 swift-frontend           0x0000000105525e9c swift::InterfaceTypeRequest::OutputType swift::evaluateOrDefault<swift::InterfaceTypeRequest>(swift::Evaluator&, swift::InterfaceTypeRequest, swift::InterfaceTypeRequest::OutputType) + 948
20 swift-frontend           0x000000010512f88c swift::ASTVisitor<(anonymous namespace)::DeclChecker, void, void, void, void, void, void>::visit(swift::Decl*) + 308
21 swift-frontend           0x000000010512c6e4 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 400
22 swift-frontend           0x000000010513036c swift::ASTVisitor<(anonymous namespace)::DeclChecker, void, void, void, void, void, void>::visit(swift::Decl*) + 3092
23 swift-frontend           0x000000010512c6e4 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 400
24 swift-frontend           0x000000010512c548 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 204
25 swift-frontend           0x00000001051f6270 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 540
26 swift-frontend           0x00000001051f8f1c llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 576
27 swift-frontend           0x00000001051f6000 swift::performTypeChecking(swift::SourceFile&) + 120
28 swift-frontend           0x0000000104419198 bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_6>(long, swift::SourceFile&) + 16
29 swift-frontend           0x000000010441390c swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) + 288
30 swift-frontend           0x00000001044137b0 swift::CompilerInstance::performSema() + 148
31 swift-frontend           0x00000001043a65d4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4364
32 swift-frontend           0x00000001043476e8 swift::mainEntry(int, char const**) + 3940
33 dyld                     0x000000010b65508c start + 520

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please fill out the following information)

  • Xcode Version/Tag/Branch: 14.1 (beta 1)

Additional context

Related: pointfreeco/swift-url-routing#52

@stephencelis stephencelis added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Sep 19, 2022
@stephencelis
Copy link
Contributor Author

@slavapestov This may be in your wheelhouse?

@stephencelis
Copy link
Contributor Author

I worked around the problem by replacing the Bytes.Input in this line:

https://github.com/pointfreeco/swift-url-routing/blob/0.3.0/Sources/URLRouting/Body.swift#L29

With Data (which is equivalent).

  where Bytes == Parsers.MapConversion<Parsers.ReplaceError<Rest<Data>>, C> {

@AnthonyLatsis AnthonyLatsis added compiler crash generics Feature: generic declarations and types labels Sep 19, 2022
@slavapestov
Copy link
Contributor

slavapestov commented Sep 19, 2022

Nice, I was about to suggest the same workaround but you beat me to it.

Here is a reduced test case:

struct Data {}

protocol Parser {
  associatedtype Input
}

struct Rest<Input>: Parser {}

struct Body<Bytes: Parser> where Bytes.Input == Data {
  init<C: Parser>(_: C) where Bytes == Rest<Bytes.Input>, C.Input == Bytes.Input {}
}

@slavapestov
Copy link
Contributor

The problem is that the requirement Bytes.Input == Data is not minimized away. It should be redundant because it is implied by Bytes == Parsers.MapConversion<Parsers.ReplaceError<Rest<Data>>, C> (or in my test case, just Bytes == Rest<Data>).

@slavapestov
Copy link
Contributor

The regression was introduced by #60507, but it's exposing an existing bug which needs to be fixed in a more fundamental way.

@slavapestov slavapestov self-assigned this Sep 20, 2022
slavapestov added a commit to slavapestov/swift that referenced this issue Sep 20, 2022
…e equivalence classes

This fixes an edge case where we start with the following requirements:

    - U : P
    - T : P
    - T.[P]A == C
    - T == G<T.[P]A>
    - U.[P]A == T.[P]A

and end up with the following set of minimal rules (where the type
witness for [P]A in the conformance G<C> : P is C):

    - U.[P] => U
    - U.[P:A] => T.[P:A]
    - T.[concrete: G<C>] => T
    - T.[concrete: G<C> : P] => T

Since U.[P]A and T.[P]A are concrete, we split the abstract same-type
requirement into two requirements, and re-run minimization:

    - U : P
    - T.[P]A == C
    - U.[P]A == C
    - T == G<C>

The concrete conformance rule T.[concrete: G<C> : P] => T does not
correspond to a requirement, so it was simply dropped, and the above
rules violate post-contraction invariants; T.[P]A is not a valid
type parameter because there is no conformance requirement T : P in
the minimized signature.

We can fix this by re-running concrete contraction after splitting
concrete equivalence classes. After contraction, the above requirements
turn into

    - U : P
    - C == C
    - U.[P]A == C
    - T == G<C>

Which correctly minimizes to

    - U : P
    - U.[P]A == C
    - T == G<C>

Both concrete contraction and concrete equivalence classes are hacks,
and we should think of a way to directly express the transformations
they perform with the rewrite system.

Fixes swiftlang#61192.
@slavapestov
Copy link
Contributor

swift-url-routing no longer crashes when built with my fix.

@AnthonyLatsis AnthonyLatsis added crash Bug: A crash, i.e., an abnormal termination of software compiler The Swift compiler itself labels Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types
Projects
None yet
3 participants