Skip to content

Compiler error with simple TextOutputStream #65213

@WolterSmit

Description

@WolterSmit

When compiling this program, the compiler quits with a bug report. The problem is in assigning TextPrinter to the variable. That will cause the error

import Darwin.C

@main
public struct p1test {
    public private(set) var text = "Hello, World!"

    public static func main() {
        
        var output : TextOutputStream

        output =  TextPrinter()

        print(p1test().text, to: &output)
    }
}

public struct TextPrinter: TextOutputStream {
    public mutating func write(_ string: String) {
        print(string)
    }
}

It will generate this stack trace:

Building for debugging...
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/wolters/Documents/dev/p1test/Sources/p1test/p1test.swift -emit-dependencies-path /Users/wolters/Documents/dev/p1test/.build/x86_64-apple-macosx/debug/p1test.build/p1test.d -emit-reference-dependencies-path /Users/wolters/Documents/dev/p1test/.build/x86_64-apple-macosx/debug/p1test.build/p1test.swiftdeps -target x86_64-apple-macosx10.13 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -I /Users/wolters/Documents/dev/p1test/.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/wolters/Documents/dev/p1test/.build/x86_64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -entry-point-function-name p1test_main -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -module-name p1test -disable-clang-spi -target-sdk-version 13.0 -parse-as-library -o /Users/wolters/Documents/dev/p1test/.build/x86_64-apple-macosx/debug/p1test.build/p1test.swift.o -index-store-path /Users/wolters/Documents/dev/p1test/.build/x86_64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "/Users/wolters/Documents/dev/p1test/Sources/p1test/p1test.swift")
4.	While emitting IR SIL function "@$s6p1testAAV4mainyyFZ".
 for 'main()' (at /Users/wolters/Documents/dev/p1test/Sources/p1test/p1test.swift:7:12)
    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           0x000000010ffbcff7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x000000010ffbc028 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x000000010ffbd610 SignalHandler(int) + 288
3  libsystem_platform.dylib 0x00007ff80258bc1d _sigtramp + 29
4  swift-frontend           0x000000010ac49440 swift::ProtocolConformanceRef llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>::callback_fn<swift::LookUpConformanceInSignature>(long, swift::CanType, swift::Type, swift::ProtocolDecl*) + 0
5  swift-frontend           0x000000010b044594 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 340
6  swift-frontend           0x000000010af72100 swift::irgen::emitGenericRequirementFromSubstitutions(swift::irgen::IRGenFunction&, swift::CanGenericSignature, swift::irgen::GenericRequirement, swift::SubstitutionMap) + 272
7  swift-frontend           0x000000010af77f03 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::SubstitutionMap, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_22>(long, swift::irgen::GenericRequirement) + 35
8  swift-frontend           0x000000010af78029 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::enumerateUnfulfilledRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&)::$_12>(long, swift::irgen::GenericRequirement) + 233
9  swift-frontend           0x000000010c01e2e2 swift::GenericSignatureImpl::forEachParam(llvm::function_ref<void (swift::GenericTypeParamType*, bool)>) const + 706
10 swift-frontend           0x000000010af69b79 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 57
11 swift-frontend           0x000000010af714b5 swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 421
12 swift-frontend           0x000000010b01a60d (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 4397
13 swift-frontend           0x000000010aff4552 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 10706
14 swift-frontend           0x000000010ae9b647 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) + 1623
15 swift-frontend           0x000000010afc0d10 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 10272
16 swift-frontend           0x000000010aff185c swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 204
17 swift-frontend           0x000000010afcbbb0 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 832
18 swift-frontend           0x000000010afc543c swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 348
19 swift-frontend           0x000000010ab733ab performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2539
20 swift-frontend           0x000000010ab75105 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5701
21 swift-frontend           0x000000010ab0b02a swift::mainEntry(int, char const**) + 3082
22 dyld                     0x00007ff80222e310 start + 2432

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILGenArea → compiler: The SIL generation stagebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.call expressionsFeature → expressions: Call expressionscompilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwaredefault argumentsFeature: default arguments for value parametersexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesfunction parametersFeature → declarations: function parametersgenericsFeature: generic declarations and typesimplicit existential openingFeature → existentials: implicit opening of existentials when passed to parameters of generic typeinoutFeature → types: `inout` typesswift 5.9variadic parametersFeature → declarations → function parameters: Variadic function parameters

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions