wesl 0.3.2

The WESL compiler
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::collections::HashSet;

use wgsl_parse::{
    SyntaxNode,
    syntax::{Ident, TranslationUnit},
};

/// Remove unused declarations.
pub(crate) fn strip_except(wgsl: &mut TranslationUnit, keep: &HashSet<Ident>) {
    wgsl.global_declarations.retain_mut(|decl| {
        if let Some(id) = decl.ident() {
            keep.contains(&id) || id.use_count() > 1
        } else {
            true
        }
    });
}