How to Implement Your First Compiler Feature:The Story of Concepts in Clang - Saar Raz - CppCon 2019

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I watched this guy's Core C++ 2019 talk on the same subject which is also excellent.

👍︎︎ 18 👤︎︎ u/liquidify 📅︎︎ Oct 13 2019 🗫︎ replies

Slides here

👍︎︎ 14 👤︎︎ u/saarraz1 📅︎︎ Oct 13 2019 🗫︎ replies

That's an incredible achievement; I really hope you enjoyed the process, and I thank you for making our life easier :)

👍︎︎ 13 👤︎︎ u/matthieum 📅︎︎ Oct 13 2019 🗫︎ replies

I read it as "one point twenty-one jigga-bytes! Great scott!"

👍︎︎ 8 👤︎︎ u/cfraizer 📅︎︎ Oct 13 2019 🗫︎ replies

hope some day static_print will be avaiable in clang too..

👍︎︎ 7 👤︎︎ u/arturbac 📅︎︎ Oct 13 2019 🗫︎ replies

Great talk! Thanks /u/saarraz1 for sharing your experience in implementing this non-trivial feature :-) So, what does the roadmap look like, will this be included in Clang 10?

👍︎︎ 3 👤︎︎ u/bandzaw 📅︎︎ Oct 14 2019 🗫︎ replies

Great work and great talk! I am looking forward to using this feature. Thanks!

👍︎︎ 3 👤︎︎ u/smookiechubs 📅︎︎ Oct 16 2019 🗫︎ replies

Sometimes you can abuse compiler errors and compiler warnings to print the types.

https://cukic.co/2019/02/19/tmp-testing-and-debugging-templates/

