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-10985] Crash when using didSet in @State property wrapper #53375

Closed
theblixguy opened this issue Jun 20, 2019 · 4 comments
Closed

[SR-10985] Crash when using didSet in @State property wrapper #53375

theblixguy opened this issue Jun 20, 2019 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software property wrappers Feature: property wrappers

Comments

@theblixguy
Copy link
Collaborator

Previous ID SR-10985
Radar None
Original Reporter @theblixguy
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 11 beta 2 and macOS 10.15 beta 2.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, PropertyWrappers
Assignee @DougGregor
Priority Medium

md5: a070bd793eb03fa40929130ae7b3a44a

duplicates:

  • SR-10918 Segfault when using didSet with a property wrapper

Issue Description:

import SwiftUI

struct ToggleModel: Identifiable {
  let id: UUID = UUID()
  var value: Bool
}

struct ToggleView: View {
  @State var value: Bool {
    didSet { } // causes the crash
  }
  
  var body: some View {
    Toggle(isOn: $value) {
      Text("Toggle state is \(String(value))")
    }
  }
}

struct ContentView: View {
  private var models: [ToggleModel] = [.init(value: true),
                                       .init(value: false)]

  var body: some View {
    List(models) { model in
      ToggleView(value: model.value)
    }
  }
}

Stack trace:

