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-15324] Function with default value after guard statement triggers captureInfo.hasBeenComputed() assertion failure #57646

Closed
BradLarson opened this issue Oct 14, 2021 · 1 comment · Fixed by #70835
Labels
assertion failure Bug → crash: An assertion failure 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 default arguments Feature: default arguments for value parameters SILGen Area → compiler: The SIL generation stage statements Feature: statements swift 6.0

Comments

@BradLarson
Copy link
Collaborator

Previous ID SR-15324
Radar None
Original Reporter @BradLarson
Type Bug
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 3834635bf2a835289c6dc1d000ee51a7

Issue Description:

At some point after the 2021-09-09 nightly snapshot and before the 2021-09-14 nightly (I haven't yet isolated it further), the following single-file example started triggering a captureInfo.hasBeenComputed() assertion failure in TypeLowering.cpp when building with debug symbols:

var hello: String? = ""

guard let test = hello else {
  fatalError()
}

func cleanExit(exitCode: Int32 = 0) {
}

To reproduce, place the above in a single file and run `swiftc -g file.swift`. Building without debug symbols will not trigger the assertion. Either removing the default value for the exitCode argument or removing the guard statement prevents the assertion from failing.

The full text of the assertion failure is as follows:

Assertion failed: (captureInfo.hasBeenComputed()), function operator(), file TypeLowering.cpp, line 2877.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types DiscoCrasher.swift -target x86_64-apple-macosx11.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -color-diagnostics -g -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a.xctoolchain/usr/bin/swift-driver -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -module-name DiscoCrasher -target-sdk-version 11.3.0 -emit-module-doc-path /var/folders/1s/z_s04yq55wq2jvgqghm8zm7w0000gp/T/TemporaryDirectory.eKkB4e/DiscoCrasher-1.swiftdoc -emit-module-source-info-path /var/folders/1s/z_s04yq55wq2jvgqghm8zm7w0000gp/T/TemporaryDirectory.eKkB4e/DiscoCrasher-1.swiftsourceinfo -o /var/folders/1s/z_s04yq55wq2jvgqghm8zm7w0000gp/T/TemporaryDirectory.eKkB4e/DiscoCrasher-1.swiftmodule -emit-abi-descriptor-path /var/folders/1s/z_s04yq55wq2jvgqghm8zm7w0000gp/T/TemporaryDirectory.eKkB4e/DiscoCrasher-1.abi.json
1.  Apple Swift version 5.6-dev (LLVM 7aef0efea99e2c6, Swift e4f71c8e118fc09)
2.  Compiling with the current language version
3.  While evaluating request ASTLoweringRequest(Lowering AST to SIL for module DiscoCrasher)
4.  While getting lowered local captures at 'cleanExit(exitCode:)' (at DiscoCrasher.swift:8:1)
5.  While lowering local captures at 'cleanExit(exitCode:)' (at DiscoCrasher.swift:8:1)
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           0x0000000106a978f7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x0000000106a96b15 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x0000000106a98146 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007fff2040cd7d _sigtramp + 29
4  libsystem_platform.dylib 0x00007f904d080570 _sigtramp + 18446743597719435280
5  libsystem_c.dylib        0x00007fff2031c406 abort + 125
6  libsystem_c.dylib        0x00007fff2031b7d8 err + 0
7  swift-frontend           0x0000000106b15883 std::__1::__function::__func<swift::Lowering::TypeConverter::getLoweredLocalCaptures(swift::SILDeclRef)::$_0, std::__1::allocator<swift::Lowering::TypeConverter::getLoweredLocalCaptures(swift::SILDeclRef)::$_0>, void (swift::CaptureInfo, swift::DeclContext*)>::operator()(swift::CaptureInfo&&, swift::DeclContext*&&) (.cold.13) + 35
8  swift-frontend           0x00000001022f84f7 std::__1::__function::__func<swift::Lowering::TypeConverter::getLoweredLocalCaptures(swift::SILDeclRef)::$_0, std::__1::allocator<swift::Lowering::TypeConverter::getLoweredLocalCaptures(swift::SILDeclRef)::$_0>, void (swift::CaptureInfo, swift::DeclContext*)>::operator()(swift::CaptureInfo&&, swift::DeclContext*&&) + 1367
9  swift-frontend           0x00000001022f97c8 std::__1::__function::__func<swift::Lowering::TypeConverter::getLoweredLocalCaptures(swift::SILDeclRef)::$_2, std::__1::allocator<swift::Lowering::TypeConverter::getLoweredLocalCaptures(swift::SILDeclRef)::$_2>, void (swift::SILDeclRef)>::operator()(swift::SILDeclRef&&) + 264
10 swift-frontend           0x00000001022e92a4 swift::Lowering::TypeConverter::getLoweredLocalCaptures(swift::SILDeclRef) + 836
11 swift-frontend           0x00000001022e8de4 swift::Lowering::TypeConverter::getConstantGenericSignature(swift::SILDeclRef) + 436
12 swift-frontend           0x00000001022e78bf swift::Lowering::TypeConverter::makeConstantInterfaceType(swift::SILDeclRef) + 1439
13 swift-frontend           0x000000010225cc93 swift::Lowering::TypeConverter::getConstantInfo(swift::TypeExpansionContext, swift::SILDeclRef) + 83
14 swift-frontend           0x0000000102253dce swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, llvm::function_ref<swift::SILFunction* (swift::SILLocation, swift::SILDeclRef)>, swift::ProfileCounter) + 142
15 swift-frontend           0x0000000102705058 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 360
16 swift-frontend           0x000000010270949c emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef, bool) + 364
17 swift-frontend           0x00000001027092eb swift::Lowering::SILGenModule::emitArgumentGenerators(llvm::PointerUnion<swift::ValueDecl*, swift::AbstractClosureExpr*, swift::FileUnit*>, swift::ParameterList*) + 171
18 swift-frontend           0x000000010270908f swift::Lowering::SILGenModule::emitAbstractFuncDecl(swift::AbstractFunctionDecl*) + 63
19 swift-frontend           0x0000000102705819 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 41
20 swift-frontend           0x000000010270baf4 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2020
21 swift-frontend           0x00000001027db5f6 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&) + 134
22 swift-frontend           0x000000010271037d llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 413
23 swift-frontend           0x000000010270c9a8 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&) + 168
24 swift-frontend           0x00000001020b330d performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2141
25 swift-frontend           0x00000001020a7c82 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4850
26 swift-frontend           0x000000010206fcd2 swift::mainEntry(int, char const**) + 546
27 libdyld.dylib            0x00007fff203e2f3d start + 1
28 libdyld.dylib            0x000000000000001d start + 18446603339975217377
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@BradLarson
Copy link
Collaborator Author

