[SR-7879] UIEdgeInsets.zero use crashes Xcode 10/Swift 4.2 compiler Created: 5 Jun 2018  Updated: 29 Jun 2018  Resolved: 22 Jun 2018

Status: Resolved
Project: Swift
Component/s: Compiler

Type: Bug Priority: Medium
Reporter: Dave Reed Assignee: Jordan Rose
Resolution: Done Votes: 10
Labels: Serialization
Environment:

macOS 10.14 and Xcode 10 initial betas


Issue Links:
Duplicate
is duplicated by SR-7892 Swift compiler crashes with `error: A... Resolved
is duplicated by SR-7893 Compiler error when building for Swif... Resolved
is duplicated by SR-7966 Migrating issues Resolved
is duplicated by SR-8062 error: fatal error encountered while ... Resolved
is duplicated by SR-7947 Xcode 10: Trap 6 in Merge swiftmodule Closed
Relates
relates to SR-8149 NSPasteboard.PasteboardType.findPanel... Open
Radar URL: rdar://problem/40735990

 Description   

UIEdgeInsets.zero crashes compiler. Replacing that with UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) allows the code to compile.



 Comments   
Comment by Matt Neuburg [ 5 Jun 2018 ]

Alternatively, replace it with UIEdgeInsets().

.zero is still documented, so the need to make this change seems like a bug.

The crash reads in part:

MergeSwiftModule normal x86_64

*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
result is ambiguous
0  swift                    0x0000000109540c5a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000109540066 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff7e535f5a _sigtramp + 26
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 2175574208
4  libsystem_c.dylib        0x00007fff7e2d31ae abort + 127
5  swift                    0x00000001069e699b swift::ModuleFile::fatal(llvm::Error) + 1915
6  swift                    0x0000000106a1e4d2 swift::SILDeserializer::readGlobalVar(llvm::StringRef) + 1890
7  swift                    0x0000000106ac8f9a swift::SerializedSILLoader::getAllForModule(swift::Identifier, swift::FileUnit*) + 234
8  swift                    0x000000010581bdbe performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 34750
9  swift                    0x000000010581010f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7839
10 swift                    0x00000001057b9c48 main + 13144
11 libdyld.dylib            0x00007fff7e227015 start + 1

1.	While deserializing SIL global "UIEdgeInsetsZero"
error: Abort trap: 6
Comment by Jordan Rose [ 5 Jun 2018 ]

Thanks, Dave and Matt!

Comment by Bobby Ren [ 5 Jun 2018 ]

I worked with Max at WWDC and we were able to reproduce this with a fresh project created in Xcode 10.

 

<unknown>:0: error: fatal error encountered while reading from module 'Test2'; please file a bug report with your project and the crash log



*** DESERIALIZATION FAILURE (please include this section in any bug report) ***

result is ambiguous

0  swift                    0x000000010867ac5a PrintStackTraceSignalHandler(void*) + 42

1  swift                    0x000000010867a066 SignalHandler(int) + 966

2  libsystem_platform.dylib 0x00007fff7ea4ef5a _sigtramp + 26

3  libsystem_platform.dylib 000000000000000000 _sigtramp + 2170228928

4  libsystem_c.dylib        0x00007fff7e7ec1ae abort + 127

5  swift                    0x0000000105b2099b swift::ModuleFile::fatal(llvm::Error) + 1915

6  swift                    0x0000000105b584d2 swift::SILDeserializer::readGlobalVar(llvm::StringRef) + 1890

7  swift                    0x0000000105c02f9a swift::SerializedSILLoader::getAllForModule(swift::Identifier, swift::FileUnit*) + 234

8  swift                    0x0000000104955dbe performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 34750

9  swift                    0x000000010494a10f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7839

10 swift                    0x00000001048f3c48 main + 13144

11 libdyld.dylib            0x00007fff7e740015 start + 1

12 libdyld.dylib            0x0000000000000040 start + 2173435948

Stack dump:

0.	Program arguments: /Users/bren200/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -merge-modules -emit-module /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Objects-normal/x86_64/ViewController~partial.swiftmodule /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Objects-normal/x86_64/AppDelegate~partial.swiftmodule -parse-as-library -sil-merge-partial-modules -disable-diagnostic-passes -disable-sil-perf-optzns -target x86_64-apple-ios12.0-simulator -enable-objc-interop -sdk /Users/bren200/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.0.sdk -I /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Products/Debug-iphonesimulator -F /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/bren200/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 4.2 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/bren200/Desktop/Projects/Test2 -Xcc -I/Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Test2-generated-files.hmap -Xcc -I/Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Test2-own-target-headers.hmap -Xcc -I/Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Test2-all-target-headers.hmap -Xcc -iquote -Xcc /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Test2-project-headers.hmap -Xcc -I/Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/DerivedSources/x86_64 -Xcc -I/Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Objects-normal/x86_64/Test2.swiftdoc -emit-objc-header-path /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Objects-normal/x86_64/Test2-Swift.h -module-name Test2 -o /Users/bren200/Library/Developer/Xcode/DerivedData/Test2-azqhapnmgemxarbrndxkhgtjvvij/Build/Intermediates.noindex/Test2.build/Debug-iphonesimulator/Test2.build/Objects-normal/x86_64/Test2.swiftmodule

1.	While deserializing SIL global "UIEdgeInsetsZero"

error: Abort trap: 6
Comment by Jordan Rose [ 6 Jun 2018 ]

The workaround right now is what Dave put in the original report: don't use UIEdgeInsets.zero.

Comment by Anisov Aleksey [ 6 Jun 2018 ]

Hi, Jordan Rose

I don't know why it doesn't work for me, still have a crash. Maybe dependencies influence it?

Comment by Jordan Rose [ 6 Jun 2018 ]

And the crash still says "UIEdgeInsetsZero" at the end? Hm. I don't have any other suggestions without being able to see your code. (I know that if it were my code, though, I would have missed a .zero somewhere.)

Comment by Matt Neuburg [ 6 Jun 2018 ]

Jordan Rose In my case that's exactly what happened in another project: I got the crash, it said UIEdgeInsetsZero, I searched on zero and found it, I fixed it. Gotta say, what a great crash log! Tells you just what to do. Makes me happy.

Comment by Anisov Aleksey [ 6 Jun 2018 ]

Jordan Rose I have found the code

contentInset = .zero

  now all works, sorry

Comment by Nick Lockwood [ 7 Jun 2018 ]

FYI, here the workaround I'm using (avoids hunting around for all the usage sites in your app):

#if swift(>=4.2)
    // Workaround for https://bugs.swift.org/browse/SR-7879 
    extension UIEdgeInsets {
        static let zero = UIEdgeInsets()
    }
#endif
Comment by Keith Smiley [ 8 Jun 2018 ]

This also appears to be an issue with UIOffset, I assume it's related.

Comment by Slava Pestov [ 9 Jun 2018 ]

There are two declarations named ‘zero’ in UIEdgeInsets. One is an imported global variable, renamed to a member via API notes. The other is defined in the UIKit overlay, as a computed property in Swift. The serialization xref does not encode enough information to distinguish the two.

Comment by Slava Pestov [ 9 Jun 2018 ]

This part of filterValues() doesn’t make sense — why are we ignoring the module filter if the declaration was imported? If I remove this part, we no longer crash with this .zero thing:

     // FIXME: Should be able to move a value from an extension in a derived
     // module to the original definition in a base module.
     if (expectedModule && !value->hasClangNode() &&
Comment by tyeen [ 9 Jun 2018 ]

Just an additional information, I've encountered the same error, and if I switched to "Whole Module" in "Compilation Mode", the building could pass successfully.

Comment by Jordan Rose [ 10 Jun 2018 ]

@Slava: Removing that would be an incorrect fix since we really do want the one from UIKit proper, and not the overlay. There's a whole pile of badness here, really, but as far as a fix for Swift 4.2 goes I have a hack that I've already run by Doug and Max. I do want to check in with the UIKit folks before I land it, though.

Comment by Jordan Rose [ 11 Jun 2018 ]

tyeen: Yep, in most cases that will avoid the bug, but not all. (Inlinable code that references UIEdgeInsets.zero is the other major cause.)

Comment by Jordan Rose [ 11 Jun 2018 ]

Hack, as promised: https://github.com/apple/swift/pull/17122

Generated at Tue Oct 16 14:35:22 CDT 2018 using Jira 7.11.1#711001-sha1:ea73d62a147b9e78feacb774553e1635dfb20b0b.