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