wdl_engine/
lib.rs

1//! Execution engine for Workflow Description Language (WDL) documents.
2
3mod backend;
4pub mod config;
5pub mod diagnostics;
6mod eval;
7pub(crate) mod http;
8mod inputs;
9mod outputs;
10pub mod path;
11mod stdlib;
12pub(crate) mod tree;
13mod units;
14mod value;
15
16use std::sync::LazyLock;
17
18pub use backend::*;
19pub use eval::*;
20pub use inputs::*;
21pub use outputs::*;
22use sysinfo::CpuRefreshKind;
23use sysinfo::MemoryRefreshKind;
24use sysinfo::System;
25pub use units::*;
26pub use value::*;
27use wdl_analysis::diagnostics::unknown_type;
28use wdl_analysis::document::Document;
29use wdl_analysis::types::Type;
30use wdl_analysis::types::TypeNameResolver;
31use wdl_analysis::types::v1::AstTypeConverter;
32use wdl_ast::Diagnostic;
33use wdl_ast::Span;
34use wdl_ast::TreeNode;
35
36/// One gibibyte (GiB) as a float.
37///
38/// This is defined as a constant as it's a commonly performed conversion.
39const ONE_GIBIBYTE: f64 = 1024.0 * 1024.0 * 1024.0;
40
41/// Resolves a type name from a document.
42///
43/// This function will import the type into the type cache if not already
44/// cached.
45fn resolve_type_name(document: &Document, name: &str, span: Span) -> Result<Type, Diagnostic> {
46    document
47        .struct_by_name(name)
48        .map(|s| s.ty().expect("struct should have type").clone())
49        .ok_or_else(|| unknown_type(name, span))
50}
51
52/// Converts a V1 AST type to an analysis type.
53fn convert_ast_type_v1<N: TreeNode>(
54    document: &Document,
55    ty: &wdl_ast::v1::Type<N>,
56) -> Result<Type, Diagnostic> {
57    /// Used to resolve a type name from a document.
58    struct Resolver<'a>(&'a Document);
59
60    impl TypeNameResolver for Resolver<'_> {
61        fn resolve(&mut self, name: &str, span: Span) -> Result<Type, Diagnostic> {
62            resolve_type_name(self.0, name, span)
63        }
64    }
65
66    AstTypeConverter::new(Resolver(document)).convert_type(ty)
67}
68
69/// Cached information about the host system.
70static SYSTEM: LazyLock<System> = LazyLock::new(|| {
71    let mut system = System::new();
72    system.refresh_cpu_list(CpuRefreshKind::nothing());
73    system.refresh_memory_specifics(MemoryRefreshKind::nothing().with_ram());
74    system
75});