8 ms·
Extracting the abstract syntax tree from GCC (2015)
- Ericson2314 6y agoIt's really depressing to see these people not believe copy left is enough, and think we have to main our programs and make them less composible in addition. Intentional impediments to code interopt are absolute heresy given my own ideology of free software, and I wish rather than being on the defensive someone would argue that more forthrightly. I hope in the last 5 years the situation has changed.
- kmeisthax 6y agoRichard Stallman's schtick with copyleft isn't so much to lock a particular program into a Free Software license, it's to use Free Software as a cudgel to demand licensing concessions from other software vendors. An obvious example of this would be GPLv3's anti-TiVo clause, although in that particular case there's a direct connection between locking down hardware and your nominal right to modify the software being practically curtailed. The bargain the GPL tries to strike is "you can do whatever you like with the program as long as you don't restrict the user's freedoms to use, distribute, or modify the program". GPLv2 only talks about legal restrictions to user freedom, v3 extends that to curtail technical restrictions, too. One oft-overlooked controversy is that of GNU readline. You see, RMS decided specifically to release readline as a GPL library so that anything that used it had to be GPL, too. This actually worked - for example, CLISP relicensed itself specifically to comply with GPL terms on readline. There's an old e-mail thread between RMS and CLISP's author, Bruno Haible, which I'm going to have to make an extended quote of as it's really telling: (quoted from https://web.archive.org/web/20131111095101/http://clisp.cvs.sourceforge.net/viewvc/clisp/clisp/doc/Why-CLISP-is-under-GPL https://web.archive.org/web/20131111095101/http://clisp.cvs....) Bruno: I could provide a libnoreadline.a and let the user choose to link lisp.a with either GNU's libreadline.a or my libnoreadline.a . Would that convince you that lisp.a "can be reasonably considered independent and separate work" ? RMS: No, and I doubt it would convince a judge either. I'll have to insist that you stop using readline unless you make the program free. Bruno: If someone was to turn the readline library into a shared library (a library that is needed at runtime by the executable, but not contained in the executable): Would that mean that any executable that uses a readline shared lib would have to be accompanied with full source? RMS: Yes. The sum total of what you are doing is still tantamount to distributing one program which contains readline but is not under the GPL. Bruno: So the only reason why you may object is that my lisp.a has an INTERFACE that allows it to be linked to libreadline.a . As far as I know, only the readline CODE is copyrighted, not its INTERFACE. (Would you object because my libnoreadline.a has a similar interface?) RMS: I say this based on discussions I had with our lawyer long ago. The issue first arose when NeXT proposed to distribute a modified GCC in two parts and let the user link them. Jobs asked me whether this was lawful. It seemed to me at the time that it was, following reasoning like what you are using; but since the result was very undesirable for free software, I said I would have to ask the lawyer. What the lawyer said surprised me; he said that judges would consider such schemes to be "subterfuges" and would be very harsh toward them. He said a judge would ask whether it is "really" one program, rather than how it is labeled. --- RMS doesn't entirely answer the question about interfaces, because he responds with an example about NeXT, but I can smell the same logic here. Bruno is asking if APIs carry copyright, and Richard Stallman does not say no. He specifically argues that the existence of a version of CLISP that can be linked with readline is enough to trip the GPL. This is dangerously close to the Oracle v. Google case, played out 30 years ahead of it's time on a private mailing list between two people who really shouldn't be fighting. The only reason why RMS doesn't explicitly say "yes APIs are copyrightable" is probably because... 1. Arguing against Free reimplementations is hypocritical - especially today when we have three non-GPL readline implementations. 2. Bruno decided to GPL CLISP anyway (because Linux was getting lots of contributions). I'm surprised the FSF hasn't commented on this case further, though I can imagine why. Seeing the absolute stalwart of Free Software argue in favor of Larry Ellison has been a huge yikes moment for me. In fact, one way to interpret Oracle v. Google (in the light of OpenJDK existing), is that of a massive GPL compliance lawsuit. Free reimplementation is how we got GNU and BSD; but RMS being any kind of right here imperils the right to reimplement... all so that Steve Jobs couldn't extend GCC.
- Someone 6y agoI don’t think you can conclude that lawyer said anything about whether APIs are copyrightable. I think that lawyer said “if you create that interface for the sole/main purpose to get away with having to license your code under the GPL, judges will consider it subterfuge”. It’s like arguing “I didn’t take a cookie out of your cookie jar. I turned the jar around and later found a cookie lying on my desk”. Saying that’s stealing doesn’t imply that eating cookies you find lying on your desk is stealing. I would think that, if a third party created a common interface to them to give users choice as to what UI they provide (releasing the GNU readline wrapper under the GPL, the BSD readline wrapper under a BSD license, etc), CLISP could say “feel free to replace the BSD readline we ship with with another one)
- jancsika 6y agoStallman is saying he's surprised-- probably in the same way many on HN always are-- that a judge would, you know, use judgment. I.e., one program that would trip the GPL chopped into two in an attempt to not trip the GPL part of the program which is still there! His lawyers are telling him the judge would a) see the part with the license the person wants to avoid, b) see the subterfuge to do an end run around it (in both cases they are asking Stallman directly abou it), and c) judge harshly as a result. I don't know if his lawyers were right, but that's the argument. With Google vs. Oracle, part 'a' doesn't exist. Google did a clean room implementation under the Apache license-- there's no Oracle-licensed software behind the curtain of the headers. So Oracle's only chance was to claim that an API is copyrightable. If it's not, that's the ballgame. But in the examples you gave wrt Stallman, API copyright doesn't matter-- it'd still be subterfuge to avoid triggering a license for the 2nd part of the program (at least according to his lawyers). Edit: clarification
- p_l 6y agoFunnily enough, the current state of the art in understanding GPLv2 is completely opposite (albeit disputed, see SFC vs Canonical on ZFS in Linux). The critical part is whether the software is derived, as that is the language used by GPL, and it can be hard to claim that optional line editor - as many other lisp implementations showed, you can really go far with dumb (loop (print (eval (read)))) However, RMS had an obvious agenda involved, and libreadline was one of the major cugels used by FSF for significant part of 1990s. There's a reason why the term "GPL virality" stuck.
- rektide 6y agollvm used to have a -ast-dump-xml that I used but it got removed in like 2009 or so. annoying. wish tools would free the information inside.
- johndough 6y agoThere is clang -Xclang -ast-dump=json -fsyntax-only main.c these days. Probably not exactly the same, but still very useful.
- Someone 6y agoThe best way to get that info nowadays likely is through libclang, but other options are clang plugins, lib tooling, or Clang tools. See https://clang.llvm.org/docs/Tooling.html https://clang.llvm.org/docs/Tooling.html for considerations on what approach to pick.
- touisteur 6y agoYes, libadalang, inspired by libclang, is 'it' for me. And I can write queries directly instead of parsing some intermediary shit and wishing I was after generic instantiation... I worked around gnat2xml but it's faaaaar better like this.
- yudlejoza 6y agoWait, wait, wait. I was going to point out llvm/clang, but they disabled that too? It's a BSD/MIT-license tool. Any idea why they did that? second big-picture question: how hard is it to code up ast (as long as the source language is not C++)? we have lexers, parsers, PEGs, what not.
- detaro 6y agoAFAIK the xml-ast was always just intended as a debugging tool for llvm developers, not an API for externals (and thus came with no stability promise). You always were supposed to just link against clang/llvm and use the APIs it specifically provides to access the AST.
- new_realist 6y agoJust another example of poor leadership from Stallman.
- jhgb 6y agoYep, it should have been GCC, not LLVM, that earned Apple more big bucks. Totally a bad decision.
- CalChris 6y agoApple used GCC for more than a decade. It wasn’t until LLVM came along that they had a viable choice and they took it.
- klyrs 6y agoYes and no. Stallman's asshattery created the need for a more flexible, scrutible, tool. We have LLVM now, the world is better off for it. Companies are free to extend it privately, and upstream bugfixes and features when it's in their interest. GPLv3 pushed many of us over to Apache or other more permissive licenses. Companies are free to develop software, APIs, and libraries that are free to use, extend, and repair without threatening their patent portfolio. The ecosystem is thriving, thanks to RMS's immovable opinions.
- staticassertion 6y agoThis just sounds like "yes" to me.
- emmanueloga_ 6y agoI remember reading an article about the difficulties of extracting AST from clang [1]. Even when there are less politics involved, seems like a hard problem. With GCC, the problem becomes an Stallman order of magnitude harder :-) 1: https://foonathan.net/2017/04/cppast/ https://foonathan.net/2017/04/cppast/
- pfdietz 6y agoExtracting ASTs from C (or C++) is difficult in general, due to the preprocessor. I really hate the C/C++ preprocessor.
- ironmagma 6y agoAnother reason I love Rust. It’s very statically analyzable.
- rdescartes 6y ago> Another reason I love Rust. It’s very statically analyzable. Proc-macro in Rust is very tricky to analyze statically, some are even impossible (due to non-deterministic behavior)
- Ericson2314 6y agoThat's moving the goal posts. The important thing is that macro invocations can be found "statically" (with out knowing the implementations of macros at all let alone evaluating). One way to look at this is that partial evaluation of Rust or Scheme macros is very tractable, because there are very few side effects / side channels. But if you have a lack of hygiene or the C preprocessor, it's very difficult and almost everything becomes a "stuck term" whose evaluation is contingent on earlier evaluation.
- varajelle 6y agoThat's true about the pure act of parsing and generating an AST. Bit once we want to do semantic analysis, this is no longer true. Because of procedural macro, it becomes practically impossible to find all occurrences or rename a particular symbol regardless of the #ifdef or #[cfg] or whatever.
- new_realist 6y agoFree software intentionally hobbled for political ends. For the best software, go elsewhere.
- jcelerier 6y agoGCC is literally the compiler that produces the fastest code in most cases
- petr_tik 6y agoWhile clang and LLVM is the set of compiler libraries that people write and extend developer tooling in: * clangd * clang-tidy * clang error messages * mlir And others
- staticassertion 6y agoSometimes. GCC is also far older - about twice the age or more compared to llvm. Do you think that your statement will be as true in 10 years?
- saagarjha 6y agoYes, since it’s been true for about the last 10.
- pirocks 6y agoMy understanding is that for Intel cpus Intel compiler is substantially better than gcc.
- jcelerier 6y ago> My understanding is that for Intel cpus Intel compiler is substantially better than gcc. It's not, except for super specific workloads. Intel's own Intel-CPU-optimized distro, Clear Linux, is built mostly with GCC as a conscious performance decision: https://docs.01.org/clearlinux/latest/guides/clear/performance.html#a-benchmark-approach-to-compiler-performance https://docs.01.org/clearlinux/latest/guides/clear/performan... ICC was for a very long time quite superior to MSVC tho.
- rijoja 6y agoSo why not just extract it? I mean it is open source?
- xyzzy123 6y agoIt's interesting to see Free Software try to enact the same kinds of moats (purposefully limited interoperability) as proprietary software to cement control of the ecosystem. All very "ends justify the means". "We had to sacrifice your freedom in order to save it". I'm more understanding of purposely limited interfaces for the kernel because of the support burden on maintainers caused by crashes from proprietary modules.
- froh 6y agowas such discussion possibly a driving force behind the creation of the language server protocol LSP? which created an interface between meta knowledge about code on one side and user interaction (ide) on the other? https://en.wikipedia.org/wiki/Language_Server_Protocol https://en.wikipedia.org/wiki/Language_Server_Protocol
- joatmon-snoo 6y agoLSP was a pretty inevitable development in software IMO- there are increasingly many codebases where local compilation is a nightmare and you need some kind of remote/distributed build system to manage it for you, and once you have that you need to push xref and indexing out of the IDE as well.
- imode 6y agoStallman is looking more like FOSS' Stalin every day. There's no technical justification or even an overtly ethical one to use GCC over libclang, Stallman's ego just needs stroking every couple of years. I long for the day that he stops making decisions.
- bumbada 6y agoI would say he is looking more like Lenin than Stalin: Having some ideal in his mind that he will apply no matter what. And people giving him authority like a God, everything depending on his opinion. Lenin had his perfect idea on his mind, that did not work in the real work, he exterminated most farmers that opposed its perfect system and made tens of millions of people starve, producing way less food than in the WWI(usually as you end a war your production goes up a lot). All because in his mind, it was perfect. Stallman is in a similar position with some people venerating him and using him as Messiah of the Pure Free software movement. But no single man is perfect or omniscient. Lenin was forced to give way or Russia would have collapsed 70 years before it did. https://en.wikipedia.org/wiki/New_Economic_Policy https://en.wikipedia.org/wiki/New_Economic_Policy With free software we don't really need Stallman or any other gatekeeper. We(our team) have been using LLVM for a long time because of that. Stallman is free to have the opinions he wants. People will just move on and use alternatives.
- Narishma 6y agoSo, has anything changed since?