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-11603] Compiler crash when combining property wrappers #54010

Closed
mortenbekditlevsen mannequin opened this issue Oct 12, 2019 · 7 comments
Closed

[SR-11603] Compiler crash when combining property wrappers #54010

mortenbekditlevsen mannequin opened this issue Oct 12, 2019 · 7 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

@mortenbekditlevsen
Copy link
Mannequin

mortenbekditlevsen mannequin commented Oct 12, 2019

Previous ID SR-11603
Radar rdar://problem/56255391
Original Reporter @mortenbekditlevsen
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 11.1
Toolchain: Snapshot of master from Oct. 10th

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

md5: 1697befa2eb4165409e07f101d44070b

Issue Description:

When combining @ObservedObject property wrapper with a property wrapper of my own, the compiler crashes:

@ObservedObject @A var a: Int = 1

Here is the stack trace:

Assertion failed: (address.isLValue() && "physical lvalue decl ref must evaluate to an address"), function emitUsingStorage, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SILGen/SILGenLValue.cpp, line 2628.
Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-10-10-a.xctoolchain/usr/bin/swift -frontend -c /Users/mortenbekditlevsen/Desktop/Test/Test/AppDelegate.swift /Users/mortenbekditlevsen/Desktop/Test/Test/SceneDelegate.swift -primary-file /Users/mortenbekditlevsen/Desktop/Test/Test/ContentView.swift -emit-module-path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/ContentView~partial.swiftmodule -emit-module-doc-path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/ContentView~partial.swiftdoc -emit-module-source-info-path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/ContentView~partial.swiftsourceinfo -serialize-diagnostics-path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/ContentView.dia -emit-dependencies-path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/ContentView.d -emit-reference-dependencies-path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/ContentView.swiftdeps -target x86_64-apple-ios13.1-simulator -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.1.sdk -I /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Products/Debug-iphonesimulator -F /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -enable-anonymous-context-mangled-names -Xcc -I/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Test-generated-files.hmap -Xcc -I/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Test-own-target-headers.hmap -Xcc -I/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Test-all-target-headers.hmap -Xcc -iquote -Xcc /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Test-project-headers.hmap -Xcc -I/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/DerivedSources-normal/x86_64 -Xcc -I/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/DerivedSources/x86_64 -Xcc -I/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/mortenbekditlevsen/Desktop/Test -module-name Test -o /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Build/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/ContentView.o -index-store-path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/Test-bhccrlkgiqkpkzcabetvkbmxbfbc/Index/DataStore -index-system-modules
1. Apple Swift version 5.1.1-dev (LLVM 6e04008c7f, Swift d930599394)
2. While emitting SIL for setter for a (at /Users/mortenbekditlevsen/Desktop/Test/Test/ContentView.swift:23:28)
3. While silgen emitFunction SIL function "@$s4Test11ContentViewV1aSivs".
for setter for a (at /Users/mortenbekditlevsen/Desktop/Test/Test/ContentView.swift:23:28)
0 swift 0x0000000108df92e5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1 swift 0x0000000108df8595 llvm::sys::RunSignalHandlers() + 85
2 swift 0x0000000108df98c8 SignalHandler(int) + 264
3 libsystem_platform.dylib 0x00007fff60d35b1d _sigtramp + 29
4 libsystem_platform.dylib 0x000000011c359268 _sigtramp + 3143776104
5 libsystem_c.dylib 0x00007fff60c0ba08 abort + 120
6 libsystem_c.dylib 0x00007fff60c0acc2 err + 0
7 swift 0x0000000108f0a6e3 swift::Lowering::LValue::addNonMemberVarComponent(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::VarDecl*, swift::SubstitutionMap, swift::Lowering::LValueOptions, swift::Lowering::SGFAccessKind, swift::AccessStrategy, swift::CanType) (.cold.11) + 35
8 swift 0x00000001055454c0 swift::Lowering::LValue::addNonMemberVarComponent(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::VarDecl*, swift::SubstitutionMap, swift::Lowering::LValueOptions, swift::Lowering::SGFAccessKind, swift::AccessStrategy, swift::CanType) + 2384
9 swift 0x00000001055462d2 emitLValueForNonMemberVarDecl(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::ConcreteDeclRef, swift::CanType, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions, swift::AccessSemantics) + 258
10 swift 0x0000000105546ad7 SILGenLValue::visitDeclRefExpr(swift::DeclRefExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 183
11 swift 0x0000000105544057 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) + 279
12 swift 0x00000001055444be SILGenLValue::visitRec(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions, swift::Lowering::AbstractionPattern) + 206
13 swift 0x0000000105547b7b SILGenLValue::visitMemberRefExpr(swift::MemberRefExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 923
14 swift 0x0000000105544071 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) + 305
15 swift 0x00000001055444be SILGenLValue::visitRec(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions, swift::Lowering::AbstractionPattern) + 206
16 swift 0x0000000105547b7b SILGenLValue::visitMemberRefExpr(swift::MemberRefExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 923
17 swift 0x0000000105544071 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) + 305
18 swift 0x00000001055444be SILGenLValue::visitRec(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions, swift::Lowering::AbstractionPattern) + 206
19 swift 0x0000000105547b7b SILGenLValue::visitMemberRefExpr(swift::MemberRefExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 923
20 swift 0x0000000105544071 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) + 305
21 swift 0x0000000105543e77 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 55
22 swift 0x000000010552ef3b emitSimpleAssignment(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Expr*, swift::Expr*) + 939
23 swift 0x0000000105520705 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 12181
24 swift 0x0000000105513b18 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 1128
25 swift 0x0000000105584e93 (anonymous namespace)::StmtEmitter::visitBraceStmt(swift::BraceStmt*) + 323
26 swift 0x000000010557f565 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
27 swift 0x000000010553631e swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 366
28 swift 0x00000001054bb9fd swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_0::operator()(swift::SILFunction*) const + 237
29 swift 0x00000001054b4183 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 611
30 swift 0x000000010558d385 void llvm::function_ref<void (swift::AccessorDecl*)>::callback_fn<(anonymous namespace)::SILGenType::visitAccessors(swift::AbstractStorageDecl*)::'lambda'(swift::AccessorDecl*)>(long, swift::AccessorDecl*) + 21
31 swift 0x0000000105fac405 swift::AbstractStorageDecl::visitExpectedOpaqueAccessors(llvm::function_ref<void (swift::AccessorKind)>) const + 309
32 swift 0x0000000105fac275 swift::AbstractStorageDecl::visitEmittedAccessors(llvm::function_ref<void (swift::AccessorDecl*)>) const + 149
33 swift 0x000000010558d208 (anonymous namespace)::SILGenType::visitVarDecl(swift::VarDecl*) + 184
34 swift 0x000000010558ad2b (anonymous namespace)::SILGenType::emitType() + 379
35 swift 0x000000010558aba9 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
36 swift 0x00000001054b90d3 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 867
37 swift 0x00000001054ba004 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 308
38 swift 0x00000001054ba456 swift::performSILGeneration(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions&) + 38
39 swift 0x00000001051c79e3 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 7411
40 swift 0x00000001051c4d86 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3046
41 swift 0x000000010516a319 main + 729
42 libdyld.dylib 0x00007fff60b34405 start + 1
43 libdyld.dylib 0x0000000000000049 start + 2672606277
error: Abort trap: 6 (in target 'Test' from project 'Test')

