Skip to content

jespino/having-fun-with-the-go-source-code-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Having Fun with the Go Source Code Workshop

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

  • 🐹 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

πŸŽ“ Workshop Overview

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.

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.

πŸš€ 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.

πŸ“ Repository Structure

.
β”œβ”€β”€ 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)

🌐 Website Generator

This repository includes a Go program that automatically generates a static website from the markdown exercise files.

Generate the Website

# Using make (recommended)
make website

# Or run directly
cd website-generator
go run . -exercises ../exercises -output ../website

Serve Locally

# Start a local web server
make serve

# Then open http://localhost:8000 in your browser

The 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.

πŸ’‘ Tips for Success

  • ⏰ Take your time with each exercise - compiler internals are complex!
  • πŸ” Don't hesitate to explore the Go source code beyond what's required
  • 🌿 Use git to track your changes and revert when needed
  • πŸ§ͺ Test your modifications thoroughly with various Go programs

πŸ“– Resources

πŸŽ₯ Video References

These workshop exercises are based on insights from my talks:

πŸ† Workshop Completion

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

🀝 Contributing

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! πŸš€βœ¨

About

Having Fun with the Go Source Code Workshop

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •