#loader #swamp #dep

swamp-dep-loader

Parses Swamp modules, scans for dependencies (mod and use), and determines the correct analysis order

4 releases

Uses new Rust 2024

new 0.1.13 Mar 30, 2025
0.1.12 Mar 30, 2025
0.1.11 Mar 29, 2025
0.1.10 Mar 29, 2025

#1 in #dep

Download history

85 downloads per month
Used in 6 crates (4 directly)

MIT license

175KB
4K SLoC

Swamp Dependency Loader

Parses Swamp source files, identifies module dependencies (mod and use statements), and calculates the correct order for semantic analysis.

Overview

This crate orchestrates the initial parsing phase of the Swamp compilation process. Starting from an entry point module, it recursively:

  1. Parses Swamp source files into ASTs (swamp-ast) using swamp-parser.
  2. Scans the AST for mod (import) and use declarations to discover dependencies on other modules.
  3. Maps module paths (e.g., crate.My.Module, some_package.Lib) to file system paths using swamp-source-map.
  4. Builds a dependency graph of the modules.
  5. Determines the correct topological order in which modules must be analyzed to satisfy dependencies.

Key Functionality

  • DependencyParser: Manages the state of parsed modules and scanned dependencies.
  • parse_local_modules: Recursively parses the entry module and its dependencies.
  • get_analysis_order: Calculates the topological sort of the module dependency graph.
  • Path Resolution: Handles finding module files based on conventions (crate vs. registry packages, .swamp extension).

Installation

This crate is primarily used internally by the Swamp compiler.

[dependencies]
swamp-dep-loader = "0.1.13"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/swamp

Dependencies

~2.4–9.5MB
~98K SLoC