sway_core/control_flow_analysis/
mod.rs

1//!
2//! This module contains all of the logic related to control flow analysis.
3//!
4//! # Synopsis of Dead-Code Analysis Algorithm
5//! The dead code analysis algorithm constructs a node for every declaration, expression, and
6//! statement. Then, from the entry points of the AST, we begin drawing edges along the control
7//! flow path. If a declaration is instantiated, we draw an edge to it. If an expression or
8//! statement is executed, an edge is drawn to it. Finally, we trace the edges from the entry
9//! points of the AST. If there are no paths from any entry point to a node, then it is either a
10//! dead declaration or an unreachable expression or statement.
11//!
12//! See the Terms section for details on how entry points are determined.
13//!
14//! # Synopsis of Return-Path Analysis Algorithm
15//! The graph constructed for this algorithm does not go into the details of the contents of any
16//! declaration except for function declarations. Inside of every function, it traces the execution
17//! path along to ensure that all reachable paths do indeed return a value. We don't need to type
18//! check the value that is returned, since type checking of return statements happens in the type
19//! checking stage. Here, we know all present return statements have the right type, and we just
20//! need to verify that all paths do indeed contain a return statement.
21//!
22//!
23//! # # Terms
24//! # # # Node
25//! A node is any [crate::semantic_analysis::TyAstNode], with some
26//! [crate::semantic_analysis::TyAstNodeContent]. # # # Dominating nodes
27//! A dominating node is a node which all previous nodes pass through. These are what we are
28//! concerned about in control flow analysis. More formally,
29//! A node _M_ dominates a node _N_ if every path from the entry that reaches node _N_ has to pass
30//! through node _M_.
31//!
32//! # # # Reachability
33//! A node _N_ is reachable if there is a path to it from any one of the tree's entry points.
34//!
35//! # # # Entry Points
36//! The entry points to an AST depend on what type of AST it is. If it is a predicate or script,
37//! then the main function is the sole entry point. If it is a library or contract, then public
38//! functions or declarations are entry points.
39mod analyze_return_paths;
40mod dead_code_analysis;
41mod flow_graph;
42
43pub use flow_graph::*;