How fuellabs/sway works
Sway is a Rust-inspired smart-contract language and toolchain for Fuel. Its broad workflow is authoring Sway code, using Forc and language tooling, and compiling programs for the Fuel ecosystem; the repository also includes testing, documentation, debugging, migration, and publishing tools. The sampled sources show several internal relationships, especially IR utilities and test execution, but do not expose the complete compiler or CLI orchestration. Unverified workflow links are therefore dashed and uncited.
Main entry points: context.rs IR context · lib.rs Forc utilities · execute.rs Test execution · cli Forc CLI
Components 34
Forc and packages
- Forc CLI
forc/src/cli - Package management
forc-pkg/src - Forc utilities
forc-util/src/lib.rs - Bytecode utilities
forc-util/src/bytecode.rs - Filesystem locking
forc-util/src/fs_locking.rs - Restricted operations
forc-util/src/restricted.rs - Transaction utilities
forc-util/src/tx_utils.rs
Language compiler
- Parser and AST
sway-parse/src/parser.rs - Semantic and type analysis
sway-core/src/semantic_analysis - Type engine
sway-core/src/type_system/engine.rs - Type parameters
sway-core/src/type_system/ast_elements/type_parameter.rs - Type unification
sway-core/src/type_system/unify/unifier.rs - Source mapping
sway-types/src/source_engine.rs - Compiler diagnostics
sway-error/src/handler.rs - Assembly generation
sway-core/src/asm_generation - Source spans
sway-types/src/span.rs
Intermediate representation
- IR context
sway-ir/src/context.rs - IR parser
sway-ir/src/parser.rs - IR types
sway-ir/src/irtype.rs - IR pass manager
sway-ir/src/pass_manager.rs - IR printer
sway-ir/src/printer.rs - IR formatting
sway-ir/src/pretty.rs - Storage keys
sway-ir/src/storage_key.rs
Developer tools
- Language server
sway-lsp/src/server.rs - Code formatter
swayfmt/src - Documentation generator
forc-plugins/forc-doc/src/render - Debugger
forc-plugins/forc-debug/src/server - Code migration
forc-plugins/forc-migrate/src - Package publisher
forc-plugins/forc-publish/src
Testing and runtime
- Test execution
forc-test/src/execute.rs - Test setup
forc-test/src/setup.rs - VM syscall handling
forc-test/src/ecal.rs
Other components
- Sway developer
- Fuel VM
Connections 22
- Sway developer → Forc CLI: uses
- Forc CLI → Package management: invokes
- Forc CLI → Parser and AST: compiles with
- Parser and AST → Semantic and type analysis: feeds analysis
- Type engine → Type parameters: uses
sway-core/src/type_system/engine.rs - Type engine → Type unification: uses
sway-core/src/type_system/engine.rs - Semantic and type analysis → IR context: lowers to
- IR context → IR printer: printed by
sway-ir/src/context.rs - IR types → IR context: uses
sway-ir/src/irtype.rs - IR types → IR formatting: formats with
sway-ir/src/irtype.rs - IR pass manager → IR printer: registers
sway-ir/src/pass_manager.rs - Storage keys → IR context: stores in
sway-ir/src/storage_key.rs - Storage keys → IR types: uses
sway-ir/src/storage_key.rs - IR context → Assembly generation: compiled to
- Source mapping → Source spans: tracks
sway-types/src/source_engine.rs - Test execution → Test setup: prepares tests
forc-test/src/lib.rs - Test execution → VM syscall handling: uses
forc-test/src/execute.rs - Test execution → Fuel VM: executes on
- Forc utilities → Bytecode utilities: exposes
forc-util/src/lib.rs - Forc utilities → Filesystem locking: exposes
forc-util/src/lib.rs - Forc utilities → Restricted operations: exposes
forc-util/src/lib.rs - Forc utilities → Transaction utilities: exposes
forc-util/src/lib.rs