👍︎︎ 2 👤︎︎ u/huixie 📅︎︎ Oct 14 2019 🗫︎ replies
Captions
hi everyone thanks for coming my name is SAR and today I'm gonna be walking you through how to implement your first compiler feature by telling you a bit about my story implementing my first compiler feature concept in Clank I'm gonna first make it quick quick like overview of what concepts are if you're not familiar but the talk is not gonna focus on concepts but rather on the story on my story and mind both of them so it's a quick overview first thing new in in concepts in C++ 20 is the requires Clause safe before you had this sort function that's like the canonical example for concepts that accepted a type name and beginning in iterators and they could just mean anything now you can constrain them by adding requires Clause right after the template parameter list with a name of a concept for example here I'm requiring these to be iterators another new thing you can do is add abbreviated templates this and this now means the same thing can write auto instead of the template parameter type and it'll completely omit omit to the template parameter list and a template keyboard you can you can articulate static requirements using concepts on a set of types or just one type for example here I can say the large concept is anything that whose size is any type whose size is more than ten and can even make more elaborate concepts using the new requires keyboard it requires expression excuse me for example here I'm requiring that the T type well the t-type has a food type inside of it and you can do if you have a tea object and a you object you can do tea dot foo give it you and get a food type you can also increment T sort of requirements that you can express using the requires expression and you can also prefix the auto keyword with the name of a concept and and optional arguments can you please use your mouse cursor because the laser pointer is not recorded and it's not visible in that screen okay okay so you can prefix the auto keyboard with the name of a concept with optional arguments like this this means that means that anything that you give to the doufu function must satisfy full with int for example it must be incremental and have the ability to do tea tofu and give it you cool one of the primary reasons concepts were introduced is to have nicer error messages for example if you would try to have your own class a and give it as a key to unordered map this would happen okay and this is a relatively good relatively like easy case and with concepts you could get something like this telling you that a is not hashable and it's pretty readable and explains exactly what went wrong instead of giving you a very long error message drilling down into the internal implementation of the class you are misusing another cool thing you can do with concepts is overloading you can for example have having the sort function here you can actually you can actually also write the name of a concept instead of a type name keyword and have it means the same thing like before what it requires and you can also for example have another version of sort and overload them based on the concept and here if you would call them if you were to call sort with a random access pair of iterators it would know to select the second one because it is more specific okay that's like that's what this was a short overview of concepts the main features of the new language feature is he plus 20 but this is not gonna be the focus of this talk it's cool so about me my name is Sarah and I'm 25 from Israel I like programming graphic design and video games and basically relearn C++ in 2015 fell in love with it ever since and I have been working on the Klang implementation of the concepts feature in the past two years and I'm gonna be telling you about this story so the best way to describe this story is this is this was a very slippery slope it started with me trying to write a game engine just for a fun educational project and it involved a lot of generics and things were getting a little bit out of hand and at the time concepts had an implementation in GCC seven and knowing what concepts were I knew that if I were to write a lot of generics they would probably be of great help to use concepts so I was I was like ok gc7 wasn't even now back then it's probably still buggy and not sure if anyone maintains it hopefully fine just start using it so I built GCC seven and started writing a lot of code with concepts as like if it was the future so before I had this function okay this past message function here that takes a bunch of template parameters which you know nothing about what is this like propagate last parameter what does it even mean basically like writing this auto auto auto auto auto now with C++ 20 strong typing I could do something like this and actually specify the types of all of these generic parameters and actually have an idea of what this function does when looking at it which is a nice feature cool so there's really no turning back after you start using concepts I'm sure you're gonna agree with me once you do and they all lived happily ever after until I found that GCC concepts did have bugs and but but you know once once once the compiler how's the bucket tells you to report the bug and you can just go to the bug tracker and report it right so I reported this bug and as you can see the date this was the last time I've heard of this 20:17 so turns out this this branch was not heavily maintained at the time and not only that I've had some some problems using GCC but not just ECC I had a bunch of my as I've said I've had a bunch of templates and my code and compile times enormous it just started getting a bit out of hand for example I had this an indicative error message and accusations of murder like this one and have I had this one time I had this very another an indicative error message it happened when I tried to compile the project don't ever try this this is super game dangerous and it froze the whole PC froze okay the kernel frozen nothing the mouse won't even move at that point so I thought maybe okay maybe this was a very long error message so I used F max errors equals one do you know this flag it just makes the compiler stop it's trying to emit more error messages after it encounters the first one by default the compiler will just try to give you more as most as much error messages as it can give you so this still ork tried to uh put the message to a file and it still doesn't doesn't work so I thought okay maybe this is a problem with Windows and was using cygwin maybe it's a cygwin problem of some kind so I moved to Linux VM and it freezes again and the host freezes as well well this shouldn't happen it turns out I had a BIOS problem but never mind okay so I put the message the error message to a file and it didn't freeze and I had a file with the error message in it okay this is like huge it was 1.2 gigabytes so you might be wondering what this was with F max there is equals 1 so you might be wondering what do do those 1.2 gigabytes of error message say well how do you read 1.2 gigabytes of air well some of the text editors do open this like sublime text for example and it turns out this was only 10 lines of error message each each of them having about a hundred megabytes of error and they were basically something like this just template back trace listing okay I had this function by with these a hundred megabytes of template parameters of template arguments which tried to call function bars with these 100 megabyte of template arguments and was the ten lines of this okay you can actually limit this the depth of this template back trace but you do need but much of the information there to actually understand what went wrong because there was like a bad series of calls somewhere yeah people complain about like an indicative error messages C++ gives them I couldn't even read mine so so the the way you chose to go about this was to parse okay I started writing this Python script that it would take this this template back trace and collapse all the elaboration of what like for example what TSU would collapse it to just like one in you to two and you could like click one to expand just one level of what T is and to to expand just one level of what us and just do it incrementally to read whatever you actually need to read so this doesn't work why no because python is too slow so I moved to C++ and and it worked after I like heavily optimized the bit C++ script and I got the bug and a few daily days later that PC freezes again with two gigabytes of error message and the script can handle this anymore so I tried I started looking for other solutions for example I noticed that the long name templates actually compile time trees so they had each type name with something like this only like 90 megabytes or something so how can we shorten these names okay nice okay so the thing you can do is really create a new class my tree that inherits from all this monstrosity and inherit the constructors so what you get is a new class that acts exactly like the previous one only it has shortened shortened names in the error messages and given this it worked and emitted only 400 megabytes of fare message which is like a piece of cake for the script and cool so then I was like every like inheriting from every template like this is a pain and you can it's not a long term solution and I sometimes even don't even need all the information I just won the compiler to print 10 these 10 lines of like calls of back-trace of calls and it seems like there is no way to actually get the compiler to do this do not prints all of these annoying of this annoying data so then I took a look at the error message I'm getting and you see the interesting word here has an emoji next to it so I saw this keyword with and I went with it and open up the DCCC binary okay and if you can see over there it's probably hard to see from back there but you can actually see that lately you can actually see the whiff keyword over here in the binary okay so this is the function which prints all of these hundreds of megabytes of error message so I just patched it to return and and this is now and now it printed out their messages instantly and I had no problems ever since so yeah this was like my first time messing with the actual compiler so I I was like okay if I'm already patching GCC I had this other problem which I couldn't get around which is what which was that I needed to debug a lot of compile time things I had a lot of templates and there was no like proper print debugging at compile time so I was thought I thought to myself let's add some print debugging at compile time because like print debugging is one of the most important tools we have as programmers so how can we met a program if you don't have meta printing so I'd open up GC sources and good thing GCC sources are so nice for example here is parser C which parses all of C++ and as you can see it's a light read and there are bigger files and maybe they've gotten bigger since I've checked if this picture well so my idea was to add the keyword static print the keyword would act like this you would just stick it somewhere and give it a bunch of string literals and other compile-time things and it would print and by compiling this it would print out the strings and the compiled time things for example here you get you you ask it to print deckle type of lie and it would print test int 3 wise type is test in 3 while you were compiling the program not while you were running it so how do you add a keyword to C++ well I did take compilers class back in university and I know that there's probably a nice little file that defines the grammar declaratively and I can just go go in there and add the new keyword right with the syntax and everything well the real world isn't so pretty and well maybe C++ world isn't so pretty and it's just functions all the way down that parse the other thing so what do we do now so I had no other way to handle this and I went with copy paste copy and paste and I had this observation that static print behaves awfully similar to static assert and I'll try to convince you about that it can appear in the same places which is basically like everywhere and it also parses string literals write static assert has an error message that it can print out and we need to like string literals for printing during the static print and it also starts with static underscore and is pink in the slides so the plan was like this search the whole sources of GCC for static assert fine wherever the keyword is being parsed and where it is whatever it is just duplicate it and rename it to static print and do this recursively ok let's see how this goes I found this thing this is a list of was sort of an array of structs and i saw these people post keywords over there one of them was static assert and it had a bunch of other things in there i just duplicated this line and renamed it the static print there was our ad static assert we named it to our ad static print there are a couple bunch of other flags in there that you seemed okay so I kept them and then I did this with our ad static print which I knew now needed to find I found this enum listing our ID static assert added an RD static print right after it then I searched for other uses of Rd static assert and then I found this piece of code if the next token is static assert we have a static assertion and this if the checks whether you have an RD static certain calls CP bar so static assert so if the next token is static print we have a static print statement and call of course CP bars or static print we still need to write that function so now we reach the business logic itself CP parser static assert this is the whole function I'm gonna highlight the interesting bits of it for example here you can see that they're looking for the static assert keyword because there was a comment that says that they're looking for the static assert keyword there is a string literal parsing like we expected cool and here they're parsing a constant expression which is nice but not enough right we wanted to be able to give this thing anything not just constant expressions but also types or template names something we need something more general than this for parsing our static print statement any ideas where we can find something that can give us the thing we need [Music] what what else in the language can be both expressions and types and template names template arguments that's right so I found this function CP parser a template argument and I just used it I arranged a function to look just like picking and choosing the right things from static assert using CP parser template arguments for the arguments and it worked and I compiled the first program using static print but then there was a bug this code does not work and I'll give you a hint if you check that's if you try to print out whether size of t is equal to 3 it does work yeah okay so so we use CP parser a template argument to parse this the size of T is greater than 3 and when it sees the greater than it says ok that's the end of the template argument and doesn't continue to parse anything the lesson learned here is that copying and pasting may break some hidden code assumptions and so when you use some functions you see somewhere try to like please figure out whether there are these hidden assumptions in the code and try to adjust for that somehow and ok now it really worked I mowed it modified CV parser template arguments a very hacky solution and but now it really does work and I could like print debug my own code at compile time which is pretty cool then I thought to myself maybe others would like to use use this as well so I had 4 options as its as I saw them back then first one was just to use it to myself which is no work which is always good second option was to publish the dot patch file so people can download GCC sources apply the patch then build it for themselves and have static print in their own code which is probably a day's work roughly I could try getting this merged into GCC which was a month's work and might not be accepted because this is non-standard and I'm not sure I could promote propose this to the standard just like two years and there were already already some other proposals like this in circulation so I went with number two seemed like a reasonable compromise so I posted this reddit post saying that I had this new static print statement you can print debugging do it you use print debugging during compile time then this is what this person seemed upset about this turns out I was cheating anyway also it got featured on C++ weekly and pretty cool which was pretty cool and I also published the patch file to github and can you see the problem here yeah that's right there was an issue even has a red circle over it what was the issue build fails at stage 2 so something something something that I couldn't build this because it fails during stage 2 what is stage 2 let me walk you through what which bootstrapping is saying say new version of GCC comes out ok with new optimizations if you compile the new version you get a compile of the compiler that builds faster code right but the compiler itself was built with an older compiler so the compiler itself is slow but can you do compile the compiler again with itself and get fast compiler that builds fast code this is stage 2 but maybe your optimizations broke something so you compile it again and check whether you've got the same result as stage 2 and this is stage 3 this is a tldr if you didn't get it so what was the problem how come compilation failed only on stage two and not on the stage one well we hadn't we added a new keyword right static print and in stage one we use the compiler without that keyword and I had a local variable means static print so in stage two using static print as a variable name is an easily is a syntax error and this is why this failed and I just changed the variable name and it just worked cool so what now I also have used static print to like profile my long compilation times I would like trace place a static print before a big template then call a function that instantiates the huge template and then place another static print after it like a poor man's profiler and crank had some sort of a template profiler but clang had no implementation of concept so I couldn't use it and it was still pretty slow and also TCC had this page on their website saying we know our compiler is slow and we need to take care of that of that someday so that wasn't very uplifting and some say clang is faster so I had four options as I saw it back then first option to drop the project entirely which is no work which is always good second is stop using concepts which is like a week's work and the lifetime of regret optimize DCC know or implement concepts in clang myself which was like a month or two so I went with the last one this this was my line of reasoning back then really so yeah concepts in clang someone's probably done it already right let's Google that so I found this concept clang an implementation of super fast concepts and clang sans reason right well what's the problem here yeah can you see the year turns out clang is very quick the implemented concepts nine years before they revert it into the standard so and if you check out take a look you can also see that the syntax here is pretty weird it doesn't look anything like what we have today and what what what what what like what it turns out is that and also found this little article by B RNA concepts were previously merged into C++ 11 and were basically ripped out before C plus 11 was published and this is a three-page article in which B RNA explains why this happened and why it's terrible and very sad so this implementation was outdated I also found some this page that about that lists clanks standard support and under concepts didn't really say whether it was work in progress or not just linked to this paper and this mailing list someone tried to ask what what like what's the status of concepts I see that it's working progress but I don't know if it's like we're just testing some last things out or it's on the to-do list and someone replied that the client concept development is occurring on trunk so I downloaded crank trunk and built it turns out we even like clang even had an F concepts TS flag that you could pass in to an able concept support pretty cool but it seemed to just like parse requires clauses and ignore them anyway it seems like no substantial work has been done at that point so this was a point where I had to like had this really as a realization that I'm not a compiler engineer okay I've never done anything related to compilers why would the Clank gods even let me work on their compiler and so I had this plan to overcome all this I would just implement the whole feature without asking anyone this is step one step two show up at clangs door with everything implemented and they just accept me and merge it so I started working and how hard could it be right just a bunch of error messages concepts but how do you implement a C++ feature well where do you even start implementing something like this well remember this that paper over there well I don't know if you ever if you've ever taken a look at the C++ paper but they are basically diffs to the standard text okay so this is an excerpt from the concepts paper it's literal diff to the standard text for example here you add concept to the list of entities you remove the or there and add or concept to the end it's a very just add if this diff is 36 pages long compared to the size of the standard it's not a lot but this is still a pretty big patch so I said okay let's start slowly and we'll just add the concept definition seems easy enough this is how its defined in the paper you have the template head and then the concept definition which is the keyword concept then a name then it equals token then it comes accountant constraint X expression which I guess is just an expression how do you add concept well I'm gonna use the only tool I have in my arsenal right now which is copy and paste and I would I will search for something that looks that for I just I'll search the whole project for a file named template something and I found template deckled LH and it had a class named template deco in a bunch of other classes in hurting for and from Rita Clarabelle templated echo which I assumed meant something with ridiculous or you would declare a template than define it later concepts don't seem to be read Eclair Abel according to the syntax so I just inherited from template echo and this is roughly how it looked like so I start a constraint expression using an expression pointer because that's how it seemed things went there I had all these parameters being passed to template deckle and a constrained expression also had to create and create the serialize because all the other cool kids seem to seem to have them around all the other classes how to get her and set her because why not and about a bunch of other boilerplate that you need for classes in the ast and a bunch of other friends down there because everybody seemed to be friends with these classes yeah so I had no real idea what all of these were but I just went with it at that point so now I want to parse this thing well first I won't get my goodness make this compile okay so I just search for something that's roughly similar to a concept and try to add concepts to all these places what's like roughly similar to a concept variable templates that's right and there's this VAR template deco looks pretty similar right so yeah a bunch of matches so I do this for a while had to go through all men are weird stuff like a ste dumper SD reader is the writer a bunch of mentions of var templating non code files like this okay so there's a VAR template over there so I just added concept down there to look that and make it look make it made it look believable and a bunch of switch cases and like handle all the things and I just added concept down and it compiles okay this was amazing and now I wanted to parse this thing and following our template deck around was pretty tough so I went with something simpler just follow the template keyword and I found this this is a diagnostic that says something about templates and and it sits in a function named parse template parameters seems pretty promising because it's supposed to be close to the actual parsing of the concept keyword and I went up and I found this we just check for the template keyword then parse a template parameter list pretty cool then down the line I had parsed single declaration after template seems very promising I just left this it for there if we have a concept keyword just parse the concept definition and parse concept definition again pretty simple I just saw looked around and saw how people check for keywords how an expression is parsed used parse expression and consume the semicolon in the end and then I called act on concept definition because everything around me seemed to do the same thing in the end all the parse method and it worked concept the concept was parsed but then there was a bug the following code compiles what's the problem here there's a there is no B right so what this compiles but what does it do right it's pretty surprising well spot the bug yeah well I do check it no no that's actually but but the bug is there in the parse expression and I don't know how you missed this but I should have called actions not correctly typos an expert on parse expression and not just parse expression of course so yeah turns out when you try to use parse expression and it encounters in non-existent identifiers it just tries to guess what you actually meant and returns that expression treats it as a typo so it actually returned a here and act calling correct delayed typos and expert causes the diagnostic to be printed but if you don't do it then it just doesn't get printed and your program compiles fine so yeah there are a bunch of unwritten rules in the code base and there are some things that you're probably not going to know until you use them and incorrectly and debug the consequences and like for example a bunch of stack objects you need to instantiate layering why you need both a parse concept deckle and acting concept deco and concept deco create and the constructor of concept deckle and this is a this is actually a point for copy and paste because if you actually read code that does something similar to what you want to do you would find out all these rules and save yourself having to discover them in your own so a good strategy when you try to implement something is to always find something that's roughly similar to what you want to do and see how things like this happen in the codebase and yeah another thing that that happens here which is like a very important principle in compilers is that there's no quit outs when you're compiling if you if the user made a mistake you're gonna try to you're gonna fire an error message but then guess what he actually meant and sure and continue compiling as if he actually did it which is a which is a which one which is what allows the compiler to keep compiling even though you did something wrong another another nice principle that you can use is that is the following this is a trailing return types index okay so which is correct this one flexing the requires Clause before the trailing return type or placing it after the trailing return type no it's actually the second one but user users are still gonna get confused about this and in practice I just try both ways and accept both of them just issue issue an error message if you get them wrong so yeah as a compiler you need to try to defend the user from the standard which he can read and try to account for common mistakes I need to expect the unexpected another thing I learned the hard way is that every word using used in the standard is there for a reason and cutting corners almost never works and almost always ends in death for example here say I have these two overloads one of them requires that size of t is larger than one and one of them requires that size of T is both larger than one and larger and equal to four and then I calls through of int which one of these should get called second one right yeah the second one should get called right but this actually doesn't work okay this is ambiguous why is that well let's see the standard to atomic constraints are identical if they are formed from the same expression and the targets of the parameter mappings are equivalent this is the same expression right size of T is greater than one appears in both places okay so why isn't it the same expression well it's the same expression but not the same expression when you say expressions in italics you actually mean the grammar rule expression and because they are derived from different places in the source this means they are not equivalent you have to actually go ahead and place the size of T great little one in a concept in order for this to work so yeah I've had numerous bug reports complaining that this doesn't work for it actually it is invalid to do such a thing but nobody in the world is going to know this so in practice I try both ways and complain if the user probably got it wrong anyway I continue like copying and pasting my way around the feature for example how would you find the place to place the actual checks that the constant the concept is satisfied for a given set of arguments you can I'm gonna interest of time I just search for the error message produced when for example give the wrong number of template parameters of template arguments okay those specific error message it gets emitted just search for it and then I find the place that checks whether a given set of arguments matches a given set of parameters okay that's a cool little neat way to find the place you need to find and I finish most of the feature in about about a month's work okay so what now so I have most of the feature implemented at least that's what I thought and I was just about to show up to the Klang community with my patch ready to merge then I saw this little page on the LLVM LLVM developer manual saying we have a strong list dislike for huge changes and long term development branches and also a friend warned me how how hard it is to get getting stuff merged into LLVM well Plan B instead of just showing up with a patch ready to merge I would just break what I did in to commit size steps of how I would theoretically implement concepts in claim and just show up with the plan instead so I did it I created this repo client concepts road map listing the steps required in my opinion to implement concepts in claim and then there was the moment of truth one of the most stressful emails I've ever sent explaining a bunch of things that we need to implement concepts right now and it's really not that hard can be done in a month or two and we have this I have prepared this road map and if you really want I can also do it myself then I got an airmail thing I'm not on the I'm not on the mailing list so I can't even send mails there then I joined the mailing list then Richard here replied saying thank you for offering to help out we were actually looking for people to implement concepts we want to do it but we know when I had the time to devote to the task also Hebert which was also involved saying yeah we just needed people with time to actually go ahead and implement this so yeah great success and yeah I was basically preaching to the choir they wanted to implement concepts and had no had no one to do it so and then I get and they got this reply saying I want to help you implement your roadmap I've already finished point one and I'm working on two and three if I have any questions I'll let you know and it was like whoops was not appropriate time to tell him that I already have the thing ready and then four months later I realized why small commits are a good thing and it turns out that actually implementing and testing this correctly takes longer than just I believe a month of Dhu and after about four months doing this in my spare time I reached the same point I had before sending that email but with like properly tested patches and a few people on reddit suggested that I get this up on compiler explorer so I send an email to Matt and he put it up there a bunch more people copying copying my steps later then I wanted to let the world know that someone is implementing concepts in clang and there's hope so I send this reddit post which was pretty cool but what what's wrong with this post yeah yeah there's a typo which I only noticed recently recently but there's something fundamentally wrong in this post no well maybe can you see it now yeah I'll publish this on April 1st yeah anyway lesson learned all I had left at that point was requires expressions the new expressions that let you express static requirements seems easy enough right well no it wasn't so easy probably one of the most complicated expressions ever but I parsed it after like eternity and now the compiler was feature complete and I had another post not on April Fool's letting the world know ever since I've been fixing a bunch of bugs them that people in the concepts and ranges community reported once he would be slack but then in November I had this reddit post that they merged a new syntax into the concepts working draft yay yeah so it wasn't feature complete anymore but actually I finished this feature just recently now I am feature complete according to the standard and I'm right now working on fixing CR comments a bunch of issues that I still have and merging this into trunk I have a bunch of commits waiting I have one of them merged already but I've been working on my talk a bunch of a bunch of time recently so probably will get more time to work in this soon and how do you implement your first compiler feature now have this formula which is basically my my experience here you start out like the the basic thing you need to do when you try to implement to compile a feature or how it usually works when I tried to like implement if even a part of concepts for example I start by reading a bunch of code could be the code needed to be changed understanding the the code around the thing the place we need to be changed or code doing similar things and there's probably always a code that does a piece of code that does a similar thing to what you're trying to achieve somewhere in the code base and then you come to the part where you you know what you need to do but there's a bunch of ways to actually do it and they vary by by where they are where it is that you want to actually implement the change where in the compiler where in the compilation process there's usually a bunch of places where you can actually place the change and sometimes we get to a place where you know you can change it here but you don't have the required information to actually do it and how to get like information from this part of the compilation process down to here and like the alternatives may vary and how difficult they how difficult this way of implementing the changes is going to be or not and then you're going to implement the simplest alternative requiring the fewest changes or breaking the current code then the tests are going to fail then you debug them then you understand why the alternative you chose is bad then you go back to then you go to the next alternative after you exit the loop you put it up for CR and go back to step one F then you let users find bugs then you go back to 1 e so yeah it's a lot of the challenge then profit a lot of the a lot of actually I love the work here is handling a very large very complicated code base and a like a very good way to actually manage this is to first realize first hacking all compilers is fun it's it's not very it's not this insurmountable code base that you can't even open it's just another C++ code base doing some complicated things but it's still C++ and it's very it's pretty fun thing to do anyone with the ctrl key can do it and the the way to approach this is be my Eve at first try the simplest solution and you're probably not gonna nail it on the first try but you can always learn from your mistakes which is the best way to learn probably and from CR you need to search really hard for developers manuals I've had some very long hours of debugging that could have been saved if I had found the relevant and developers manual I did search for some but I didn't search hard enough realized that everything in the standard is there for a reason and there's no cutting corners and in general will take a control of your compiler you're gonna probably run at some point into a place where you're limited by what your compiler can do just know that it that it's not that it is possible to change that whether it's giving you a nicer compilation or message and errors or implementing a nice little feature that you need for your project or implementing a C++ 20 feature the fastest way to get superfast wedding is to implement it yourself it's not necessarily very fast way to get it but it's a fast it's probably the fastest way so yeah that was the story of concepts in clang and I hope you realized how you could implement your first compiler feature thank you thanks for the for the talk you said you implemented it in one month in one month of full-time or part-time work like part-time but like all-nighters so how do you combine full-time job with part-time work on this kind of feature how many hours a day understands I had like I had some periods of time where I would like not working this at all and then like a month where I had relatively small like other things to do amount of thing to other things to do so I like putting in three four hours a day more questions great talk what happened to the work of the compiler writer who was also implementing concepts he he quit after a couple months didn't have time for them yeah thanks a great talk just one comment which is this is not just how to implement your first compiler feature this is still what I do for every compiler v4 implements thanks cool thanks for the comment I apologize if I missed it but is there a place we could grab a binary to try it out concepts in clang mm hm yeah you can visit my my github and there's instruction the instructions there how to build it thank you for the talk that was fantastic um I think it's important to note that the person that just said that's what I do for every compiler feature was Richard Smith the editor of the ISO standard yeah and implement our most features and Clank any other questions well thank you [Applause]
Info
Channel: CppCon
Views: 16,274
Rating: undefined out of 5
Keywords: Saar Raz, CppCon 2019, Computer Science (Field), C++
Id: Y1o4rc9P1FQ
Channel Id: undefined
Length: 54min 54sec (3294 seconds)
Published: Sun Oct 13 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.