As an update, this assertion failure now also appears if the default value is removed from the above code (func cleanExit(exitCode: Int32)). The key elements appear to be the placement of the function after a guard statement in a file parsed as main.swift, as well as the generation of debug symbols (-g).

jkshtj added a commit to jkshtj/swift that referenced this issue Jan 11, 2024
unless skipping all function bodies

Changes in this commit ensure that all top-level functions appearing
after a `guard` statement are always typechecked, unless
`-experimental-skip-all-function-bodies` has been specified.

This means that such functions should be typechecked and SILGen-ed in
the presence of `-experimental-skip-non-inlinable-function-bodies` and
`-experimental-skip-non-inlinable-function-bodies-without-types` flags.

Fixes apple#57646
jkshtj added a commit to jkshtj/swift that referenced this issue Jan 11, 2024
Type-checking and SILGen for non-inlinable functions is skipped in the
presence of `-experimental-skip-non-inlinable-function-bodies` and
`-experimental-skip-non-inlinable-function-bodies-without-types` flags.

Such functions may be top-level and may contain captures (if they appear
after a `guard` statement), for which we were setting the type expansion
context during SILGen. Setting type expansion context however, relied on
the capture info being computed -- which was never happening because of
the abovementioned flags.

Changes in this commit make setting type expansion context, for
captures, conditional on a flag that ensures that the function has already
been typechecked.

Fixes apple#57646
@AnthonyLatsis AnthonyLatsis added SILGen Area → compiler: The SIL generation stage crash Bug: A crash, i.e., an abnormal termination of software assertion failure Bug → crash: An assertion failure swift 6.0 default arguments Feature: default arguments for value parameters statements Feature: statements labels Jan 19, 2024
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 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 default arguments Feature: default arguments for value parameters SILGen Area → compiler: The SIL generation stage statements Feature: statements swift 6.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants