News for hackers. Stuff that matters.
Re:Swift 5.0 release process by ainar-g on Tuesday September 25, 2018 @05:11PM (#18070510)
My memory might fail me, but I thought Swift 4 was supposed to be "the last major breakage"? Swift has a new major revision every year.

Compare this to Go (no major revisions after 6 years, probably a backwards-compatible major revision in 2-3 years) and Rust (no major revisions after 3 years, but with a mechanism called "editions"). To say nothing about Java or C#.

Re:Swift 5.0 release process by xenadu02 on Tuesday September 25, 2018 @05:21PM (#18070593)
Neither of those languages launched out of the gate with a stable ABI. Prior to Rust 1.0 it was much the same, with regular breaking changes. C++ famously took many years to have a stable ABI.

Swift 5 represents a stable ABI. That means from this point forward all binaries built with Swift 5 or later will run against a newer Swift stdlib.

The ABI is entirely separate from source compatibility. Swift is already source compatible and the bar for a source-breaking change is extremely high.

Re:Swift 5.0 release process by aw1621107 on Tuesday September 25, 2018 @08:52PM (#18071800)
> C++ famously took many years to have a stable ABI.

I'm pretty sure C++ doesn't prescribe any particular ABI for implementations to adhere to. There was even a paper in 2014 about defining a portable ABI, and I don't believe it was adopted [0].

In particular, MSVC uses a different ABI than the *nixes, and MSVC's ABI isn't guaranteed to be stable across major compiler releases. In addition, libstdc++ 5.1 had a significant break for C++11 std::string and std::list [1].

    [0]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4028.pdf
    [1]: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
Re:Swift 5.0 release process by coder543 on Tuesday September 25, 2018 @05:30PM (#18070656)
The Swift 5 release process document specifically implies that some Swift 4 code will not compile on Swift 5. This discussion is about source compatibility, not binary compatibility, which neither Rust nor Go offer AFAIK.

The number 5 _also_ implies significant breaking changes. Otherwise, why wouldn't it be Swift 4.3?

Removing Swift 3 compatibility mode (which was part of Swift 4) is itself a major source-compatibility breaking change, even if nothing else.

Re:Swift 5.0 release process by slavapestov on Tuesday September 25, 2018 @05:33PM (#18070682)
So far there are only a handful of small breaking changes between -swift-version 4 and -swift-version 5 on the master branch. The only ones I can think of are a type safety hole getting plugged and some warnings for corner cases around access control that got promoted to errors.
Re:Swift 5.0 release process by coder543 on Tuesday September 25, 2018 @05:37PM (#18070710)
If that's the case, that's encouraging to hear.
Re:Swift 5.0 release process by saagarjha on Tuesday September 25, 2018 @05:34PM (#18070687)
"Source compatibility" for Swift means that the compiler provides a flag with that will allow it to compiler earlier versions of Swift.
Re:Swift 5.0 release process by slavapestov on Tuesday September 25, 2018 @05:22PM (#18070605)
Rust does not have a stable ABI.
Re:Swift 5.0 release process by paulddraper on Tuesday September 25, 2018 @05:33PM (#18070672)
Java has and has always had a very high ABI compatibility.

But that's an unfair comparison since its "binary" format is non-native.

Re:Swift 5.0 release process by helge5 on Tuesday September 25, 2018 @08:52PM (#18071804)
C++ has a stable ABI? Do you have pointers on that?
Re:Swift 5.0 release process by olliej on Tuesday September 25, 2018 @11:20PM (#18072480)
There are basically two parts to ABI stability. Memory layout, and calling convention. C++ defines the memory layout ABI exactly - two c++ compilers will (theoretically) produce identical struct layouts irrespective of inheritance, virtual vs non virtual classes, etc

C++ implementations generally use a calling convention that is stable ABI on each platform, but different platforms may have a different ABI. In the past the MSVC ABI was different from most posix platforms, I’m not sure if that carries through to win64.

The easiest way to explain why C++ the language doesn’t prescribe the calling convention ABI is that you may want to compile code on different cpu architectures. There’s no way you could (sensibly) have the same calling convention :)

Re:Swift 5.0 release process by IshKebab on Wednesday September 26, 2018 @06:50AM (#18074599)
There's way more to a stable ABI than that. All of the standard library for example. Try making a binary library that uses `std::string`. It can't really be done - you have to take `const char*` and convert to `std::string` internally.

Huge pain for closed-source libraries.

Re:Swift 5.0 release process by olliej on Thursday September 27, 2018 @05:16AM (#18083025)
I think you're confusing maintaining ABI stability with at an API level, vs. ABI compatibility at the language level.

ABI stability at a language level is for code (replace syntax with your language of choice):

class Foo { virtual void bar();

   int _i;
   float _f;
   bool b;
   int bitfield : 5;
}

Should be stable across multiple compilers and versions. This is what swift currently does not have.

This is vs. source defined ABI, e.g.

class Foo { virtual void bar(); virtual void wibble(); int i; float f; }

vs.

class Foo { virtual void wibble(); virtual void bar(); float f; int i; }

In this example Foo is API stable, and the language ABI means either definition is ABI stable, but as a publicly exposed API it is not ABI stable. C++ defines vtable layout in terms of order of definition (so changing the order of virtual methods is not stable). And you have the source compatible reordering of i and f, which is just as ABI breaking in C++ as it is in a C struct.

Re:Swift 5.0 release process by IshKebab on Thursday September 27, 2018 @03:57PM (#18088007)
I'm not confusing it. We weren't talking about API stability at all. The issue isn't Swift's API stability.

This is all about ABI - can binaries compiled with one version of the compiler interoperate with binaries compiled with a different version.

API stability is easy - C++ has an extremely stable API. Swift is pretty stable apparently.

Re:Swift 5.0 release process by olliej on Thursday September 27, 2018 @09:44PM (#18090353)
Ok, here's an example API:

SomeLibrary.h:

class Foo {

   virtual void bar(); 

   virtual ~Foo();
};

The library is compiled into SomeLibrary.dll,dylib,so or what have you.

Your program uses this:

void my_cool_function(Foo* foo) {

    foo->bar();
}

Later on the library makes a change, and adds a new virtual method wibble(). The API is stable -- they haven't removed Foo::bar, and they haven't changed its parameters or return type. But this API change can break the library ABI if it declared the new virtual method in the wrong part of the class, because vtable ordering is defined as being order of declaration.

So there are two aspects of ABI compatibility. First, does a given API result in the same ABI irrespective of what compiler version it uses. The second is, given that your language is ABI stable, are your changes to the API also ABI stable. C++ is notoriously bad at this, because of foot guns like vtable ordering, changes to binary layout of superclasses, etc.

Swift is at least in existing versions even less stable, where you're not necessarily guaranteed that a single API will get the same ABI depending on what things it is compiled with, and certainly not through even minor compiler version changes - let alone actual language version changes.

Re:Swift 5.0 release process by jedieaston on Tuesday September 25, 2018 @05:15PM (#18070535)
I don't think Swift 5 is a major breakage. Swift 3 -> 4 code is compatible, so 4 -> 5 should be compatible too.
Re:Swift 5.0 release process by ainar-g on Tuesday September 25, 2018 @05:20PM (#18070580)
>Swift 3 -> 4 code is compatible

Is this really true? Looking through 4.0 release notes I see some incompatible changes like:

  SE-0164 Remove final support in protocol extensions
  SE-0160 Limiting @objc inference
If your code compiled with the old version and doesn't with the new one, then those versions are incompatible.
Re:Swift 5.0 release process by slavapestov on Tuesday September 25, 2018 @05:21PM (#18070596)
The compiler has a -swift-version flag which gates the source-incompatible changes. There were a number of changes between -swift-version 3 and -swift-version 4, including the two you highlighted. The delta between -swift-version 4 and 4.2 released this year was much smaller.
Re:Swift 5.0 release process by favorited on Tuesday September 25, 2018 @05:38PM (#18070724)
The real issue I encounter isn't Swift itself, it's the constant Swift-specific SDK changes... When the `NSNotification.Name` Swift APIs change every year, it means migration is still painful.

It's not the Great Renaming, and it might not be fair to the Swift project itself, but unless I can compile a project using the 10.13 and 10.14 SDKs without source changes (which you can in Objective-C), the impression is that Swift doesn't have source compatibility.

Re:Swift 5.0 release process by saagarjha on Tuesday September 25, 2018 @05:43PM (#18070760)
As I'm sure you're aware, these are changes in AppKit, not Swift. AFAIK the Swift project has no control over how this API is exposed.
Re:Swift 5.0 release process by dbaupp on Tuesday September 25, 2018 @05:56PM (#18070853)
The Swift compiler does a lot of automatic "rewrites" of (Objective) C headers to be more Swifty, so it does have some measure of control. That said, the largest changes are guided by annotations associated with the headers.
Re:Swift 5.0 release process by favorited on Tuesday September 25, 2018 @05:48PM (#18070797)
I'm not disputing that. What I am saying is that, until the Swift representations of the Apple platform SDKs are stable between releases (like it is in Objective-C), then the majority of Swift codebases will not be source compatible the way Objective-C codebases are.
Re:Swift 5.0 release process by Nullabillity on Wednesday September 26, 2018 @12:35AM (#18072816)
They're both ran by Apple, so that's a distinction without a difference.
Re:Swift 5.0 release process by saagarjha on Thursday September 27, 2018 @04:28PM (#18088286)
Unfortunately, this isn't how Apple works. Both teams are more or less separate in this case. Sure, the Swift team can certainly send information over to the AppKit team, but they don't have the ability to make any decisions on naming conventions.
Re:Swift 5.0 release process by ainar-g on Tuesday September 25, 2018 @05:34PM (#18070686)
That is compiler compatibility. I am talking about language-level compatibility.

Yes, you can continue compiling v3 code with a v4 compiler with a flag, but if you compile your v3 code without a flag, your code may fail to compile. So while there may not be a compiler breakage, there is a language breakage between v3 and v4, and apparently there will be another one between v4 and v5.

Re:Swift 5.0 release process by slavapestov on Tuesday September 25, 2018 @05:37PM (#18070711)
That is right, but as I wrote in another reply here the changes from 4 to 5 are miniscule, mostly just fixing corner cases where the old behavior was not correct.
Re:Swift 5.0 release process by coder543 on Tuesday September 25, 2018 @05:33PM (#18070683)
it is worth noting that swift 3 support is being removed from swift 5.
Re:Swift 5.0 release process by airstrike on Tuesday September 25, 2018 @05:21PM (#18070591)
See https://docs.swift.org/swift-book/GuidedTour/Compatibility.h...

> When the Swift 4.2 compiler is working with Swift 3 code, it identifies its language version as 3.4. As a result, you can use conditional compilation blocks like #if swift(>=3.4) to write code that’s compatible with multiple versions of the Swift compiler.

Re:Swift 5.0 release process by melling on Tuesday September 25, 2018 @06:14PM (#18071006)
Apple is pretty good about automating the conversion of Swift to the newer version.

Swift 2 to 3 was a little bit of work but the new succinct syntax was worth it.

It doesn’t sound like there will be many breaking changes in 5.0:

“As with Swift 4.2, the vast majority of sources that built with the Swift 4.2 compiler should compile with the Swift 5.0 compiler”

Re:Swift 5.0 release process by pwinnski on Tuesday September 25, 2018 @05:16PM (#18070548)
If long-term stability is your goal, Swift is definitely not yet for you. Perhaps after v5, things will settle down. That seems to be what they're aiming for, but I would wait and see.
Re:Swift 5.0 release process by raydev on Tuesday September 25, 2018 @11:20PM (#18072476)
> but I thought Swift 4 was supposed to be "the last major breakage"?

It wasn't even major. I updated several projects from Swift 3 to 4 without issue. The largest project was close to 200k loc and it only took me 20 minutes to get everything up to date.

Just make sure your dependencies aren't in Swift because then you're relying on 3rd parties to update their code. I'll be avoiding all Swift libraries except for PromiseKit (it's so nice!).