
Go in Go - zdw
http://talks.golang.org/2015/gogo.slide
======
fizixer
Fun fact: what's common between Rob Pike, Bjarne Stroustrup, Larry Wall, Guido
van Rossum, and so many other language inventors?

They're all C programmers!

~~~
danieldk
_Bjarne Stroustrup_

Wasn't CFront written in C++?[1] (Of course, the initial version of C with
classes was probably written in C.)

[1]
[https://en.wikipedia.org/wiki/Cfront](https://en.wikipedia.org/wiki/Cfront)

~~~
ExpiredLink
Probably the only C++ program he ever wrote.

~~~
72deluxe
Bjarne has written numerous C++ programs, has he not?

~~~
72deluxe
Out of curiosity to the downvoters, has he NOT written C++ programs? Was his
paper in IEEE the other year calling for more static code (let the compiler do
its work) and abandonment of the dynamic_cast "let's check at runtime!"
development model something he pulled from thin air? Or has he actually
written code?

------
Kurtz79
Unless I missed it, it is surprising the lack of benchmarks or mentioning how
compile speed compares with the previous iteration.

I'm not saying it would be necessary slower than a compiler written in C, if
they wrote the more critical parts in assembler, but you would think compiling
speed would be one of the outstanding discussion points, after a major
rewrite.

~~~
bojo
Does the speed it takes to compile the compiler really matter?

Edit: Of course, faster speeds would be interesting to hear about, so great
question.

~~~
gsnedders
"We believe it's worth trying again with a new language, a concurrent,
garbage-collected language with fast compilation."

Fast compilation is an explicit goal of Go, so they certainly think it
matters.

------
andrewchambers
I am most excited for the new SSA backend in go. I have been following commits
to it here:

[https://github.com/golang/go/tree/dev.ssa](https://github.com/golang/go/tree/dev.ssa)

No idea how long it will take to mature, but I hope there are some decent
performance improvements once it is fully functional.

~~~
Spiritus
SSA?

~~~
andrewchambers
Internal graph representation the compiler uses for programs. llvm uses SSA
form of programs as its main low level representation. The benefits of SSA is
that it enables some analysis and optimization techniques.

~~~
seanmcdirmid
It is basically a simplification that makes optimizations easier by
eliminating re-assignment of local variables (where possible, for loops and
conditions, merging phi values might be necessary). It has been awhile since I
played with this, but it made CSE (common sub-expression elimination) really
easy.

------
comboy
Oh, I was hoping for some go (aka baduk or weiqi) playing program written in
go. These are a bit tricky to google ;)

~~~
FlailFast
Finally, my moment! I submit my own library, which is really meant for two
players and scoring...and like much of what I do, was purely pun-driven. Maybe
one day I'll add AI:

[https://github.com/acityinohio/baduk](https://github.com/acityinohio/baduk)

~~~
erikb
Have a look at the Go Text Protocol [1] and SGF [2]. If you add these then the
strongest existing AIs can already play on your board.

All that said you can of course write your own bots, but Copmputer Go isn't as
easy as one might think. In fact it's still considered a much harder problem
than Computer Chess.

[1]
[http://www.lysator.liu.se/~gunnar/gtp/](http://www.lysator.liu.se/~gunnar/gtp/)

[2]
[http://en.wikipedia.org/wiki/Smart_Game_Format](http://en.wikipedia.org/wiki/Smart_Game_Format)

~~~
FlailFast
Ah awesome! Thanks for sharing. Definitely going to add this on my to-do list;
would love to add some already-made AI to it. :D

------
pjmlp
> Getting rid of C was a huge advance for the project.

> Code is cleaner, testable, profilable, easier to work on.

This is just great!

------
krzrak
Looking at the title, my first thought was that somebody is making fun of all
those posts "[something] in Go" ;)

------
haberman
There is no slide about writing the GC in Go.

How do you write a GC in a GC'd language?

~~~
Zikes
Slide #9 mentions they use the unsafe package in the GC to deal with pointers
as raw bits.

~~~
haberman
But does the GC run on the GC's own runtime data?

Can the GC be interrupted by itself if it takes too long or uses too much
memory?

It seems like there are several things about the GC that would need to be
special-cased, since the GC is implicitly invoked by the runtime.

~~~
kinghajj
I would assume not. GCs are typically invoked by requesting allocation. Since
the GC (presumably) uses lower-level OS facilities to allocate memory, it
wouldn't need to recursively invoke itself.

------
bottled_poe
Can we trust the go compiler?

edit: This is the link I meant -
[https://www.ece.cmu.edu/~ganger/712.fall02/papers/p761-thomp...](https://www.ece.cmu.edu/~ganger/712.fall02/papers/p761-thompson.pdf)

~~~
scscsc
i.e. can a bug that existed early in the toolchain history propagate in the
binaries but not the sources?

c_i is the i'th version of the compiler.

    
    
        c1 c2 // c1 compiles c2
    
        c2 c3 // c2 compiles c3
    

Source code of c1 has bug, source code of c2 and c3 is fixed. Bug in c1 causes
binary of c2 to have bug. Binary bug in c2 causes binary bug in c3.

------
zatkin
I really like the slide software. Does anyone know where I can find it?

~~~
thirsteh
[https://godoc.org/golang.org/x/tools/cmd/present](https://godoc.org/golang.org/x/tools/cmd/present)

~~~
zatkin
Wow, they run an entire web server just for slides?

~~~
davecheney
Wow. You have to use a whole web browser just to view slides ?

~~~
TazeTSchnitzel
The web is almost perfect for a presentation.

------
olov
Live stream recording here:
[https://youtu.be/Fx304EfqtMo?t=2468](https://youtu.be/Fx304EfqtMo?t=2468)

~~~
nsajko
Not anymore :)

------
ClassicFarris
Can some one answer this question. It says that Go1.4 will be needed to
compile Go1.5. Does this mean that Go1.4 will always be needed, even for Go1.6
and beyond? So are they essentially locking things to the Go1.4 "C" code, then
updating on top of that?

~~~
Aissen
Yes. It means that anytime you want to add a new supported architecture,
you'll need to bootstrap through Go 1.4.

Otherwise, I'm guessing that for Go 1.6, they'll rely on you having a binary
distribution of 1.5 (probably from your distribution, or their website), etc.

~~~
EdiX
>It means that anytime you want to add a new supported architecture, you'll
need to bootstrap through Go 1.4.

That's not true at all, (1) you write the backend for the target machine, (2)
you recompile the compiler with the new backend included on a supported host,
(3) then use the new compiler to compile itself for the target using the new
backend, (4) you now have a compiler that runs on the target.

Same process is used to port C compilers (or any self-hosting compiler,
really).

------
klapinat0r
Sorry for the noob question, but could someone help me understand how this is
(conceptual) possible?

I get that you can write a program which compiles language X to machine code,
e.g. how python interpreting Go to write the assembly necessary would be
technically possible.

My question is, how is the compiler generated? If it's written in c, gcc -o
compiler, but what is the piece I'm missing when it comes to Go compiles a Go
compiler -- or is this still done as "here's the machine code, now compile the
Go runtime"?

I suppose my question is a similie to "the chicken or the egg?".

~~~
comex
On a related note, while Go at least has Go 1.4 available to allow
bootstrapping from a C compiler for the near future (see [1] for more detail),
many languages have no easy way to do so. For example, Rust's compiler was
originally written in OCaml, and Nim's in Object Pascal, but both compilers
were migrated to be written in the respective languages themselves, and AFAIK
both languages have since evolved alongside their compilers for long enough
that bootstrapping all the way from before said migrations to the present
would require a massive chain of newer and newer compiler versions - not an
undertaking anyone really wants to carry out.

Instead, any Linux distribution etc. that wants to integrate the language into
its build system has to start by importing a binary from somewhere else. In
general this isn't a problem, because that binary is used only to compile the
compiler from source (and then that compiler recompiles itself, usually), so
any bugs in it are unlikely to affect the final product. However, the topic
tends to come up of Ken Thompson's famous paper [2] describing a hypothetical
scenario where a compiler binary is intentionally backdoored to insert a
vulnerability when it's compiling some security-critical program, plus a copy
of the same backdoor whenever it detects it's compiling itself. In that case,
the backdoor could theoretically infect the final result of a bootstrap,
despite it being compiled from pristine source; no attack of that nature has
ever been detected in the wild, though.

[1]
[https://docs.google.com/document/d/1OaatvGhEAq7VseQ9kkavxKNA...](https://docs.google.com/document/d/1OaatvGhEAq7VseQ9kkavxKNAfepWy2yhPUBs96FGV28/edit)

[2]
[https://www.ece.cmu.edu/~ganger/712.fall02/papers/p761-thomp...](https://www.ece.cmu.edu/~ganger/712.fall02/papers/p761-thompson.pdf)

~~~
hobarrera
What also intrigues me is how one would port to a new architecture.

You've got no go1.4 there to boostrap you (new architecture), and you can't
get the binary because you're trying to build the first one.

~~~
comex
Easy, you cross compile from Go on a different architecture. Go apparently has
a good cross compilation story, though I don't have experience with it;
honestly IMO the whole perception that cross compiling is an unusual or
difficult thing comes from poorly designed Unix build systems. Though I
suppose this would make a fully automated bootstrapping system a bit messier.
(Do the first build in an emulator?)

~~~
hobarrera
Thanks for you answer. I hadn't though about cross compilation, and I guess
that's the sanest approach, when possible.

------
pvinis
a curiosity question. is "all but impossible" correct? shouldnt it be "all but
possible" or "all but easy"? whenever i see the "X is all but Y" phrase, it
makes sense to me that X is not Y. its everything else but/except Y. am i
thinking correctly or is the use in the slides correct?

~~~
TazeTSchnitzel
> is "all but impossible" correct?

Yes.

> whenever i see the "X is all but Y" phrase, it makes sense to me that X is
> not Y.

It's not "X is not Y", it's "X is _all but_ Y", that is, X is very nearly not
Y. "All but impossible" means it's possible, but only barely.

~~~
hencq
And to make it extra confusing there's "X is anything but Y" idiom which
basically means what pvinis says.

~~~
pvinis
aaah thats why i get confused. i thought its always one phrase, but its "all
but" and "anything but". now i get it. lets just say this whole confusion is
anything but unclear now. it used to be all but impossible to understand what
people meant.

------
sacado2
Does that mean cgo is away too ?

~~~
sacado2
I don't know why I've been downvoted. Maybe my question wasn't clear. Since
there is no need anymore for a C compiler in the Go toolset, how will the
magic import "C" package work ?

~~~
rsc
If you want to use cgo you still need a C compiler for that. But it's the
system C compiler (clang or gcc), not the one we deleted.

~~~
sacado2
OK, thanks for the information.

------
smaili
Just out of curiosity, is this the first time a language is written using
itself?

~~~
segmondy
It's a sign of maturity to show that a language can bootstrap itself, prolog
has been written in prolog, erlang was written with prolog first, then later
rewritten in erlang, as other's have pointed out, it's pretty common for
C/C++, Lisp, Assembly. This of course applies more to compiled languages.

~~~
fenollp
You know that Erlang is not entirely written in Erlang, right?

------
oldpond
Congrats on this milestone!

------
narsil
It would be nice to see benchmarking stats to gauge the significance of the
performance problems mentioned in the slides. For users, I'd imagine the ease
of developing the Go language is less important than its performance.

------
ilitirit
Is there anyway to navigate that presentation using only the mouse? If not,
why not?

~~~
Akuma
From the instructions on the page:

> Use the left and right arrow keys _or click the left and right edges of the
> page_ to navigate between slides.

------
gamesbrainiac
Is the video out yet?

~~~
mschwaig
Here you 'Go'. Hehe.
[https://youtu.be/Fx304EfqtMo?t=40m20s](https://youtu.be/Fx304EfqtMo?t=40m20s)

------
bla2
"How to sell a rewrite of your compiler that made it slower"

~~~
andrewchambers
This is a fair criticism presented in a poor way. Hopefully the performance
will improve with the new dev.ssa branch eventually.

I will note that go programs still seem to build orders of magnitude faster
than C++ programs, even after this change.

~~~
imslavko
Can you please explain what dev.ssa branch is implementing and how is it going
to change the performance of the compiler?

~~~
andrewchambers
It is a program representation that a few modern compiler optimization
techniques rely on. It just mean there is potential for the compiler to emit
better assembly code.

Because the compiler is now written in Go, compiler optimization will affect
how fast programs compile.

The compiler may speed up or slow down because it is doing more advanced code
analysis, but is generating better assembly. I do not know if this will cancel
itself out or not.

------
Merkur
whee exciting new stuff AND a foundation for even more stuff in the future.
great thx!

------
smegel
These new Go presentations (this one and [http://talks.golang.org/2015/state-
of-go-may.slide#1](http://talks.golang.org/2015/state-of-go-may.slide#1)) are
great. Very insightful and well explained.

~~~
petesoder
We'll have vids of both up on
[https://www.hakkalabs.co/meetups/gosf](https://www.hakkalabs.co/meetups/gosf)
within a few days or so.

------
SilasX
Could someone explain why 4 of the top 5 stories right now are about Go?

~~~
enneff
This event just finished:
[http://www.meetup.com/golangsf/events/170421402/](http://www.meetup.com/golangsf/events/170421402/)

------
billpg
I've created my own programming language and they always tell me that the best
languages are always self-hosted, so I wrote the compiler in my new language
too.

I'm having trouble running the compiler.

    
    
         bpgcomp bpgcomp.bpg -o bpgcomp
    

But I keep getting a "bpgcomp not found" error.

