Episode 184: Safety in Swift 6, Protocols & More with Doug Gregor
40 minAudio
In this episode, Conor and Bryce chat with Doug Gregor from Apple about the Swift programming language! Link to Episode 184 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Twitter ADSP: The Podcast Conor Hoekstra Bryce Adelstein Lelbach About the Guest: Douglas Gregor is is a Distinguished Engineer at Apple working on the Swift programming language, compiler, and related libraries and tools. He is code owner emeritus of the Clang compiler (part of the LLVM project), a former member of the ISO C++ committee, and a co-author on the second edition of C++ Templates: The Complete Guide. He holds a Ph.D. in computer science from Rensselaer Polytechnic Institute. Show Notes Date Recorded: 2024-04-29 Date Released: 2024-05-31 Swift Programming Language Swift Actors D Programming Language Rust Programming Language Fearless Concurrency? Understanding Concurrent Programming Safety in Real-World Rust Software Swift Protocols 2022 LLVM Dev Mtg: Implementing Language Support for ABI-Stable Software Evolution in Swift and LLVM Oxide Episode - Discovering the XZ Backdoor with Andres Freund Swift Algorithms Library Intro Song Info Miss You by Sarah Jansen https://soundcloud.com/sarahjansenmusic Creative Commons - Attribution 3.0 Unported - CC BY 3.0 Free Download / Stream: http://bit.ly/l-miss-you Music promoted by Audio Library https://youtu.be/iYYxnasvfx8
Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.
Transcript
From the show. Tap a time to play from there.
Doug GregorSo the Swift generics model is rooted in exactly the same ideas as C OX concepts. So some of the names are different, but the ideas are the same. So the equivalent to a concept in Swift is called a protocol. And a protocol is an abstraction that describes a set of types that have a certain set of common operations. Now, just like with concepts, you can compose protocols. So a protocol can inherit from another protocol, for example, meaning every type that conforms to the one protocol also conforms to all the ones it inherits from.
ConorWelcome to ADSP the podcast episode 184, recorded on April 29th, 2024. My name is Connor, and today with my co-host Bryce, we finish part five of our five-part interview with Doug Regard. In today's episode, we talk about safety in Swift 6, protocols, generics, ABI, and more. You mentioned that, you know, half of its lifetime has been working up to Swift 6, uh, which obviously then sets off a bunch of bells in my head.
ConorWhat are the what what is the reason for that? And my guess is that it's because there are some uh big features that are coming in Swift 6 that are, you know, if if if the last couple of years hasn't necessitated uh, you know, a version bump or a major version bump, uh there's probably some exciting stuff that obviously the people that follow the Swift community uh and the Swift language probably have been teased about or know about. Um so to the extent that you can talk about it, I I would love to not leave our listeners hanging on what uh is coming in Swift 6 and what should get them excited. So feel free to answer those in in whatever order you want, and maybe that's how we'll wind down, and then we can dive and do a full-blown you know history of the Swift 1, 2, 3, 4, 5, 6 or whatever you'd like to come back and talk about.
ConorBut yeah, uh let's see.
Doug GregorWell, maybe let's start with Swift 6, because I think it says interesting things about how Swift evolves. So um we have not done a major version bump since 2019. That was Swift 5. And this does not mean that we didn't get new features in Swift. So we deliver new features to Swift every six to 12 months. So there's a new release every six months, and usually it comes with major features. Um since we declared Swift 5, we added a concurrency model. So async await uh actors is the basis of the concurrency model in Swift.
Doug GregorWe added that in 2021 and have been refining it ever since then. We added macros support last year, and we've been involving the generic system and so on since then. So new features we just sort of deliver on the annual cadence. We have uh there's no surprises here. So um Swift has an open evolution process. So if you go to the Swift forums, uh you can see reviews on new Swift features as they're being discussed. Um they're discussed in the community, then decided upon and you know implemented throughout this process to come available.
Doug GregorSo it's a fairly rapid turnaround from a programming language standpoint to have these features discussed, designed, rolled out pretty quickly. So why are we doing Swift 6? So uh Swift 6 has one major goal, which is that uh we are expanding on the memory safety that we've always had since the beginning of Swift time to include database safety. Oh wow. So the idea here is that uh the language statically has an understanding of where data is created and where concurrency is introduced, so that it can tell you whether you are uh leaking shared mutable state across concurrency boundary, therefore introducing a database.
Doug GregorSo there's no way to do this without a without breaking some source code. Because there is some source code today that is uh accepted in Swift 5 and has data races that will necessarily uh produce errors in the Swift 6 language mode to diagnose the fact that there are data races here. And the goal is we want Swift 6 to be at a point where you know you already didn't have to think about memory safety in Swift, you just program, it's fine.
Doug GregorWe want that same thing when you're doing concurrent programming, that you don't have to worry about data race safety because the system is supporting you and will tell you when you've made a mistake. And that's that's essentially what the the whole run-up to Swift 6 has been about.
ConorThat's really exciting. And that is gonna I mean, already I think Swift is you know in the space of sort of languages that get compared with Rust, but uh definitely is gonna elevate it even more. Uh because I I know that you know D as well. There's been lots of conversations about uh safety and D. I don't follow the D community that closely, but I do know that I attended certain meetings and and meetups, and those conversations have been there. Anyway, so in the system space, it is obviously the hot topic if you follow obviously the C conference uh circuit.
ConorYou know, half of the keynotes in 2023, my guests, were all about safety and C. And you know, I'm sure folks that you know uh have have given you know these these safety talks.
BryceUm anyway, so it's uh not my keynotes though. Not my keynotes.
ConorBut uh that yeah, I'm I imagine that that's gonna uh um cause a certain amount of uh whatever ripples or or or waves in the uh because you know, the White House document, whatever it was called, got released and they had a shortlist, I think, of six languages. I don't recall, I don't recall Swift being on that short list, but maybe they were. Yeah. Um it was. But they were okay. Yeah. So I mean this will, I mean, you're you've already made the short list, but this is uh obviously already adding uh to uh to to that sort of um argument for why Swift uh in in you know how safe is it?
Doug GregorYeah, and concurrency safety, it's a really tricky one. So like I haven't seen a proposal in the C space, for example, to introduce concurrency safety. Um Rust Rust has managed it uh using strict ownership rules. Um and it's it's an interesting model. Um we found in Swift that that would be too onerous. So in Swift, uh the fact that we are very uh value type-centric helps a ton because it is completely safe to share a value, like a value of value type across concurrent tasks because all the copies are independent.
Doug GregorLocal reasoning wins. But we Swift has classes like with inheritance and people use this feature, and so you can't share those in any meaningful way. Um so we and strict ownership, like unique putter style. Good for concurrency, not so great if you actually have more interesting graphs. So a c a class in Swift doesn't have value semantics? No. They are reference types. So structs and enums and anything built on them, like uh arrays of structs and dictionaries of structs and so on, all value semantics.
Doug GregorSo you can build pretty much anything out of a value semantic model, and it's you know, a copy when you when you pass it around.
BryceSo so isn't a isn't a what type of thing is an array? It's a generic something, but what is it's a generic what?
Doug GregorYeah, so it is a generic struct.
BryceOkay.
Doug GregorThat wraps a class and implements copy on write semantics.
BryceOkay, got it.
Doug GregorSo copy copy on write is the way out, right? Because like in C, you wouldn't copy a vector everywhere. Right? Right. That would be problematic. You pass them by const reference.
BryceRight.
Doug GregorCopy and write does. Yeah. Um so with with classes, we needed a better answer in Swift. And actually, we found it uh when I was chatting with you two at PLDI two years ago. Oh. There was an amazing paper there on fearless concurrency, which had a type system that uh was far more usable than what we've seen in any other language. Uh, and we worked with those authors to bring those ideas into Swift.
Doug GregorAnd they're they are actually forming part of the backbone of Swift 6's data array story to make reference types like classes uh work much better.
BryceInteresting.
Doug GregorYeah.
BryceWell, it certainly sounds like a uh uh a language in developments that we, as two people who are getting vidia, the parallel programming company, should should uh be paying more attention to. Does Swift have atomics? Yes. Okay. And uh does Swift have GPU support? Can I program my GPU with Swift?
Doug GregorSwift does not compile to GPU. No. You could possibly make it do so.
BryceI assume that on Apple that that it that there's some uh metal compute way of uh doing things like like you can't program an NVIDIA GPU with it today, I would imagine. But but if you want to do compute on Apple, I would presume that there's something. Maybe I'm wrong about that though.
Doug GregorAaron Ross Powell You can use the metal libraries from Swift, certainly. But I but your you know your actual code that runs on GPU would still be metal. Okay, gotcha. Oh interesting.
BryceOkay. Yeah. All right. So we we we we we we should talk about the generics. We should talk about generics. They're so much fun.
Doug GregorOkay. What do you want? You want a rundown of the Swift generic system?
BryceUm yeah, yeah. I mean, you said that it's rooted in C OX concepts. So start from how you got start start from the beginning of your their C concepts, OX concepts is rejected, then you start working on Swift, and what do you come up with?
Doug GregorYeah, we come up with something that is uh very similar, but without the holes. So the Swift generics model is rooted in exactly the same ideas as COX concepts. So some of the names are different, but the ideas are the same. So uh the equivalent to a concept in Swift is called a protocol. And a protocol is an abstraction that describes a set of types that have a certain set of common operations. Now, just like with concepts, you can compose protocols.
Doug GregorSo a protocol can inherit from another protocol, for example, meaning every type that conforms to the one protocol also conforms to all the ones that it inherits from. Any type can uh describe that it conforms to a protocol, meaning it implements the interfaces required of the protocol. And it can do so with what's called an extension. So let's say I want to uh I talked about this earlier, right? I want to make a Swift array conform to the equatable protocol.
Doug GregorEquatable protocol will say protocol equatable, and it will have a function equal equal in it that takes two values of type self and return to bool. And so now I can write extension array that says I can array conforms to equatable. That's going to be fully type checked. And the compiler will say, ah, no, you don't, because your equal equal operator requires that your element type be equatable. So you can instead so you can correctly state, you know, extend the array type to make it equatable, where the element type is already equatable.
Doug GregorAnd implement any logic that you need to make sure that that is true. Uh generics in Swift are follow the same notion as like a constrained template. So you can write a generic, we still use angle brackets, same thing as many other languages. And that uh template, that generic definition is separately type-checked. There is no specialization, there's no overloading at instantiation time. So the separately type-checked body can never go wrong.
Doug GregorRight? There's d instantiation failures don't exist. Um and more than that, the generics can actually be separately compiled. So the actual default is you separately compile your generics, and the entire body is written in terms of these constraints on protocols. And that code will work for any type that that uh conforms to the protocols that you know meets the requirements of that generic function, even if you don't know about these types.
Doug GregorLike you can ship a generic function in a shared library if you want, right? And and use it with unknown clients.
BryceIs that is that because it's not like uh a static system like C, but it's more like a type erased sort of thing?
Doug GregorAt the implementation level, it is I'm afraid of the word type erase, the phrase type erased, because there's a very specific meaning in Java, which is that it loses the information about like parameters. That information is never lost in Swift. It's maintained even though you don't know what the type is until runtime. There's metadata there that's passed along to the generic function to say what the type is. And you can always have that information, so it's not erased, but the implementation is essentially you know dynamically dispatched such that it can deal with any type that that meets the requirements.
Doug GregorGotcha. Yeah, yeah. So there's indirect. And we we treat sort of instantiation in Swift is just a compiler optimization pass. So if you have access to the body of a generic function and you have a call to it with concrete arguments, then the compiler can go and do the equivalent of instantiation to create a faster version exactly for that type when it's profitable, right? When you have the information and it looks profitable.
BryceSo so yeah, I mean what what in C, you essentially have two very explicit systems where you have a way of doing templates which are instantiated at compile time, and uh if you want to do any form of dynamic dispatch, you you either have to roll your own thing or you have to do inheritance and classes, and so it's sort of two worlds, whereas in language like Swift, it's one world where the uh the generics can be optimized by the compiler in in the places where it matters. Um people don't have to think about and deal with these two different things.
BryceIt's a very C way of doing things where it's like we care about the performance and we don't care if there's half a dozen ways of doing things.
Doug GregorSure. And in in in C, you have mechanisms if you need them. Like if you don't want to instantiate the template for every use, you can do tricks, right? You can put std functions in there, or you could use like one of the type erasure libraries that are available. I know. Boost has an interesting one. I'm not sure what people are using today. Swift also builds that notion of type erasure into the language. So if you have a protocol, you can use it for generic constraints.
Doug GregorYou can also create a value of type, any space, and that protocol name, which dynamically erases the type that's that's been put in there and lets it vary at runtime. So let's say I want a container of strings. I don't care if that container is a set or um an array or something else you came up with. Right. In C I would write like a type erasure class of some sort that you know maybe does some virtual dispatch to do that.
Doug GregorUh in Swift, you basically write any collection of string. And the compiler handles that type erasure for you, um, which lets you like the the idea here is most of the time you should be using generics and sort of keeping all that static type information because it can optimize well when you need to optimize it well. But if you really do need that indirection, you're going to deal with like collections of heterogeneous types, for example, then the same mechanism that is there, and you can sort of like uh seamlessly shift into the dynamic dispatch world and back to the static world when you need to.
BryceYeah, this reminds me of another topic that uh I I uh I was neglectful in my in my role and not uh bringing this up, but uh Swift has the rather interesting approach to uh ABI uh resilience that uh I think is is often talked about in the C world whenever our ABI problems come up. And uh maybe you can maybe you can explain a little bit of how that's uh approach.
Doug GregorYeah, sure. So this is one of the things I think is almost unique to Swift. There are very few languages with a stable ABI at all. C, C, and the managed languages that are stable like at the bytecode level, but not necessarily at the low-level calling convention. And of those that do, they're not really built to make it easy to evolve something while maintaining an ABI. And this is the challenge that C has always had, where it has a stable ABI, and people do ship like shared libraries of the standard library, but you really can't change anything in the implementation without breaking the ABI.
Doug GregorIt's very hard to reason about. We knew with Swift as we were going into designing it that one of the fundamental things we wanted to do was be able to ship system like platform libraries written in Swift. And so a platform library is this interesting breed of library where it ships in the operating system and it's used from third-party apps. And users completely expect that they can update their operating system and their apps still work.
Doug GregorRight. And maybe even get new features, which means the implementations need to be able to change without breaking that binary interface. And so uh in the design of Swift, we realized, okay, we have to not just provide a stable ABI like C does, sort of the de facto ABI that C has is stable. We actually need to make it deliberately designed such that teams that are working on these platform libraries can do like real serious feature development and evolve their libraries without breaking those interfaces.
Doug GregorUm and so this is actually it's it is a part of the language only in subtle ways that you don't see. Uh, but it's um deeply embedded in the way that Swift compiles code when you are building a library that is that is meant for this. So, you know, stepping back to like the the language itself, so you know, imagine you are a vendor of a platform library and you have a struct, like a URL struct, right? It's a value type, you're gonna provide some APIs on it, and you know you, you know, at some point you're gonna say, okay, I'm gonna give this out to my users.
Doug GregorNow, Swift takes uh the view that unless you explicitly make something public, no clients can depend on it. So you might have your struct you can develop yourself, no one can touch it outside of your module. If you want to make it public, you slap the public keyword on it. And that means you must continue providing this thing or else you will break your client, which is both a promise on the source code side of things, like they'll continue to compile. When your library is built in in this form with this library resilience form, uh it also means that clients will be compiled in a way that you can change any non-public detail of your type without breaking the ABI.
Doug GregorSo things like reshuffling your fields, fine. Changing the size and layout of your type, fine. You can go and do that, because those are non-public details of your type. So mostly that's just the compiler sort of introducing a direction where it needs to, when it knows that it's uh at a boundary where something underneath it can change and needs to maintain the ABI. And for the most part, it doesn't affect users, other than we have other checking technologies to make sure that you know when you changed and you know delivered a new version of your of your library, you didn't actually break the ABI or break the interface.
Doug GregorBut it's a very pervasive system. So from the user perspective, you add this library evolution flag to the compiler, and now your your code builds in a way that it is ABI stable. And you can change the implementation for your clients. Your clients will not even know that you did this because the language impact is zero for enabling this. Um this is actually super important that the language impact is useful because the same code needs to be able to run against a platform where like the Swift standard library is baked into the platform itself as part of the operating system, and also run.
Doug GregorSomewhere where you don't have those constraints and you just want to like not have any of these resilience barriers in there and compile down to um you know even just one statically linked binary, for example.
BryceYeah, I don't know any other language that has a uh a system quite like us.
Doug GregorIt's um I I wish we knew of one so we could see if they had some ideas that we missed. So I guess it's a little late for us. But uh as far as I know, this isn't a thing that other people have tackled. Maybe Connor knows. Connor's the researcher's here here. He would he would maybe know.
ConorI do not know of any languages, and I recall if I recall correctly, Doug, that was the talk that you gave at PLDI 2022 uh was on ABI evolution. And I if I recall correctly, you kind of at the end of the talk said, you know, the point of this talk is you know, I'm sitting in front or I'm standing in front of an academic crowd, and for better or for worse, this is not a topic of interest for most of you. You know, like I'm I'm not sure if you said this, but you know, it is true that 90% of you know PL research these days is in type theory and uh you know and safety and and proof systems.
ConorAnd you know, as interesting as that topic is, uh I think what you said is like, you know, this ABI evolution, you know, different techniques, etc., it may not be as sexy and cool as you know, Agda and all these different proof languages, but this is extremely important and only folks in industry really care about this. And to be honest, there's not really that, you know, like you said, like what are the other languages that actually experiment with this? I cannot off the top of my head think of any really. And uh maybe you could argue that Rust with, you know, epochs uh or additions or whatever they ended up getting, I think it's additions, right?
ConorUm and then C.
BryceIt's not really the same thing at all, but like I I don't I don't think Rust's epochs thing provides any form of ABI resilience, and C's epoch proposal didn't either. Different thing.
ConorDifferent thing?
BryceYeah.
Doug GregorThere have been discussions in the Rust community about around a stable ABI, but I haven't seen anything that is crystallized there.
ConorOkay, so maybe this is more API API evolution than it is ABI evolution.
Doug GregorYeah.
ConorBut yeah, it's interesting, not even just with respect to this feature, but like the disconnect between academia and industry when it comes to programming languages, because there seems to be, at least from my perspective, like a gap in the usefulness necessarily of the stuff that gets researched on versus the interest and sort of like academic nature of the work. And yeah, I'm not sure if you want to add anything to that, Doug. And I I think that talk was recorded. If it is, I will definitely find a link and throw it in the show notes if folks are interested.
ConorUm, I'm not I'm not sure if it was, but I I mean I was there in person, so I saw it live. If it's not recorded, um maybe I'll try and find a talk. I'm not sure if you gave that talk again at a different venue that you you definitely know it was recorded.
Doug GregorUm there's uh a form of that talk that is more compiler-centric that I gave at the LLVM developer meeting. And I can't remember if it was 2020 or 2021. Okay. One of the LLVM developer meetings, I gave a talk that was more about how we do code generation for this ABI resilience model. Whereas the the talk that you're you're mentioning at PLDI was very much like this is a real problem we have in industry that we yeah, it it is getting ignored.
Doug GregorI think it's really unfortunate that this problem is getting ignored. Because as it stands, how do we talk to our operating systems today? It's C, right? It's COSIX C interfaces, which is a little bit unfortunate, especially as we talk toward, well, we want to improve the safety of our systems for memory safety.
BryceYeah.
Doug GregorHaving to funnel everything through a C API to talk to your OS is not good for that overall goal. Right. Right. And this is part of where we're coming from, but we want to build the platform APIs in a language that is both expressive and safe. And so we had to have an ABI there. But yeah, even new languages. I I don't I wouldn't say it's it's academia that's specifically at fault here. You look at brand new programming languages, they don't they won't commit to an API, right? Yeah. And I understand the reasons. You you do give up optimization potential, and it becomes harder to evolve your compiler once you've locked down an API.
ConorYeah. I find this stuff interesting from from like a PO point of view, of the stuff that kind of falls through the cracks, like the other thing that comes to mind because it's topical. ZX or XZ, whatever that uh the massive uh almo like near miss of um and like that's that's completely Oh wait, wait, I have I you've completely lost me.
BryceWhat are you talking about?
ConorYou didn't you didn't hear about this, Bryce? No. It was uh I do do you know what what order of the two letters it was, Doug? It was it was either Z, yeah.
Doug GregorXZ open source project.
ConorIt's actually socially engineered into creating a bad thing. Social engineering, basically.
BryceBut like over years and so so somebody was contributing to this project for like two or three years and then uh inserted uh malicious code, and it seems like the whole entire thing was a setup for him to insert malicious code.
ConorYeah. But this is it's it I I bring it up because it's one of these things that you know it doesn't really get talked about in the you know, well, we gotta program in memory-safe languages and safe. Safety is such a huge topic, but like this is an another like it's adjacent to safety or should be under this safety umbrella, but no one's talking about this stuff. And like this would have been like this would this was like what do they call it, uh, you know, level 10 like CVE. Like this, like it's getting it's getting uh you know access, like SSH access. It would have just been anyways, and and and I I listened, I think uh was it Brian Cantrell from Oxide and Friends, he had a podcast where they had the Microsoft engineer that found it.
ConorAnd he like his story of like how he ended up like noticing the the perf difference, it was like it could have been like a gust of wind basically that uh caused him to not look at it. And that is like that's terrifying. That like it was it was pure coincidence that he happened to notice one thing a month ago, he happened to not be super busy, and so we all take some extra time. Anyway, so it's it's this kind of stuff that like there's always these sexy topics in like programming language, whether you're a compiler writer or uh an academic in industry or an academic uh in academia, and then there's these kind of topics that don't get talked about as much, whether it's with respect to you know ABI evolution or uh security.
ConorIt makes me makes me think that there, you know, that there should be some greater ecosystem or or way that we talk about this stuff and not just you know, how are we gonna get uh dependent types into Haskell and then into every other language? Because like as cool as that would be, uh there's probably more important important things that'll have a larger impact on the industry of software engineering, but for whatever reason, there's less folks with eyes on that stuff.
Doug GregorIt it's hard to know. I mean, the part of the nature of research is you often don't know what the ripples will be from your success. I mean, I I I would love people to be looking at you know what it takes to how to maintain a stable ABI, and if if we had some formalism around the way we tackle resilience. So we have this abstract notion of like these resilience domains, like code that's compiled together, and what optimizations you can do in there without breaking code that's outside of it. It's very ad hoc.
Doug GregorLike we think it holds together. I would love if someone went out and researched it and you know, proved us right or wrong, right, and told us where the problems were. Um I don't know how to get people interested in that. On the other hand, we've pulled for research and seen things where people did chase a cool type system and it actually solved a real problem for us in the data safety realm. So I don't I don't know. I don't know how to tell what to tell people to work on, um, but I I would love seeing more wild papers at academic conferences.
Doug GregorLike I feel like there's way too much of uh a group of researchers all get interested in the same topic and publish a ton of papers pushing it forward and everything else gets starved out. And that makes me a little sad because there's a ton of wild ideas that got submitted that that won't won't get you know the airtime that they need to turn into something cool.
ConorWell, hopefully with AGI right around the corner, you know, everyone's gonna be able to make their own TV show and uh everyone will be able to make their own, you know, fully fledged with a language server and tooling and package management uh language over a weekend. So uh, you know.
BryceLook, look, I I I saw the face from Doug, but uh we gotta we gotta mention AI. They uh they they at NVIDIA they they pay us a little bit extra every time we mention AI in the podcast.
ConorI haven't seen any of this money. This is uh very upsetting to hear.
BryceAll right, all right. We got we got one more one more question for you, Doug, and then we we we do have to go because we're now into third hour, and my microphone now has a red light on it, which I think means the battery's gonna die.
Doug GregorIt looks ominous.
BryceSo so here's my last question. So has Swift become the language that you thought it would be when you started working on it? Like has it evolved in the ways that you thought it would? Has it succeeded in the ways that you've expected? And how has its evolution surprised you?
Doug GregorThat's a big question.
BryceSo I like to end big.
Doug GregorYeah. So I think the evolution path has been more or less what I expected. So you know, in the in the early days, we were just getting the pieces in place for what we felt like was the minimum you needed for a general-purpose programming language. And as we turned the corner to the point where you know we were writing system libraries in it and people were using it at a large scale, our evolution has sort of necessarily turned toward more niche things.
Doug GregorSo, you know, a macro system that gives you language extensibility, but doesn't uh really change the way the fun the language is used or uh an ownership system, so like move-only types is one of the big new things in Swift World. And but it doesn't uh really change the way you program in Swift. It's been fairly stable for the last couple years, five years probably. Um it's more about filling in the niches so that we can take Swift anywhere.
Doug GregorAnd because sometimes you you actually need the extra performance benefits of like move semantics and knowing there is nothing going on behind the scenes that you're not privy to, right? To to fair performance or to fit in, you know, down in firmware or something. And so I think that is the right evolution of the language. I keep wanting things to slow down a little bit. You know, I don't want the language can't grow forever. Uh it won't. Um, but we can continue to fill in gaps. So I think, you know, has it done as well as I thought?
Doug GregorI think it's kind of a split verdict for me. So the uptake within like the Apple development community has been amazing. And it's been wonderful to see people excited. I was thrilled that the people that like are on the conference circuit for for Swift are young and it's like people that started with Swift for the first time and found exciting things, and it's like a much more energetic and diverse group than than we've had in other communities, language communities that I've been a part of.
Doug GregorAnd I think that's been amazing, and it's been wonderful to see people pick up on like some of the things we designed hoping that they would be usable by everyone. Like the generic system comes back to that a lot for me because I love generic programming. But like people are writing generic algorithms in Swift, like fairly new Swift programmers, and they're just better fine. Like it works well for them. That's been great to see. Um I want Swift to uh break out further from the the Apple universe to really um you know be the language people want to reach for for whatever platform they're doing.
Doug GregorBecause I feel like it's a great language for getting your work done right. And you know, when we see reports of people that have done this, they seem pretty thrilled at what they've been able to do. Um but you know, the the perception is ever there that it's an iOS app language. And that's that's the thing that bothers me a little bit because I think it's so much more than that.
BryceDo you um when did you know that or when did you feel that Switch was going to succeed? Did you like from the moment that you started working on it, were you confident?
Doug GregorNo, not that early. Um so I think Alright, so there were I would say there's there's actually three points which are very, very clear for me. Um the first one is uh just when we actually introduced it and people were super excited and went out building cool stuff. Like the amount of cool things that people built in the first like two weeks of Swift being available was just amazing. The second point is in 2016, so this was Swift 3.
Doug GregorSwift 3 was a major change from Swift 2. Uh almost not the same language in many ways. But it marked a complete shift from Swift kind of like being a language that was like a better Objective-C or a layer above on uh from which you used Objective-C libraries, to like this is a language that has its own identity and feel. And like value type, this is when we were really pushing value types hard and getting people to think differently, like to really use Swift as it was meant to be used, and people picked up on that.
Doug GregorUm and I think the third part was actually 2019 with Swift 5. When we nailed the ABI stability and we declared, you know, it's ABI stable, we have the feature set that we need to move forward. Uh, we actually that is the point at which uh Apple started shipping platform libraries written in Swift with Swift interfaces. That's the point of no return because ABI is forever, right? We are invested, this is the path forward, and we can build on this for for years and years to come.
Doug GregorSo we've done a lot of cool things since then, and there's a whole lot more coming. But um that that's when it's clear that like this truly is the way forward. And you can you can look at other you know, languages that have started in a corporate environment that never got to that point or failed before they got to that point. Um so that that was a a major mark of success. And we're still maintaining that ABI and it's hard work, but it has not stopped us from doing like major language features and revisions to improve the user experience.
ConorAnd as a final note, if after these four episodes, five episodes, six episodes, we don't know how many it was. You decide to go and check out Swift. Probably this should have been at the beginning. You have to make sure that you include the algorithms library. There's a standard library that ships with Swift. But I remember the first time I went and uh checked out the standard library. I thought there's a bunch of missing, uh missing like what I would expect standard algorithms. Uh I think famously one of them was scan. And uh I was like, wow, this is just incomplete.
ConorAnd then sure enough, a little while later, uh I found the algorithms library, which had every single, I swear, every single algorithm that I thought was missing was there. I they don't call it scan. If I have my memory serves correctly, it's called reductions, which is actually quite nice because uh that's the same name that Clojure calls it. And it kind of kind of reflects the symmetry between reduce and and scan, where you know, from those two names you'll never guess that they have anything to do with each other. Uh but yeah, make sure, make sure, folks, if you check, if you check out Swift, you gotta include the algorithms library.
ConorThey got adjacent pairs to one of the few languages that calls the adjacent adjacent pairs.
BryceConnor Connor is just lost without a scan. Like if he doesn't have access to a scan and a reduce, he's just lost without a scan too.
ConorWhat are we talking about here? I'm I'm lost without a scan. Like you know, we're all lost without a scan. If you're an array programmer and you don't have a scan, it's like, what are we doing here? What have I got to write a four? Anyways, thank you so much, Doug. This definitely, I think, has set the record as the longest recording. I mean, I we've done two hours plus before.
BryceI didn't think we would ever break it, but I guess this is what the dog thinks uh the length of the recording. She's like, Can you stop and take me out now?
ConorTake me for a walk now. But yeah, thank you so much. This has been an absolute blast. I know for a fa I mean, uh whatever I call it, the C OX story with Doug Greger, whatever clickbaity title I find for the first couple episodes, uh, they're gonna be our best in a while. Be sure to check these show notes either in your podcast app or at adspthepodcast.com for links to anything we mentioned in today's episode, as well as a link to a GitHub discussion where you can leave thoughts, comments, and questions. Thanks for listening. We hope you enjoyed and have a great day.
BryceLow quality, high quality, that is the tagline of our podcast.
ConorIt's not the tagline. Our tagline is chaos with sprinkles of information.
In this episode, Conor and Bryce chat with Zach Laine about C++26 Reflection vs CRTP, AI, kids & more. Link to Episode 313 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP:...
In this episode, Conor and Bryce chat with Zach Laine about the C++26 contracts fiasco. Link to Episode 312 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The Podcast:...
In this episode, Conor and Bryce talk with Zach Laine about his career and the career changes he has made. Link to Episode 311 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials...
In this episode, Conor and Bryce talk about Bryce's next chapter and where he is leaving NVIDIA for. Link to Episode 310 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The...
In this episode, Conor and Ben chat with Jason Turner about default construction in C++. Link to Episode 309 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The Podcast:...