Welcome to an interactive workshop where you'll learn how to modify and experiment with the Go programming language source code! This hands-on workshop will guide you through understanding, building, and making changes to the Go compiler and runtime. π―
π This workshop uses Go version 1.25.1 - we'll check out the specific release tag to ensure consistency across all exercises.
- πΉ Basic knowledge of Go programming
- π» Familiarity with command line tools
- ποΈ Git installed on your system
- β‘ Go compiler version 1.24.6 or newer (required for bootstrapping the build process)
- πΎ At least 4GB of free disk space
This workshop consists of 10 exercises that will take you through the process from building Go from source, and making modifications at different places in the compiler, tooling and runtime. You'll gain some insights about the Go internals, from things like the lexer or parser, to runtime behaviors:
Get started by cloning and setting up the Go source code environment.
Learn to build the Go toolchain from source without any modifications.
Learn scanner/lexer modification by adding "=>" as an alternative syntax for starting goroutines.
Learn parser modification by enabling multiple consecutive "go" keywords (go go go myFunction).
Explore the inliner behavior by modifying function inlining parameters.
Learn about Go's tools by modifying gofmt to modify "hello" to "helo" in code.
Create a custom SSA compiler pass that detects division operations by powers of two that could be optimized to bit shifts.
Modify the Go runtime to wait for all goroutines to complete before program termination.
π΅οΈββοΈ Exercise 8: Goroutine Sleep Detective - Runtime State Monitoring
Add logging to the Go scheduler to monitor goroutines going to sleep.
Modify Go's select statement implementation to be deterministic instead of random.
Transform Go's verbose stack traces into Java-style formatting.
- π± Start with Exercise 0 to set up your environment
- π Work through the exercises in order
- π After exercise 1, you can pick and choose the exercise that you want.
.
βββ README.md # This file
βββ exercises/ # Individual exercise files (markdown)
β βββ 00-introduction-setup.md
β βββ 01-compile-go-unchanged.md
β βββ 02-scanner-arrow-operator.md
β βββ ...
βββ website-generator/ # Go program to generate website from markdown
β βββ main.go
β βββ templates.go
β βββ README.md
βββ website/ # Generated website (HTML)
β βββ index.html
β βββ 00-introduction-setup.html
β βββ ...
βββ Makefile # Build automation
βββ go/ # Go source code (cloned during setup)
This repository includes a Go program that automatically generates a static website from the markdown exercise files.
# Using make (recommended)
make website
# Or run directly
cd website-generator
go run . -exercises ../exercises -output ../website# Start a local web server
make serve
# Then open http://localhost:8000 in your browserThe website generator:
- β Converts markdown to HTML using blackfriday
- β Preserves all formatting, emojis, and code blocks
- β Generates navigation between exercises
- β Creates an index page with exercise overview
- β Includes responsive CSS styling
See website-generator/README.md for more details.
- β° Take your time with each exercise - compiler internals are complex!
- π Don't hesitate to explore the Go source code beyond what's required
- πΏ Use
gitto track your changes and revert when needed - π§ͺ Test your modifications thoroughly with various Go programs
- ποΈ Go Compiler Overview
- π Go Language Specification
- π§ Go Runtime Documentation
- π Go Internal Documentation
These workshop exercises are based on insights from my talks:
- π¬ Understanding the Go Compiler - Deep dive into Go's compilation process
- π¬ Understanding the Go Runtime - Exploration of Go's runtime system
Upon completing all exercises, you'll have:
- β Built Go from source and understood the bootstrap process
- β Modified language syntax by changing scanner and parser behavior
- β Customized development tools like gofmt and compiler optimizations
- β Implemented SSA optimizations in the compiler backend
- β Modified runtime behavior including program entry points and scheduler monitoring
- β Altered concurrency algorithms like select statement randomization
- β Customized error reporting with Java-style stack trace formatting
Congratulations! You'll have gained the confidence to keep exploring the Go source code. This knowledge enables you to:
- Start small contributions to the Go project
- Build custom language variants and tools
- Understand some trade-offs in language and runtime design
Found an issue, have an improvement idea or want to add more exercises? Please open an issue or submit a pull request!
Happy coding and welcome to the world of Go internals! πβ¨