swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-12204] "Remangling failed" on Linux 5.1 and 5.2 #54630

Closed tachyonics closed 4 years ago

tachyonics commented 4 years ago
Previous ID SR-12204
Radar rdar://problem/59496022
Original Reporter @tachyonics
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment The following docker images can reproduce this bug- swift:5.1.4-bionic: bug reproduced swift:5.1.4-xenial: bug reproduced swift:5.0.3-bionic: bug doesn't occur swift:5.0.3-xenial: bug doesn't occur swiftlang/swift:nightly-master-xenial: bug reproduced swiftlang/swift:nightly-5.2-xenial: bug reproduced
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 144d64d07e4f10ebf45d3458ebd0933a

Issue Description:

This bug can be replicated using a development branch of the SmokeFramework package-

https://github.com/amzn/smoke-framework/tree/request_tracing

Specially when this line is added-

https://github.com/amzn/smoke-framework/blob/request_tracing/Sources/SmokeOperationsHTTP1/SmokeHTTP1Server%2BstartAsOperationServer.swift#L42-L47

An example of the compile failure is here-

https://travis-ci.com/amzn/smoke-framework/jobs/287439552#L493

beccadax commented 4 years ago

@swift-ci create

eeckstein commented 4 years ago

@tachyonics I could not reproduce the issue.
Which toolchain version did you use?

tachyonics commented 4 years ago

I was able to reproduce the issue using the 5.1.4-bionic and 5.1.4-xenial docker images plus nightly-5.2-xenial and nightly-master-xenial docker images.

5.1.4-bionic: https://travis-ci.com/amzn/smoke-framework/jobs/287439552

5.1.4-xenial: https://travis-ci.com/amzn/smoke-framework/jobs/287439553

nightly-5.2-xenial: https://travis-ci.com/amzn/smoke-framework/jobs/287439558

nightly-master-xenial: https://travis-ci.com/amzn/smoke-framework/jobs/287439556

I didn't encounter the issue when compiling on the mac.

eeckstein commented 4 years ago

Interesting.
I tried with a top-of-master compiler and could not reproduce it.
How did you build? Debug or release configuration?

tachyonics commented 4 years ago

Looks like it is only reproducible in Debug configuration.

gwynne commented 4 years ago

I just hit this with the 5.2-RELEASE compiler. This snippet is sufficient to reproduce the crash by itself:

extension Optional: Comparable where Wrapped: Comparable {
    public static func v(in r: ClosedRange<Self>) {}
    public static func < (lhs: Self, rhs: Self) -> Bool { false }
}
Remangling failed:
original     = $sSNyxSgxSgSL13remangle_failxSLHD1__HCg_GD
remangled    = $sSNyxSgAASL13remangle_failxSLHD1__HCg_GD
Stack dump:
0.  Program arguments: /usr/bin/swift -frontend -c -primary-file /remangle-fail/Sources/remangle-fail/main.swift -emit-module-path /remangle-fail/.build/x86_64-unknown-linux-gnu/debug/remangle_fail.build/main~partial.swiftmodule -emit-module-doc-path /remangle-fail/.build/x86_64-unknown-linux-gnu/debug/remangle_fail.build/main~partial.swiftdoc -emit-module-source-info-path /remangle-fail/.build/x86_64-unknown-linux-gnu/debug/remangle_fail.build/main~partial.swiftsourceinfo -emit-dependencies-path /remangle-fail/.build/x86_64-unknown-linux-gnu/debug/remangle_fail.build/main.d -emit-reference-dependencies-path /remangle-fail/.build/x86_64-unknown-linux-gnu/debug/remangle_fail.build/main.swiftdeps -target x86_64-unknown-linux-gnu -disable-objc-interop -I /remangle-fail/.build/x86_64-unknown-linux-gnu/debug -color-diagnostics -enable-testing -g -module-cache-path /remangle-fail/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-anonymous-context-mangled-names -module-name remangle_fail -o /remangle-fail/.build/x86_64-unknown-linux-gnu/debug/remangle_fail.build/main.swift.o -index-store-path /remangle-fail/.build/x86_64-unknown-linux-gnu/debug/index/store -index-system-modules
1.  Swift version 5.2 (swift-5.2-RELEASE)
2.  While emitting IR SIL function "@$sSq13remangle_failSLRzlE1v2inySNyxSgADSLAAxSLHD1__HCg_G_tFZ".
 for 'v(in:)' (at /remangle-fail/Sources/remangle-fail/main.swift:2:12)
3.  While mangling type for debugger type 'ClosedRange<Optional<Wrapped>>'

Confirmed it only shows up in Debug builds on Linux. Will also attach repro as test project in package form momentarily.

slavapestov commented 4 years ago

The bug might only show up on Linux if there's something about debug info that gets emitted differently on the two platforms. The mangled name here is coming from debug info emission.

It appears that in the original ASTMangler output, we have two occurrences of xSg. In the remangled version, the second one becomes a substitution AA. So I think the bug is that ASTMangler does not record a substitution in some case, but the remangler does. Unless this only comes up with the DWARF mangling, we have to say that the ASTMangler is "correct", since changing it will break the ABI. So we should change the remangler to not record a substitution here. It's important that the ASTMangler and remangler produce identical output.

slavapestov commented 4 years ago

https://github.com/apple/swift/pull/30840