πŸš€ Having fun with the Go Source Code

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.

πŸ“‹ Prerequisites

πŸŽ“ Workshop Overview

This workshop consists of 11 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:

Exercise 0

🌱 Introduction and Setup

Get started by cloning and setting up the Go source code environment.

Exercise 1

πŸ”¨ Compiling Go Without Changes

Learn to build the Go toolchain from source without any modifications.

Exercise 2

⚑ Adding the "=>" Arrow Operator for Goroutines

Learn scanner/lexer modification by adding "=>" as an alternative syntax for starting goroutines.

Exercise 3

πŸ”„ Multiple "go" Keywords - Parser Enhancement

Learn parser modification by enabling multiple consecutive "go" keywords (go go go myFunction).

Exercise 4

βš™οΈ Inline Parameters - Function Inlining Experiments

Explore the inliner behavior by modifying function inlining parameters.

Exercise 5

🎨 gofmt Transformation - "hello" to "helo"

Learn about Go's tools by modifying gofmt to modify "hello" to "helo" in code.

Exercise 6

πŸ” SSA Pass - Detecting Division by Powers of Two

Create a custom SSA compiler pass that detects division operations by powers of two that could be optimized to bit shifts.

Exercise 7

πŸ•°οΈ Patient Go - Making Go Wait for Goroutines

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.

Exercise 9

🎯 Predictable Select - Removing Randomness from Go's Select Statement

Modify Go's select statement implementation to be deterministic instead of random.

Exercise 10

β˜• Java-Style Stack Traces - Making Go Panics Look Familiar

Transform Go's verbose stack traces into Java-style formatting.

πŸš€ Getting Started

  1. 🌱 Start with Exercise 0 to set up your environment
  2. πŸ“š Work through the exercises in order
  3. πŸ”— After exercise 1, you can pick and choose the exercise that you want.

πŸ’‘ Tips for Success

πŸ“– Resources

πŸŽ₯ Video References

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

πŸ† Workshop Completion

Upon completing all exercises, you'll have:

Congratulations! You'll have gained the confidence to keep exploring the Go source code. This knowledge enables you to:

🀝 Contributing

Found an issue, have an improvement idea or want to add more exercises? Please open an issue or submit a pull request!

Start with Exercise 0 β†’