@theblixguy
Copy link
Collaborator

Reproducer that doesn't involve SwiftUI or Combine:

@propertyWrapper
struct MyObservedObject<T> {
  var wrappedValue: T
}

@propertyWrapper
class Wrapper<T> {
  var wrappedValue: T
  init(wrappedValue: T) {
    self.wrappedValue = wrappedValue
  }
}


struct Foo {
  @MyObservedObject @Wrapper var a: Int

  func bar() {
    a = 1
  }
}

@belkadan
Copy link
Contributor

@swift-ci create

@beccadax
Copy link
Contributor

@theblixguy's reproducer works for me. (Thanks, Suyash!) From messing around in the debugger, it looks like it’s trying to lower the indicated AST node into an lvalue:

(accessor_decl implicit range=[suyash-repro.swift:16:34 - line:16:34] 'anonname=0x1180dbeb0' interface type='(Foo) -> (Int) -> ()' access=internal set_for=a
  (parameter "self" type='Foo' interface type='Foo')
  (parameter_list
    (parameter "value" type='Int' interface type='Int') range=[suyash-repro.swift:16:34 - line:16:34])
  (brace_stmt implicit range=[suyash-repro.swift:16:34 - line:16:34]
    (assign_expr implicit type='()'
      (member_ref_expr implicit type='@lvalue Int' decl=main.(file).Wrapper.wrappedValue@suyash-repro.swift:8:7 [with (substitution_map generic_signature=<T> (substitution T -> Int))]
        (member_ref_expr implicit type='@lvalue Wrapper<Int>' decl=main.(file).MyObservedObject.wrappedValue@suyash-repro.swift:3:7 [with (substitution_map generic_signature=<T> (substitution T -> Wrapper<Int>))]
          (member_ref_expr implicit type='@lvalue MyObservedObject<Wrapper<Int>>' decl=main.(file).Foo._a@suyash-repro.swift:16:34 direct_to_storage
==>         (declref_expr implicit type='@lvalue Foo' decl=main.(file).Foo.<anonymous>.self@suyash-repro.swift:16:34 function_ref=unapplied)))) <==
      (declref_expr implicit type='Int' decl=main.(file).Foo.<anonymous>.value@suyash-repro.swift:16:34 function_ref=unapplied))))

If I’m reading this dump correctly, this is a nonmutating setter, so self isn’t and shouldn’t be mutable. MyObservedObject is a struct while Wrapper is a class, so I don’t think that the DeclRefExpr or its parent or grandparent MemberRefExpr actually need to evaluate to lvalues. I therefore suspect this is a bug in the synthesis of property wrapper accessors in Sema.

@theblixguy
Copy link
Collaborator

Hmm, we should already be using getPropertyWrapperMutability to compute the mutating-ness for accessors, but I thought it was already handled by the respective requests... maybe not or maybe something is overwriting it. I'll take a look!

@theblixguy
Copy link
Collaborator

PR: #27727

@theblixguy
Copy link
Collaborator

Fixed on master. Please verify using the next development snapshot!

@mortenbekditlevsen
Copy link
Mannequin Author

mortenbekditlevsen mannequin commented Oct 22, 2019

Hi Suyash,
Thanks so much for fixing this![]( It works like a charm on the snapshot from the 20th)
Really excellent work![]( I am so happy to start experimenting with composing property wrappers)!! :-)

@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