Skip to content

[SR-9108] GSB drops requirements when processing superclass constrained type #51605

@swift-ci

Description

@swift-ci
Previous ID SR-9108
Radar rdar://44736411
Original Reporter carlos4242 (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

Mac Pro 2013, running macOS 10.13.6.

The swift compiler is the pre-built one from Xcode 10. I will attempt to build swift 4.2 from scratch and confirm that the issue still exists there, that it is not an "Apple" created issue.

It would be really good if someone can confirm if this is a bug in swift 4.2 compiled on a linux box.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, CompilerCrash, OptimizedOnly
Assignee @slavapestov
Priority Medium

md5: ebc0bd91af09edfda7c3156aa2734372

Issue Description:

A regression seems to have appeared in the optimisation pipeline for SIL.

I've got it down to a fairly minimal case...

protocol SimpleProto: class {
    init(simpleValue: Int)
}

class BaseClass {
    let baseValue: String

    required init(baseValue: String) {
        self.baseValue = baseValue
        print(baseValue)
    }
}

extension SimpleProto where Self: BaseClass {
    init(simpleValue: Int) {
        self.init(baseValue: "***")
    }
}

class AdjustedClass: BaseClass, SimpleProto {
//    required init(simpleValue: Int) {
//        super.init(baseValue: "---")
//    }

    required init(baseValue: String) {
        super.init(baseValue: baseValue)
    }
}

print("initialising...")
let viceControlType: SimpleProto.Type = AdjustedClass.self
let control = viceControlType.init(simpleValue: 901)
print("done \(control)")

Compiled with optimisation turned on, this will crash the compile in Xcode 10 [Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)].

e.g.
...Xcode\ 10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -O crashOptimiser.swift

swift                    0x000000010be5a64a PrintStackTraceSignalHandler(void*) + 420  
swift                    0x000000010be5a64a PrintStackTraceSignalHandler(void*) + 421  
swift                    0x000000010be59dfe SignalHandler(int) + 3022  libsystem_platform.dylib 0x00007fff5b93ff5a _sigtramp + 263  libsystem_platform.dylib 0x00007ffee7b9f580 _sigtramp + 23512981124  
swift                    0x0000000108fd32b0 (anonymous namespace)::SILTypeSubstituter::substSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>) + 14085  
swift                    0x0000000108c11417 swift::tryDevirtualizeApply(swift::ApplySite, swift::ClassHierarchyAnalysis*, swift::OptRemark::Emitter*) + 35756  
swift                    0x0000000108da4623 (anonymous namespace)::Devirtualizer::run() + 7397  
swift                    0x0000000108ccb0c9 swift::SILPassManager::execute() + 39778  
swift                    0x00000001080edd32 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 477309  
swift                    0x00000001080dedc5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 771710 
swift                    0x0000000108084a35 main + 134911 libdyld.dylib            0x00007fff5b631015 start + 1
Stack dump:
0. Program arguments: .../Xcode 10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file crashOptimiser.swift -target x86_64-apple-darwin17.7.0 -enable-objc-interop -O -color-diagnostics -module-name crashOptimiser -o /var/folders/wm/dg7pjp_93gz6y8lgphhwklfjkjnwyt/T/crashOptimiser-a447ff.o
1. While running pass #&#8203;3477 SILFunctionTransform "Devirtualizer" on SILFunction "@main".
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)

If the initialiser is uncommented in AdjustedClass, it compiles fine.

With optimisations turned off it compiles and runs fine:

...Xcode\ 10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc crashOptimiser.swift

This produces a working, simple program.

Also, I've tested the above command using the Xcode 9.4 version of swift [Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)]

With that version, no crash is seen, even if optimisations are turned on, and even if the first initialiser in AdjustedClass is commented out, and the program runs fine and behaves as you would expect (the initialiser in the protocol extension is called).

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareoptimized onlyFlag: An issue whose reproduction requires optimized compilationregressionswift 4.2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions