Skip to main content

cargo_check_deadlock/
naming.rs

1//! Module that defines the naming of places and transitions in the Petri net.
2//!
3//! The functions are grouped according to the structure they deal with, e.g., function,
4//! basic block, statement, mutex, etc.
5//! Functions used by several submodules should be defined here.
6//!
7//! All functions listed here should have an `#[inline]` attribute for performance reasons.
8//! See the reference for more information:
9//! <https://doc.rust-lang.org/stable/reference/attributes/codegen.html>
10
11pub mod basic_block;
12pub mod condvar;
13pub mod function;
14pub mod mutex;
15pub mod thread;
16
17/// Label of the place that models the program start state.
18pub const PROGRAM_START: &str = "PROGRAM_START";
19/// Label of the place that models the normal program end state.
20pub const PROGRAM_END: &str = "PROGRAM_END";
21/// Label of the place that models the program end state after a `panic!`.
22pub const PROGRAM_PANIC: &str = "PROGRAM_PANIC";
23
24/// Sanitize the function name for the DOT and the `LoLA` format:
25/// - Replace generic types "<T>" with "T".
26/// - Replace lifetimes "'a" with the empty string.
27/// - Replace generic lifetimes with the empty string.
28/// - Replace double colons with underscores.
29/// - Replace curly braces with underscores.
30/// - Replace pound sign with underscores.
31/// - Replace great-than and less-than sign with underscores.
32/// - Replace spaces with underscores.
33#[inline]
34fn sanitize(function_name: &str) -> String {
35    function_name
36        .replace("<T>", "T")
37        .replace("[T]", "T")
38        .replace("<T, A>", "T_A")
39        .replace("<'a>", "")
40        .replace("<'_>", "")
41        .replace("::", "_")
42        .replace("Result_<T, E>", "Result")
43        .replace(['{', '}', '[', ']', '#', '<', '>', ' '], "_") // Catch-all case
44}