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-15261] Build crash using try? after custom infix operator in result builder #57583

Open
swift-ci opened this issue Sep 29, 2021 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-15261
Radar None
Original Reporter TofuGarden (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 48e146170aff49e171450d7347d730c5

Issue Description:

I made a result builder that turns key-value pairs into a dictionary. I'm getting a compiler exception when I build a test that uses that result builder in combination with a custom infix operator and a `try?` statement. Not an error message, just a long cryptic stack trace that is not my code. It's at the end of the description.

The Culprit:

The result builder works on the closure if I remove this line:

"number" => try? Int(bytes: [0, 0, 0])

Forcing using `try!` and wrapping as `(try? Int(bytes: [0, 0, 0]))!` also works.

Context

The => Operator

This is an operator that turns a String and TopLevelCodableValue into a DocumentKeyValuePair. These are custom types, you can find more in the project attached.

infix operator => : AssignmentPrecedence

extension String {
    public static func => (
        key: String, 
        value: TopLevelCodableValue
    ) -> DocumentKeyValuePair {
        DocumentKeyValuePair(key: key, value: value)
    }
}

This builds and works just fine in other result builder tests.

The Initializer

This initializer has the following signature:

init(bytes: [UInt8]) throws

It is used to initialize a value from a byte array.

The try? Result

Both Int and Optional<Int> conform to TopLevelCodableValue, so should build normally.

The Error

Assertion failed: (!concreteBuffer && "concrete buffer already formed?!"), function getAddressForInPlaceInitialization, file SILGenConvert.cpp, line 558.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.      Program arguments: /Users/crichez/Library/Developer/Toolchains/swift-5.5-RELEASE.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/crichez/Documents/BSONKit/Tests/DocumentBuilderTests/DocumentBuilderTests.swift -emit-module-path /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug/DocumentBuilderTests.build/DocumentBuilderTests~partial.swiftmodule -emit-module-doc-path /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug/DocumentBuilderTests.build/DocumentBuilderTests~partial.swiftdoc -emit-module-source-info-path /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug/DocumentBuilderTests.build/DocumentBuilderTests~partial.swiftsourceinfo -emit-dependencies-path /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug/DocumentBuilderTests.build/DocumentBuilderTests.d -emit-reference-dependencies-path /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug/DocumentBuilderTests.build/DocumentBuilderTests.swiftdeps -target x86_64-apple-macosx11.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -I /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -module-cache-path /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Users/crichez/Library/Developer/Toolchains/swift-5.5-RELEASE.xctoolchain/usr/bin/swift-driver -resource-dir /Users/crichez/Library/Developer/Toolchains/swift-5.5-RELEASE.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -module-name DocumentBuilderTests -target-sdk-version 11.3.0 -parse-as-library -o /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug/DocumentBuilderTests.build/DocumentBuilderTests.swift.o -index-store-path /Users/crichez/Documents/BSONKit/.build/x86_64-apple-macosx/debug/index/store -index-system-modules
1.      Apple Swift version 5.5 (swift-5.5-RELEASE)
2.
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/crichez/Documents/BSONKit/Tests/DocumentBuilderTests/DocumentBuilderTests.swift")
4.      While silgen emitFunction SIL function "@$s20DocumentBuilderTestsAAC15testCompositionyyKF".
 for 'testComposition()' (at /Users/crichez/Documents/BSONKit/Tests/DocumentBuilderTests/DocumentBuilderTests.swift:79:5)
5.      While silgen closureexpr SIL function "@$s20DocumentBuilderTestsAAC15testCompositionyyKFSay0aB00A12KeyValuePairVGycfU_".
 for expression at [/Users/crichez/Documents/BSONKit/Tests/DocumentBuilderTests/DocumentBuilderTests.swift:80:33 - line:89:9] RangeText="{
            "firstValue" => 12
            "number" => try? Int(bytes: [0, 0, 0])
            for i in 1 ... 5 {
                String(describing: i) => i * 2
            }
            for i in 6 ... 10 {
                String(describing: i) => i * 3
            }
        "
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           0x0000000106fcf037 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x0000000106fce255 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x0000000106fcf666 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007fff2041bd7d _sigtramp + 29
4  swift-frontend           0x000000010394b6c6 llvm::Optional<swift::Type> llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>::callback_fn<substType(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions)::$_26>(long, swift::TypeBase*) + 1334
5  libsystem_c.dylib        0x00007fff2032b406 abort + 125
6  libsystem_c.dylib        0x00007fff2032a7d8 err + 0
7  swift-frontend           0x00000001071e08d3 (anonymous namespace)::ExistentialInitialization::getAddressForInPlaceInitialization(swift::Lowering::SILGenFunction&, swift::SILLocation) (.cold.8) + 35
8  swift-frontend           0x0000000102d3731e (anonymous namespace)::ExistentialInitialization::getAddressForInPlaceInitialization(swift::Lowering::SILGenFunction&, swift::SILLocation) + 958
9  swift-frontend           0x0000000102d58546 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 28070
10 swift-frontend           0x0000000102d48667 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 55
11 swift-frontend           0x0000000102d6063c swift::Lowering::ManagedValue llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>::callback_fn<(anonymous namespace)::RValueEmitter::visitErasureExpr(swift::ErasureExpr*, swift::Lowering::SGFContext)::$_9>(long, swift::Lowering::SGFContext) + 76
12 swift-frontend           0x0000000102d374db void llvm::function_ref<void (swift::SILValue)>::callback_fn<swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool)::$_6>(long, swift::SILValue) + 139
13 swift-frontend           0x0000000102d1dc98 swift::Lowering::SILGenBuilder::bufferForExpr(swift::SILLocation, swift::SILType, swift::Lowering::TypeLowering const&, swift::Lowering::SGFContext, llvm::function_ref<void (swift::SILValue)>) + 184
14 swift-frontend           0x0000000102d33471 swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool) + 1281
15 swift-frontend           0x0000000102d56a54 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 21172
16 swift-frontend           0x0000000102d48667 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 55
17 swift-frontend           0x0000000102d05f52 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3090
18 swift-frontend           0x0000000102cf357b (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 667
19 swift-frontend           0x0000000102d04eef (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 143
20 swift-frontend           0x0000000102d0e69e (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::Lowering::CalleeTypeInfo::ForeignInfo const&) && + 910
21 swift-frontend           0x0000000102d0de5d (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::Lowering::CalleeTypeInfo::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 1549
22 swift-frontend           0x0000000102cf7945 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2677
23 swift-frontend           0x0000000102cf53a6 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2006
24 swift-frontend           0x0000000102d51815 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 117
25 swift-frontend           0x0000000102d48667 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 55
26 swift-frontend           0x0000000102d05f52 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3090
27 swift-frontend           0x0000000102cf357b (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 667
28 swift-frontend           0x0000000102d04eef (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 143
29 swift-frontend           0x0000000102d0e69e (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::Lowering::CalleeTypeInfo::ForeignInfo const&) && + 910
30 swift-frontend           0x0000000102d0de5d (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::Lowering::CalleeTypeInfo::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 1549
31 swift-frontend           0x0000000102cf7945 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2677
32 swift-frontend           0x0000000102cf53a6 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2006
33 swift-frontend           0x0000000102d51815 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 117
34 swift-frontend           0x0000000102d45f12 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 258
35 swift-frontend           0x0000000102d392a2 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 1842
36 swift-frontend           0x0000000102d394cd swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 45
37 swift-frontend           0x0000000102db3e37 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 455
38 swift-frontend           0x0000000102db3c65 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
39 swift-frontend           0x0000000102d6859a swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 410
40 swift-frontend           0x0000000102ce3fc2 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 1746
41 swift-frontend           0x0000000102ce7464 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 116
42 swift-frontend           0x0000000102d5e23c (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 124
43 swift-frontend           0x0000000102d51851 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 177
44 swift-frontend           0x0000000102d48667 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 55
45 swift-frontend           0x0000000102d05afc (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1980
46 swift-frontend           0x0000000102cf357b (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 667
47 swift-frontend           0x0000000102d04eef (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 143
48 swift-frontend           0x0000000102d0e69e (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::Lowering::CalleeTypeInfo::ForeignInfo const&) && + 910
49 swift-frontend           0x0000000102d0de5d (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::Lowering::CalleeTypeInfo::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 1549
50 swift-frontend           0x0000000102cf7945 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2677
51 swift-frontend           0x0000000102cf53a6 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2006
52 swift-frontend           0x0000000102d51815 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 117
53 swift-frontend           0x0000000102d45f12 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 258
54 swift-frontend           0x0000000102d392a2 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 1842
55 swift-frontend           0x0000000102d394cd swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 45
56 swift-frontend           0x0000000102db3e37 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 455
57 swift-frontend           0x0000000102db3c65 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
58 swift-frontend           0x0000000102d677d9 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 457
59 swift-frontend           0x0000000102ce53c9 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6873
60 swift-frontend           0x0000000102ce71c0 emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef, bool) + 400
61 swift-frontend           0x0000000102ce38da swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 122
62 swift-frontend           0x0000000102dc52a2 swift::ASTVisitor<(anonymous namespace)::SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 434
63 swift-frontend           0x0000000102dc23ec (anonymous namespace)::SILGenType::emitType() + 124
64 swift-frontend           0x0000000102dc2369 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
65 swift-frontend           0x0000000102ce9677 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1975
66 swift-frontend           0x0000000102db37b6 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
67 swift-frontend           0x0000000102ced81d llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 413
68 swift-frontend           0x0000000102cea844 swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&) + 116
69 swift-frontend           0x00000001026d6e12 performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 226
70 swift-frontend           0x00000001026cb972 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4850
71 swift-frontend           0x000000010261e922 main + 546
72 libdyld.dylib            0x00007fff203f1f3d start + 1
The terminal process "swift 'build', '--build-tests', '--toolchain', '/Users/crichez/Library/Developer/Toolchains/swift-5.5-RELEASE.xctoolchain'" terminated with exit code: 1.
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

1 participant