(nil_literal_expr type='Builtin.UnknownObject'Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/suyashsrijan/Documents/Personal Projects/SwiftUI_Test/SwiftUI_Test/AppDelegate.swift /Users/suyashsrijan/Documents/Personal Projects/SwiftUI_Test/SwiftUI_Test/SceneDelegate.swift -primary-file /Users/suyashsrijan/Documents/Personal Projects/SwiftUI_Test/SwiftUI_Test/ContentView.swift -emit-module-path /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/Objects-normal/x86_64/ContentView~partial.swiftmodule -emit-module-doc-path /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/Objects-normal/x86_64/ContentView~partial.swiftdoc -serialize-diagnostics-path /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/Objects-normal/x86_64/ContentView.dia -emit-dependencies-path /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/Objects-normal/x86_64/ContentView.d -emit-reference-dependencies-path /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/Objects-normal/x86_64/ContentView.swiftdeps -target x86_64-apple-ios13.0-simulator -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk -I /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Products/Debug-iphonesimulator -F /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/suyashsrijan/Documents/Personal Projects/SwiftUI_Test -enable-anonymous-context-mangled-names -Xcc -I/Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/SwiftUI_Test-generated-files.hmap -Xcc -I/Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/SwiftUI_Test-own-target-headers.hmap -Xcc -I/Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/SwiftUI_Test-all-target-headers.hmap -Xcc -iquote -Xcc /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/SwiftUI_Test-project-headers.hmap -Xcc -I/Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/DerivedSources-normal/x86_64 -Xcc -I/Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/DerivedSources/x86_64 -Xcc -I/Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/DerivedSources -Xcc -DDEBUG=1 -module-name SwiftUI_Test -o /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Build/Intermediates.noindex/SwiftUI_Test.build/Debug-iphonesimulator/SwiftUI_Test.build/Objects-normal/x86_64/ContentView.o -index-store-path /Users/suyashsrijan/Library/Developer/Xcode/DerivedData/SwiftUI_Test-ahtcoicvtajljahamcfqwjnlfhlf/Index/DataStore -index-system-modules 
1.  While emitting property descriptor for 'value' (at /Users/suyashsrijan/Documents/Personal Projects/SwiftUI_Test/SwiftUI_Test/ContentView.swift:17:14)
0  swift                    0x000000010d028963 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010d028136 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff643d2b1d _sigtramp + 29
3  swift                    0x000000010971ae78 swift::constraints::ExpressionTimer::~ExpressionTimer() + 40
4  swift                    0x0000000109aeb63f swift::ASTVisitor<(anonymous namespace)::PrintExpr, void, void, void, void, void, void>::visit(swift::Expr*) + 79
5  swift                    0x0000000109b03e74 swift::Expr::dump(llvm::raw_ostream&, unsigned int) const + 68
6  swift                    0x00000001091326f3 SILGenLValue::visitExpr(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 35
7  swift                    0x000000010913253c 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) + 12988
8  swift                    0x000000010912f1a2 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 34
9  swift                    0x000000010908f8f1 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1425
10 swift                    0x00000001090a0ff5 (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>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 1061
11 swift                    0x000000010909e00b (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1451
12 swift                    0x000000010909bac3 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3059
13 swift                    0x00000001090ae60e swift::Lowering::SILGenFunction::emitSetAccessor(swift::SILLocation, swift::SILDeclRef, swift::SubstitutionMap, swift::Lowering::ArgumentSource&&, bool, bool, swift::Lowering::PreparedArguments&&, swift::Lowering::ArgumentSource&&, bool) + 1806
14 swift                    0x0000000109129cd9 (anonymous namespace)::GetterSetterComponent::set(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ArgumentSource&&, swift::Lowering::ManagedValue) && + 649
15 swift                    0x000000010912d06c swift::Lowering::SILGenFunction::emitAssignToLValue(swift::SILLocation, swift::Lowering::ArgumentSource&&, swift::Lowering::LValue&&) + 2556
16 swift                    0x0000000109138b9e swift::Lowering::SILGenFunction::emitAssignToLValue(swift::SILLocation, swift::Lowering::RValue&&, swift::Lowering::LValue&&) + 142
17 swift                    0x000000010910e1b2 getOrCreateKeyPathSetter(swift::Lowering::SILGenModule&, swift::SILLocation, swift::AbstractStorageDecl*, swift::SubstitutionMap, swift::GenericEnvironment*, swift::ResilienceExpansion, llvm::ArrayRef<std::__1::pair<swift::CanType, swift::SILType> >, swift::CanType, swift::CanType) + 5490
18 swift                    0x000000010910770d swift::Lowering::SILGenModule::emitKeyPathComponentForDecl(swift::SILLocation, swift::GenericEnvironment*, swift::ResilienceExpansion, unsigned int&, bool&, swift::SubstitutionMap, swift::AbstractStorageDecl*, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::CanType, bool) + 4237
19 swift                    0x0000000109087ff8 swift::Lowering::SILGenModule::tryEmitPropertyDescriptor(swift::AbstractStorageDecl*) + 1272
20 swift                    0x0000000109172886 (anonymous namespace)::SILGenType::emitType() + 2230
21 swift                    0x000000010908a8ed swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 77
22 swift                    0x0000000109089b36 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1238
23 swift                    0x000000010908b5bc swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1244
24 swift                    0x0000000108c959f5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 28757
25 swift                    0x0000000108c8b0a4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6868
26 swift                    0x0000000108c1a333 main + 1219
27 libdyld.dylib            0x00007fff641d23f9 start + 1
error: Segmentation fault: 11

What's interesting is that each compile results in a slightly different dump at the top depending on the position of the braces of the didSet. Weird...

@theblixguy
Copy link
Collaborator Author

cc @DougGregor

@belkadan
Copy link
Contributor

With asserts:

AbstractStorageDecl::isSetterMutating is out of sync with whether the setter is actually mutating
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin19.0.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Yellowstone.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name main -o /var/folders/qy/2z8q344s57lg875tnwpdlw2c0000gn/T/--3c6c50.o 
1.  Swift version 5.1-dev (LLVM 7d54a7c711, Swift 0c3a951693)
2.  While walking into decl 'ToggleView' (at <stdin>:8:1)
3.  While verifying VarDecl 'value' (at <stdin>:9:14)

@DougGregor
Copy link
Member

Huh, I thought I had already fixed this. Thank you!

@DougGregor
Copy link
Member

Ah, I did! Fixed in #25524

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
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 in itself crash Bug: A crash, i.e., an abnormal termination of software property wrappers Feature: property wrappers
Projects
None yet
Development

No branches or pull requests

4 participants