Hacker News new | past | comments | ask | show | jobs | submit login

Go does has some form of monomorphization implemented in Go1.18; it is just behind a feature flag(compiler flags).

Look at the assembly difference between this two examples:

1. https://godbolt.org/z/7r84jd7Ya (without monomorphization)

2. https://godbolt.org/z/5Ecr133dz (with monomorphization)

If you don't want to use godbolt, run the command `go tool compile '-d=unified=1' -p . -S main.go`

I guess that the flag is not documented because the Go team has not committed themselves to whichever implementation.




FWIW you can have two different compilers (and outputs) for the same input: https://godbolt.org/z/bb1oG9TbP in the compiler pane just click "add new" and "clone compiler" (you can actually drag that button to immediately open the pane in the right layout instead of having your layout move to vertical thirds and needing to move the pane afterwards).

Learned that watching one of Matt's cppcon talks (A+, would do again), as you can expect this is useful to compare different versions of a compiler, or different compilers entirely, or different optimisation settings.

But wait, there's more! Using the top left Add dropdown, you can get a diff view between compilation outputs: https://godbolt.org/z/s3WxhEsKE (I maximised it because a diff view getting only a third of the layout is a bit narrow).


thanks!


I feel like a half-idiot but I'm unable to tell how exactly the "unified=1" implements monomorphization. I don't see the extra indirections which OP writes about.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: