wdl_engine/
lib.rs

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