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-6522] Compiler crash in Debug depending on order of files in PBXSourcesBuildPhase #49072

Closed
jepers opened this issue Dec 3, 2017 · 13 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@jepers
Copy link

jepers commented Dec 3, 2017

Previous ID SR-6522
Radar rdar://problem/35830641
Original Reporter @jepers
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

Xcode Version 9.1 (9B55)
Swift Development Snapshot 2017-11-28 (a)

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

md5: f1bd1e78ffb71eaad78a87030d123832

Issue Description:

The following is from the README in the attached Xcode-project:

-----------------------------------------------------------------------------

The purpose of this Xcode project is to demonstrate a compiler crash that
happens when this project (in its original state) is compiled with
Xcode Version 9.1 (9B55) using Swift Development Snapshot 2017-11-28 (a).

*** NOTE *** Using eg the default toolchain of Xcode 9.1 will result in
*other* *unrelated* errors or crashes (because the code in this project
depends on Swift-features that are only fully/enough implemented in
recent snapshots.)


-----------------------------------------------------------------------------
Description
-----------------------------------------------------------------------------

This project crashes the compiler in Debug but compiles in Release.

Changing the order of the files in the PBXSourcesBuildPhase section of
project.pbxproj turns out to be a (surprising/interesting) workaround.

(
While trying to isolate the crash-only-in-Debug-issue I noticed that the
issue would *sometimes* go away when creating a new project with identical
source code. Long story short: I gave up my investigation after concluding
that the order of the list of source files in the PBXSourcesBuildPhase-section
of project.pbxproj can make the compiler succeed or crash (in Debug).
)

So to help reproducing the issue, this project includes these two files:

failing.txt - This is identical to the (original) project.pbxproj

working.txt - This has a reordered list of source files in PBXSourcesBuildPhase

Replacing this project's project.pbxproj with working.txt will make the
issue go away (ie the prj will compile in both Debug and Release).

Replacing this project's project.pbxproj with failing.txt will reintroduce
the issue (ie the prj will compile in Release but crash compiler in Debug).


-----------------------------------------------------------------------------
Steps to reproduce
-----------------------------------------------------------------------------

Assuming the project is in its original state, where project.pbxproj is
identical to the file in this project named "failing.txt".


1. Make sure you are using
   Xcode Version 9.1 (9B55)
   and that the toolchain you are using is
   Swift Development Snapshot 2017-11-28 (a)

2. Press cmd + B, note that it fails to compile (compiler crashes: /.../
   <unknown>:0: error: unable to execute command: Abort trap: 6
   <unknown>:0: error: merge-module command failed due to signal 6
   /.../ )

3. Switch from Debug to Release mode:
   Product -> Scheme -> Edit Scheme … -> Run -> Build Configuration -> Release

4. Press cmd + B, note that it builds successfully.

5. Switch back to debug and note that it fails to compile again.

6. cd {path-to-this-project}
   cp working.txt ResampledNoise.xcodeproj/project.pbxproj
   Note that the prj now compiles in both Debug and Release.

7. cd {path-to-this-project}
   cp failing.txt ResampledNoise.xcodeproj/project.pbxproj
   Note that the prj again crashes compiler in Debug and compiles in Release.

-----------------------------------------------------------------------------
@jepers
Copy link
Author

jepers commented Dec 3, 2017

Please let me know if you can reproduce this, since I will be able to relax a bit knowing so : )

@jepers
Copy link
Author

jepers commented Dec 3, 2017

cc @DougGregor @slavapestov @huonw (I have a feeling that this is related to recursive constraints on associated types.)

@belkadan
Copy link
Contributor

belkadan commented Dec 4, 2017

@swift-ci create

@jepers
Copy link
Author

jepers commented Dec 4, 2017

The issue persists in Development Snapshot 2017-12-03.

@jepers
Copy link
Author

jepers commented Dec 5, 2017

Perhaps I should mention that when I try to compile the source files (of the attached project) from the command line, non-incrementally, it only works without -g, ie I can get it to compile (from the command line, using a single swiftc command)
without -g and with -wmo. But as soon as I use -g and not -wmo it crashes the compiler.

Seems strange that it can be successfully compiled from within Xcode in Debug (with -g and without -wmo, although incrementally and provided the source files are listed in the "magic" order in project.pbxproj as described in the bug-report) but not using a simple swiftc command like
swiftc -g -Onone {list all source files}

I have tried to see if the magic reordering of the source files would help here too but it crashes anyway.

@belkadan
Copy link
Contributor

belkadan commented Dec 5, 2017

Crashes during SIL deserialization in the merge-modules phase, so it may not be related to recursive constraints after all.

(Jens, a reminder that @inline(__always) isn't supported. But we'd like some form of inlinable functions to be soon, so we should do something about this.)

@belkadan
Copy link
Contributor

belkadan commented Dec 5, 2017

