Skip to content

SILGen crash with propertyWrapper on an implicitly initialized property #65562

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

Closed
ellishg opened this issue May 1, 2023 · 5 comments
Closed
Labels
assertion failure Bug → crash: An assertion failure attributes Feature: Declaration and type attributes @autoclosure Feature → attributes: the @autoclosure type attribute 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 duplicate Resolution: Duplicates another issue property wrappers Feature: property wrappers SILGen Area → compiler: The SIL generation stage swift 5.9

Comments

@ellishg
Copy link
Contributor

ellishg commented May 1, 2023

Description
Swift hits an assert in some cases when using propertyWrappers. This is very similar to #58201 which I previously reported, but I found a different assert when @escaping is left out.

Steps to reproduce
Try to compile the following

@propertyWrapper
public class Bar<Value> {
  var value: Value
  // Add @escaping to fix
  public init(wrappedValue: @autoclosure () -> Value) {
    self.value = wrappedValue()
  }
  public var wrappedValue: Value { return value }
}

struct Foo {
  // Or manually initialize to nil to fix
  @Bar var blah: Bool?
}
0  swift-frontend           0x00000001076535b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001076525b4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000107653c34 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x0000000188756a84 _sigtramp + 56
4  swift-frontend           0x00000001032e8de8 swift::Lowering::SILGenFunction::emitGeneratorFunction(swift::SILDeclRef, swift::Expr*, bool) + 1336
5  swift-frontend           0x00000001032e8de8 swift::Lowering::SILGenFunction::emitGeneratorFunction(swift::SILDeclRef, swift::Expr*, bool) + 1336
6  swift-frontend           0x0000000103257a54 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 12920
7  swift-frontend           0x0000000103259740 emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef, bool) + 228
8  swift-frontend           0x000000010333672c (anonymous namespace)::SILGenType::emitType() + 876
9  swift-frontend           0x000000010325d6e0 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 104
10 swift-frontend           0x000000010325bee4 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 3356
11 swift-frontend           0x0000000103328f10 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
12 swift-frontend           0x000000010325f6e4 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 628
13 swift-frontend           0x0000000102ca0758 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5860
14 swift-frontend           0x0000000102c41294 swift::mainEntry(int, char const**) + 3940
15 dyld                     0x00000001883cff28 start + 2236

Expected behavior
The compiler should not crash

Environment

  • Swift compiler version info 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
  • Xcode 14.2
  • macosx 13.0
@ellishg ellishg added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 1, 2023
@ellishg
Copy link
Contributor Author

ellishg commented May 2, 2023

@hank121314 since you fixed #58201, do you know what might be going on here?

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself property wrappers Feature: property wrappers swift 5.9 SILGen Area → compiler: The SIL generation stage attributes Feature: Declaration and type attributes @autoclosure Feature → attributes: the @autoclosure type attribute crash Bug: A crash, i.e., an abnormal termination of software and removed triage needed This issue needs more specific labels labels May 2, 2023
@AnthonyLatsis
Copy link
Collaborator

The crash happens at a later compilation stage but essentially this is the same issue. All it takes to reproduce it via the #58201 snippet is to humor semantic analysis with an empty getter in var wrappedValue: Value { get {} }. We got rid of the type checker crash but forgot to verify the compiler behaves further down the line.

@ellishg
Copy link
Contributor Author

ellishg commented Jul 19, 2023

Friendly ping. I'm seeing lots of workarounds in our codebase (usually by adding = nil) and I'd like to see this fixed. @AnthonyLatsis or @hank121314 do you have time to look into this?

@AnthonyLatsis AnthonyLatsis added assertion failure Bug → crash: An assertion failure duplicate Resolution: Duplicates another issue labels Jul 21, 2023
@AnthonyLatsis
Copy link
Collaborator

For now, let’s make this a duplicate and reopen the older issue.

@AnthonyLatsis AnthonyLatsis closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2023
@AnthonyLatsis
Copy link
Collaborator

Duplicate of #58201

@AnthonyLatsis AnthonyLatsis marked this as a duplicate of #58201 Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertion failure Bug → crash: An assertion failure attributes Feature: Declaration and type attributes @autoclosure Feature → attributes: the @autoclosure type attribute 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 duplicate Resolution: Duplicates another issue property wrappers Feature: property wrappers SILGen Area → compiler: The SIL generation stage swift 5.9
Projects
None yet
Development

No branches or pull requests

3 participants
@ellishg @AnthonyLatsis and others