7 ms·
It's great that they are aiming for an automated conversion from C to Go. It's clear they aspire to convert their code which was written in a certain way. But
by Shamanmuni 12y ago
It's great that they are aiming for an automated conversion from C to Go. It's clear they aspire to convert their code which was written in a certain way. But I think it would be a huge boost in Go usage if they could eventually aim to transpile any C code into Go code.
A little dream of mine would be if in the future when Rust is stable Mozilla developed a transpiler from C++ to Rust. That would be brilliant.
By the way, all the other talks at GopherCon seem pretty interesting, I hope someone uploads videos of them soon.
- NateDad 12y agoIt has been stated that there will be videos available, but I'd not expect them until next week sometime (when the organizers get home and have recuperated).
- jerf 12y agoIt is unclear how one would compile arbitrary C code into useful Go. The stereotyped conventions of well-written compiler code allows for a more idiomatic translation than a general translator could ever aspire to. C++ to Rust would be even crazier. (Transpile is a silly word. It's "compile". Compiling already trans-es.)
- stcredzero 12y agoGood automated translations involve matching and translating the project idioms. This results in code that fits the target language's language-idioms. Automated translation only at the level of language constructs results in odd looking generated code.
- Shamanmuni 12y agoI know it's crazy difficult to do it, that's why I was talking about dreams. But maybe a set of guidelines about translatable C code plus a translator which is good enough for a variety of cases would make refactoring the resulting code such a manageable task that many projects could consider switching to Go directly. You are technically correct in that compile already implicates a translation, but we usually use that term refering to a translation into a lower level language and not another language at the same level. You can say transpiler or source-to-source compiler for those cases and I think it's clearer and more accurate for the reader.
- yohanatan 12y ago> ... but we usually use that term refering to a translation into a lower level language and not another language at the same level. Rust is not lower-level than C++ and neither is Go lower-level than C.
- mseepgood 12y agoExactly. Hence "transpiler".
- yohanatan 12y agoWhat part of his definition didn't you understand? He said a transpiler trasnlates from a higher-level language to a lower-level language. We are talking about translating from C -> Go and C++ -> Rust both of which are in the opposite direction (i.e., low -> high).
- mseepgood 12y ago> He said a transpiler trasnlates from a higher-level language to a lower-level language No, he said a compiler translates from a higher-level language to a lower-level language: "You are technically correct in that compile already implicates a translation, but we usually use that term [= compile] refering to a translation into a lower level language"
- yohanatan 12y agoAhh, my bad.
- yohanatan 12y agoThis should not have been down-voted. We are talking about translation from C -> Go and C++ -> Rust (which are both in the opposite direction of the definition given for 'transpiling').
- 12y ago
- mwsherman 12y agoThe use case is to bootstrap the conversion from C to Go, if one has made a decision to do so. You pick a cutoff time, and say “now were going to do our work in Go”. What comes out the other end, as Russ phrases it, is a C program in Go syntax. The next phase of work is to turn it into “Go” as a human might write it. The translated program is not meant for deployment, really. It’s to give the humans a starting point.
- kodablah 12y ago"a transpiler from C++ to Rust" I think the best approach for something like this is a disassembler for LLVM IR. I am not extremely familiar with the LLVM IR, but I figure there are common patterns or debug symbols clang produces that could let you get a decent idea of what the higher level gave you. If not targeted to clang output too much, you can then transpile any LLVM-able language to Rust. I think, but am not sure, that the problem with Rust being a target for these other languages (my pipe dream is to write a JVM in it w/ a JIT using the bootstrapped rustc lib) is that you have to use unsafe code all the time (unless there's 0 performance penalty for ARC) because the original code is not written with ownership/borrowing semantics.
- sanderjd 12y agoI think there are probably lots of chunks of code that would be perfectly valid under Rust's ownership semantics and could therefore be transpiled safely. Figuring out which chunks are and aren't would probably be quite difficult though.
- wtetzner 12y agoOne approach might be to just convert to Rust, and let the Rust compiler tell you what things don't type check.
- Someone 12y agoReading https://docs.google.com/document/d/1P3BLR31VA8cvLJLfMibSuTdwTuF7WWLux71CYD0eeD8/mobilebasic?pli=1&viewopt=127 https://docs.google.com/document/d/1P3BLR31VA8cvLJLfMibSuTdw..., I don't see that they are aiming for an automated conversion; they are aiming for an automation-assisted conversion. They want to go quite a step up from doing some global regex replaces, but in the end, step 3 has "cleaning up and documenting the code, and adding unit tests as appropriate.". I don't think they aim to automate anything there.