swiftlang / swift

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

[SR-10489] swift-api-digester: compare-sdk output empty (or crash) #52889

Open weissi opened 5 years ago

weissi commented 5 years ago
Previous ID SR-10489
Radar rdar://problem/52529034
Original Reporter @weissi
Type Bug

Attachment: Download

Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | @nkcsgexi | |Priority | Medium | md5: 482a52ceef0180a99f00c791af912258

Issue Description:

I've got swift-api-digester -diagnose-sdk to work which is really awesome but it lists only the API breakages which obvs is the most important thing.

I thought -compare-sdk would maybe also list all the differences (ie. added functionality) but no luck there.

For example diagnose-sdk works between NIO 1.13.2 and NIO 1.14.0 (where we had an accidental API breakage):

$ xcrun ../build//Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-api-digester -diagnose-sdk --input-paths nio-1.13.2.json -input-paths nio-1.14.0.json 

/* Generic Signature Changes */

/* RawRepresentable Changes */

/* Removed Decls */
Func EventLoopFuture.hopTo(eventLoop:) has been removed

/* Moved Decls */

/* Renamed Decls */

/* Type Changes */
Func EventLoopFuture.andAll(_:eventLoop:) has parameter 0 type change from [EventLoopFuture<Void>] to [EventLoopFuture<T>]

/* Decl Attribute changes */

/* Fixed-layout Type Changes */

/* Protocol Conformance Change */

/* Protocol Requirement Change */

/* Class Inheritance Change */

but compare-sdk claims they're the same:

$ xcrun ../build//Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-api-digester -compare-sdk --input-paths nio-1.13.2.json -input-paths nio-1.14.0.json 
Diffing: nio-1.13.2.json and nio-1.14.0.json
Finished deserializing
Detecting type member diffs
Finished pruning
Dumping diff to 

/* Generic Signature Changes */

/* RawRepresentable Changes */

/* Removed Decls */

/* Moved Decls */

/* Renamed Decls */

/* Type Changes */

/* Decl Attribute changes */

/* Fixed-layout Type Changes */

/* Protocol Conformance Change */

/* Protocol Requirement Change */

/* Class Inheritance Change */

which is odd. Diffing between the ancient NIO 1.4.0 and NIO 1.14.1 gives me the following for diagnose-sdk:

$ xcrun ../build//Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-api-digester -diagnose-sdk --input-paths nio-1.4.0.json -input-paths nio-1.14.0.json 

/* Generic Signature Changes */

/* RawRepresentable Changes */

/* Removed Decls */
Func UInt32.nextPowerOf2() has been removed
Func UInt64.nextPowerOf2() has been removed
Subscript CircularBuffer.subscript(_:) has been removed
Var CircularBuffer.first has been removed

/* Moved Decls */

/* Renamed Decls */
Func CircularBuffer.removeFirst() has been renamed to Func CircularBuffer.remove(at:)
Func EventLoop.newPromise(file:line:) has been renamed to Func EventLoop.newPromise(of:file:line:)
Func EventLoopFuture.wait() has been renamed to Func EventLoopFuture.wait(file:line:)

/* Type Changes */
Func EventLoop.newPromise(file:line:) has parameter 0 type change from StaticString to T.Type
Func EventLoop.newPromise(file:line:) has parameter 1 type change from UInt to StaticString
Func EventLoopFuture.andAll(_:eventLoop:) has parameter 0 type change from [EventLoopFuture<Void>] to [EventLoopFuture<T>]

/* Decl Attribute changes */

/* Fixed-layout Type Changes */

/* Protocol Conformance Change */

/* Protocol Requirement Change */
Func ChannelCore.registerAlreadyConfigured0(promise:) has been added as a protocol requirement
Func EventLoop.preconditionInEventLoop(file:line:) has been added as a protocol requirement
Func EventLoopGroup.makeIterator() has been added as a protocol requirement

/* Class Inheritance Change */

and crashes for compare-sdk

$ xcrun ../build//Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-api-digester -compare-sdk --input-paths nio-1.4.0.json -input-paths nio-1.14.0.json 
Diffing: nio-1.4.0.json and nio-1.14.0.json
Finished deserializing
Detecting type member diffs
Finished pruning
Dumping diff to 
Assertion failed: (FD >= 0 && "File not yet open!"), function preferred_buffer_size, file /Users/johannes/devel/llvm/lib/Support/raw_ostream.cpp, line 701.
Stack dump:
0.  Program arguments: /Users/johannes/devel/swift-nio/../build//Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-api-digester -compare-sdk --input-paths nio-1.4.0.json -input-paths nio-1.14.0.json 
0  swift-api-digester       0x000000010e2fcca5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-api-digester       0x000000010e2fbcc8 llvm::sys::RunSignalHandlers() + 248
2  swift-api-digester       0x000000010e2fd2a2 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff65365b5d _sigtramp + 29
4  swift-api-digester       0x000000010f66a29f cmark_strbuf__initbuf + 130231
5  libsystem_c.dylib        0x00007fff652256a6 abort + 127
6  libsystem_c.dylib        0x00007fff651ee20d basename_r + 0
7  swift-api-digester       0x000000010e2e0143 llvm::raw_fd_ostream::preferred_buffer_size() const (.cold.1) + 35
8  swift-api-digester       0x000000010e2df160 llvm::raw_fd_ostream::changeColor(llvm::raw_ostream::Colors, bool, bool) + 0
9  swift-api-digester       0x000000010e2dca83 llvm::raw_ostream::SetBuffered() + 19
10 swift-api-digester       0x000000010e2dd612 llvm::raw_ostream::write(char const*, unsigned long) + 338
11 swift-api-digester       0x000000010962afac main + 10812
12 libdyld.dylib            0x00007fff651803d5 start + 1
Abort trap: 6

versions:

johannes:~/devel/swift-nio (HEAD)
$ xcrun ../build//Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-api-digester -version
LLVM (http://llvm.org/):
  LLVM version 7.0.0svn
  Optimized build with assertions.
  Default target: x86_64-apple-darwin18.5.0
  Host CPU: skylake
johannes:~/devel/swift-nio (HEAD)
$ xcrun ../build//Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -version
Swift version 5.0.1-dev (LLVM 34250a6eef, Clang 5c9d04dc06, Swift b4e44cb124)
Target: x86_64-apple-darwin18.5.0
belkadan commented 5 years ago

cc @nkcsgexi

nkcsgexi commented 5 years ago

@weissi, the argument name is a little bit confusing. `compare-sdk` isn't about getting the API differences between two json files but about generating migration scripts for the Swift migrator to use, e.g. which function names should be updated, etc. I'll rename the argument to be a more descriptive one.

If your intention is to get the added APIs, the tool currently doesn't support it. One way to work round this is to flip the input files to `-diagnose-sdk` invocation and all added entities should be shown as `removed` (not cool but can provide a quick glance).

nkcsgexi commented 5 years ago

Rename the argument name here: https://github.com/apple/swift/pull/24871

weissi commented 5 years ago

Awesome, thank you!

weissi commented 5 years ago

@nkcsgexi btw, is there a way to see any API that was added too?

nkcsgexi commented 5 years ago

There is currently no way to detect added APIs since the tool's main goal is to detect source-breaking and ABI breaking changes. One way to have a quick glance at the added API is to switch the order of inputs so that all added APIs will show as 'removed' ones.

weissi commented 5 years ago

Cool! Thanks for confirming, also like the idea of just swapping 🙂. The other option is to just diff the .json files with regular diff

weissi commented 5 years ago

@swift-ci create