…and yes, managed to reproduce this with a near-master compiler.

@jepers
Copy link
Author

jepers commented Dec 5, 2017

My feeling that this might be related to recursive constraints on associated types is based on the following part of the crash message:

1.  While canonicalizing generic signature <τ_0_0 where τ_0_0 : ResampableTableData, τ_0_0.Value : Vector, τ_0_0.Coordinate.Index == VectorIndex2, τ_0_0.Value.Element == Float, τ_0_0.Value.Index == VectorIndex1> in requirement #&#8203;3
2.  While reading from 'ResampledNoise'
3.  While finishing conformance for type 'Vector2<Element>'
4.  While ... to 'Vector' in module 'ResampledNoise'
5.  While deserializing decl #&#8203;5 (XREF) in 'ResampledNoise'
6.  Cross-reference to module 'ResampledNoise'
    ... Vector
    ... init
    ... with type <τ_0_0 where τ_0_0 : Vector> (τ_0_0.Type) -> ((τ_0_0.Index) -> τ_0_0.Element) -> τ_0_0
7.  While reading from 'ResampledNoise'
8.  While finishing conformance for type 'Vector1<Element>'
9.  While ... to 'Vector' in module 'ResampledNoise'
10. While deserializing decl #&#8203;5 (XREF) in 'ResampledNoise'
11. Cross-reference to module 'ResampledNoise'
    ... Vector
    ... init
    ... with type <τ_0_0 where τ_0_0 : Vector> (τ_0_0.Type) -> ((τ_0_0.Index) -> τ_0_0.Element) -> τ_0_0
12. While resolving requirement ResampledNoise.(file).Vector.Index in conformance <Element> Vector2<Element>: Vector module ResampledNoise

The VectorIndex protocol has associated types that are constrained to conform to Vector and the Index-type of those Vectors must be Self. I have reported other bugs related to this before so I figured it might be related.

Also see:
https://bugs.swift.org/browse/SR-6224 (open)
and
https://bugs.swift.org/browse/SR-6130 (marked resolved by me as the problem went away (for unknown reasons) in a later snapshot, but perhaps this (6522) can be a clue as to what happened there?)

(Regarding @inline(__always), do you mean not supported as in not future-proof? I "had to" use it because it seems to be the only way to let the compiler optimize some code (not included here) that was otherwise too slow, related conversation here: https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20171030/006530.html and optimizer-issue described in more detailed here: https://bugs.swift.org/browse/SR-6254 (open))

@belkadan
Copy link
Contributor

belkadan commented Dec 5, 2017

I mean, I responded to you there with

It doesn't count as "using private APIs", but we assume no liability if your app is miscompiled. Also, we will not feel sorry for you when we change the syntax and your code doesn't compile any more.

I didn't explicitly mention crashing the compiler, but that too.

Still, thanks for helping us track down the issues with it. There's no other way to get it to a state where we do want to support something like it.

@jepers
Copy link
Author

jepers commented Dec 5, 2017

Yes, and just to be clear: The presence of the two @inline(__always) in the attached source code (Table.swift) is AFAICS not relevant for this issue, ie they can be removed and nothing changes, the compiler will still crash in Debug, unless the source files are "magically" ordered in project.pbxproj as mentioned in the report.

I could and should have removed the @inline(__always) to avoid confusion when using the code to demonstrate this issue.

@belkadan
Copy link
Contributor

belkadan commented Dec 5, 2017

Hm, true. Surprising, then, that we're getting crashes in SIL deserialization. What are we deserializing?

(clearly we're missing a PrettyStackTrace entry here—the struct that puts those "While…" lines in the output)

@jepers
Copy link
Author

jepers commented Dec 6, 2017

Another possible piece of the puzzle:

It seems like it has something to do with the stuff in TableResampling.swift (and its connections to Vector.swift, VectorIndex.swift, and StandardVectorTypes.swift, judging by the crash message and previous encounters with similar compiler issues while working on this project):

  1. Open the attached project (in its original compiler-crashing-in-Debug state).

  2. Comment out all code from main.swift.

  3. Press Build, note that it still crashes the compiler.

  4. Comment out all code from TableResampling.swift.

  5. Press Build, note that it compiles, no crash.

And this line in the crash message:

1.  While canonicalizing generic signature <τ_0_0 where τ_0_0 : ResampableTableData, τ_0_0.Value : Vector, τ_0_0.Coordinate.Index == VectorIndex2, τ_0_0.Value.Element == Float, τ_0_0.Value.Index == VectorIndex1> in requirement #&#8203;3

must be talking about the following from TableResampling.swift:

// Resampling 2D single float data (currently using vImage):
extension ResampableTableData where
    Coordinate.Index == VectorIndex2,
    Value: Vector,
    Value.Element == Float,
    Value.Index == VectorIndex1
{
    ...

@DougGregor
Copy link
Member

Fix is here: #13454

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants