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

Compiler crash with associated types #11

Open
eito opened this issue Jan 9, 2023 · 0 comments
Open

Compiler crash with associated types #11

eito opened this issue Jan 9, 2023 · 0 comments

Comments

@eito
Copy link

eito commented Jan 9, 2023

I've run into an issue where one of my "view models" has an associated type that itself has an associated type.

It looks like it's crashing the Swift compiler and I'm not sure if there is something I can potentially do to work around or alter my modeling to get past this.

Here is my project.
https://github.com/eito/xui-bug

Xcode 14.2

Inside the ContentView.swift I have 3 approaches for different approaches for how the view model is defined in the view/how it's used.

This approach fails to compile -- triggers the crash

struct ContentView: View {

    @Store
    var viewModel: any MainViewModelProtocol

    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
        .sheet(item: $viewModel.otherViewModel) { viewModel in   // this is triggering the issue when the view model defined this way
            Text(viewModel.otherText)
        }
    }
}

This approach compiles, but isn't a valid solution

struct ContentView: View {

    @Store
    var viewModel: any MainViewModelProtocol

    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
    }
}

This approach also compiles, but is also not a valid solution for me.

struct ContentView: View {

    @Store
    var viewModel = MainViewModel()

    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
        .sheet(item: $viewModel.otherViewModel) { viewModel in  // doesn't seem to be an issue here when not using `any Protocol`
            Text(viewModel.otherText)
        }
    }
}
[cleanup] %12 = argument of bb1 : $(@opened("326347C4-9070-11ED-82C7-6E1647E6637C") MainViewModelProtocol).OtherViewModelType
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.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Volumes/Source/github/xui-bug/xui-bug/ContentView.swift /Volumes/Source/github/xui-bug/xui-bug/xui_bugApp.swift -emit-dependencies-path /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/Objects-normal/arm64/ContentView.d -emit-reference-dependencies-path /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/Objects-normal/arm64/ContentView.swiftdeps -serialize-diagnostics-path /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/Objects-normal/arm64/ContentView.dia -emit-localized-strings -emit-localized-strings-path /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/Objects-normal/arm64 -target arm64-apple-ios16.2-simulator -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-14.2.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.2.sdk -I /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Products/Debug-iphonesimulator -F /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Products/Debug-iphonesimulator/PackageFrameworks -F /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Products/Debug-iphonesimulator -no-color-diagnostics -enable-testing -g -module-cache-path /Users/eric5320/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -enable-bare-slash-regex -empty-abi-descriptor -Xcc -working-directory -Xcc /Volumes/Source/github/xui-bug -resource-dir /Applications/Xcode-14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/xui-bug-generated-files.hmap -Xcc -I/Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/xui-bug-own-target-headers.hmap -Xcc -I/Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/xui-bug-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/xui-bug-project-headers.hmap -Xcc -I/Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/DerivedSources-normal/arm64 -Xcc -I/Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/DerivedSources/arm64 -Xcc -I/Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/DerivedSources -Xcc -DDEBUG=1 -module-name xui_bug -frontend-parseable-output -disable-clang-spi -target-sdk-version 16.2 -o /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Build/Intermediates.noindex/xui-bug.build/Debug-iphonesimulator/xui-bug.build/Objects-normal/arm64/ContentView.o -index-unit-output-path /xui-bug.build/Debug-iphonesimulator/xui-bug.build/Objects-normal/arm64/ContentView.o -index-store-path /Users/eric5320/Library/Developer/Xcode/DerivedData/xui-bug-gfgjrlhqjfteipclhpaikfkywkel/Index.noindex/DataStore -index-system-modules
1.	Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Volumes/Source/github/xui-bug/xui-bug/ContentView.swift")
4.	While silgen emitFunction SIL function "@$s7xui_bug11ContentViewV4bodyQrvg".
 for getter for body (at /Volumes/Source/github/xui-bug/xui-bug/ContentView.swift:65:9)
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           0x0000000108d775b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000108d765b4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000108d77c34 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001989034a4 _sigtramp + 56
4  swift-frontend           0x0000000104a3abb8 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 9880
5  swift-frontend           0x0000000104a3f9a4 swift::Lowering::ManagedValue llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext)>::callback_fn<(anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext)::$_7>(long, swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext) + 120
6  swift-frontend           0x00000001049ceb9c std::__1::__function::__func<swift::Lowering::SILGenFunction::emitOptionalToOptional(swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext)>, swift::Lowering::SGFContext)::$_1, std::__1::allocator<swift::Lowering::SILGenFunction::emitOptionalToOptional(swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext)>, swift::Lowering::SGFContext)::$_1>, void (swift::Lowering::ManagedValue, swift::Lowering::SwitchCaseFullExpr&&)>::operator()(swift::Lowering::ManagedValue&&, swift::Lowering::SwitchCaseFullExpr&&) + 628
7  swift-frontend           0x00000001049732a4 swift::Lowering::SwitchEnumBuilder::emit() && + 2300
8  swift-frontend           0x00000001049ca768 swift::Lowering::SILGenFunction::emitOptionalToOptional(swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SILType, swift::Lowering::SGFContext)>, swift::Lowering::SGFContext) + 2228
9  swift-frontend           0x0000000104a38a64 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1348
10 swift-frontend           0x0000000104a37f5c swift::Lowering::SILGenFunction::emitSubstToOrigValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 236
11 swift-frontend           0x00000001049eb188 getOrCreateKeyPathGetter(swift::Lowering::SILGenModule&, swift::AbstractStorageDecl*, swift::SubstitutionMap, swift::GenericEnvironment*, swift::ResilienceExpansion, llvm::ArrayRef<std::__1::pair<swift::CanType, swift::SILType> >, swift::CanType, swift::CanType) + 3508
12 swift-frontend           0x00000001049e76fc swift::Lowering::SILGenModule::emitKeyPathComponentForDecl(swift::SILLocation, swift::GenericEnvironment*, swift::ResilienceExpansion, unsigned int&, bool&, swift::SubstitutionMap, swift::AbstractStorageDecl*, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::CanType, swift::DeclContext*, bool) + 3772
13 swift-frontend           0x00000001049fe80c (anonymous namespace)::RValueEmitter::visitKeyPathExpr(swift::KeyPathExpr*, swift::Lowering::SGFContext) + 1128
14 swift-frontend           0x00000001049e6088 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
15 swift-frontend           0x000000010499a28c (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3328
16 swift-frontend           0x0000000104989634 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 184
17 swift-frontend           0x0000000104993c30 emitPseudoFunctionArguments(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::FunctionType>, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, swift::Lowering::PreparedArguments&&) + 344
18 swift-frontend           0x0000000104993864 swift::Lowering::SILGenFunction::prepareSubscriptIndices(swift::SubscriptDecl*, swift::SubstitutionMap, swift::AccessStrategy, swift::ArgumentList*) + 444
19 swift-frontend           0x0000000104a14cd8 swift::ASTVisitor<SILGenLValue, swift::Lowering::LValue, void, void, void, void, void, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions>::visit(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 3932
20 swift-frontend           0x0000000104a13c9c swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 48
21 swift-frontend           0x00000001049f2234 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 10028
22 swift-frontend           0x00000001049e6088 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
23 swift-frontend           0x0000000104999e4c (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 2240
24 swift-frontend           0x0000000104989634 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 184
25 swift-frontend           0x00000001049a26d0 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 420
26 swift-frontend           0x00000001049a2260 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 792
27 swift-frontend           0x000000010498e39c (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2340
28 swift-frontend           0x000000010498bf68 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2512
29 swift-frontend           0x00000001049e3634 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 80
30 swift-frontend           0x00000001049d265c swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 2164
31 swift-frontend           0x000000010497f1b4 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 148
32 swift-frontend           0x0000000104a4df30 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 3316
33 swift-frontend           0x0000000104a09398 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 724
34 swift-frontend           0x000000010497b210 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 10804
35 swift-frontend           0x000000010497d740 emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef, bool) + 228
36 swift-frontend           0x00000001049787c4 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 360
37 swift-frontend           0x0000000104a5dca4 (anonymous namespace)::SILGenType::visitVarDecl(swift::VarDecl*) + 692
38 swift-frontend           0x0000000104a5a4d8 (anonymous namespace)::SILGenType::emitType() + 280
39 swift-frontend           0x00000001049816e0 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
40 swift-frontend           0x000000010497fee4 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 3356
41 swift-frontend           0x0000000104a4cf10 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 216
42 swift-frontend           0x00000001049836e4 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 628
43 swift-frontend           0x00000001043c4758 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5860
44 swift-frontend           0x0000000104365294 swift::mainEntry(int, char const**) + 3940
45 dyld                     0x000000010b57908c start + 520

Any ideas? I'll also submit a Swift bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant