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

Crash while evaluating ASTLoweringRequest, maybe SE-0307 CGFloat vs Double issue? #73441

Open
gregomni opened this issue May 4, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@gregomni
Copy link
Collaborator

gregomni commented May 4, 2024

Description

Compiler crash with this reduced code. If you explicitly declare epsilon: CGFloat then it compiles successfully.

Reproduction

import Foundation

extension ArraySlice {
    func first<T: Comparable>(sortedBy: (Element) -> T, value: T) -> Self.Index {
        return startIndex
    }
}

class Graphic {}

func within(limit: CGFloat, in array: ArraySlice<Graphic>) {
    let epsilon = 0.0001
    let accessor: (Graphic) -> CGFloat = { _ in 0 }
    _ = array.first(sortedBy: accessor, value: limit + epsilon)
}

put into a file main.swift, run swiftc main.swift

Stack dump

error: compile command failed due to signal 5 (use -v to see invocation)
  %2 = apply %1(%0) : $@callee_guaranteed (@guaranteed Graphic) -> CGFloat
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file main.swift -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -color-diagnostics -new-driver-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name main -disable-clang-spi -target-sdk-version 14.5 -target-sdk-name macosx14.5 -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/xy/vjlqwbw546s___dc0g7d3c980000gn/T/TemporaryDirectory.Uw7QSN/main-1.o
1.	Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "main.swift")
4.	While silgen emitFunction SIL function "@$s4main6within5limit2iny12CoreGraphics7CGFloatV_s10ArraySliceVyAA7GraphicCGtF".
 for 'within(limit:in:)' (at main.swift:18:1)
5.	While emitting reabstraction thunk in SIL function "@$s4main7GraphicC12CoreGraphics7CGFloatVIeggd_ACSdIeggd_TR".
 for <<debugloc at "<compiler-generated>":0:0>>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           0x000000010804bf3c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010804b0f8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010804c544 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x000000018e1f3584 _sigtramp + 56
4  swift-frontend           0x000000010305ba80 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 6976
5  swift-frontend           0x0000000103071878 (anonymous namespace)::ResultPlanner::execute(llvm::SmallVectorImpl<swift::SILValue>&, llvm::SmallVectorImpl<swift::SILValue>&)::$_24::operator()((anonymous namespace)::ResultPlanner::Operation&, bool, bool) const + 516
6  swift-frontend           0x000000010305ecec (anonymous namespace)::ResultPlanner::execute(swift::SILValue, swift::CanTypeWrapper<swift::SILFunctionType>) + 1060
7  swift-frontend           0x0000000103064978 buildThunkBody(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::CanType) + 1632
8  swift-frontend           0x0000000103063ffc createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 3484
9  swift-frontend           0x000000010305a51c (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1500
10 swift-frontend           0x0000000103059f20 swift::Lowering::SILGenFunction::emitTransformedValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::CanType, swift::CanType, swift::Lowering::SGFContext) + 344
11 swift-frontend           0x0000000102fff098 (anonymous namespace)::RValueEmitter::visitFunctionConversionExpr(swift::FunctionConversionExpr*, swift::Lowering::SGFContext) + 4972
12 swift-frontend           0x0000000102fe6f2c swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
13 swift-frontend           0x0000000102fc80e0 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 256
14 swift-frontend           0x0000000102f51594 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 136
15 swift-frontend           0x0000000102f8ab40 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 4488
16 swift-frontend           0x0000000102f78eb8 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, llvm::Optional<swift::AnyFunctionType::Param>) + 224
17 swift-frontend           0x0000000102f896a0 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 260
18 swift-frontend           0x0000000102f95fb4 (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::ForeignInfo const&) && + 672
19 swift-frontend           0x0000000102f959cc (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 1000
20 swift-frontend           0x0000000102f7dd68 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 4064
21 swift-frontend           0x0000000102f7b7bc swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3060
22 swift-frontend           0x0000000102fe7618 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 892
23 swift-frontend           0x0000000103006e44 (anonymous namespace)::RValueEmitter::visitAssignExpr(swift::AssignExpr*, swift::Lowering::SGFContext) + 568
24 swift-frontend           0x0000000102fe7618 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 892
25 swift-frontend           0x000000010307f684 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5032
26 swift-frontend           0x0000000103016538 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 632
27 swift-frontend           0x0000000102f6ae48 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 8344
28 swift-frontend           0x0000000102f6b5bc swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 172
29 swift-frontend           0x0000000102f68d9c swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 292
30 swift-frontend           0x0000000102f6eb54 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1668
31 swift-frontend           0x000000010307df1c 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&) + 196
32 swift-frontend           0x0000000102f71f44 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 584
33 swift-frontend           0x0000000102949408 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 548
34 swift-frontend           0x000000010294d694 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1448
35 swift-frontend           0x000000010294b6d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4968
36 swift-frontend           0x00000001028dae8c swift::mainEntry(int, char const**) + 2612
37 dyld                     0x000000018de3a0e0 start + 2360
error: fatalError

Expected behavior

Compiles!

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@gregomni gregomni added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels May 4, 2024
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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant