Skip to main content

rlx_flow/
extension.rs

1// RLX — versatile ML compiler + runtime.
2// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16//! Flow-level extension wiring — applies [`rlx_ir::hir_extension`] after build.
17
18use rlx_ir::hir::HirModule;
19use rlx_ir::{apply_hir_extensions, apply_hir_extensions_named};
20
21/// Names of HIR extensions to apply when building this flow (empty = all registered).
22#[derive(Debug, Clone, Default, PartialEq, Eq)]
23pub struct FlowExtensionPlan {
24    pub enabled: Vec<String>,
25    pub apply_all: bool,
26}
27
28impl FlowExtensionPlan {
29    pub fn all() -> Self {
30        Self {
31            enabled: Vec::new(),
32            apply_all: true,
33        }
34    }
35
36    pub fn only(names: impl IntoIterator<Item = impl Into<String>>) -> Self {
37        Self {
38            enabled: names.into_iter().map(Into::into).collect(),
39            apply_all: false,
40        }
41    }
42
43    pub fn apply(&self, hir: &mut HirModule) {
44        if self.apply_all {
45            apply_hir_extensions(hir);
46        } else {
47            let refs: Vec<&str> = self.enabled.iter().map(String::as_str).collect();
48            apply_hir_extensions_named(hir, &refs);
49        }
50    }
51}