Skip to content

Commit abbcfcb

Browse files
fitzgenKowasaki
authored andcommitted
Fix template usage analysis doc comment
It had some incorrectness where there was a difference between the abstract `self_template_param_usage` and `template_param_usage` functions. In reality, they are different cases of the same function. The comment was misleading in that it implied that we run both on the same IR item, when in fact we will only run one or the other. I've tried to make it more clear in the new version of the comment.
1 parent f1dee65 commit abbcfcb

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

src/ir/named.rs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -212,46 +212,37 @@ pub fn analyze<Analysis>(extra: Analysis::Extra) -> Analysis::Output
212212
/// An analysis that finds for each IR item its set of template parameters that
213213
/// it uses.
214214
///
215-
/// We use the following monotone constraint function:
215+
/// We use the monotone constraint function `template_param_usage`, defined as
216+
/// follows:
216217
///
217-
/// ```ignore
218-
/// template_param_usage(v) =
219-
/// self_template_param_usage(v) union
220-
/// template_param_usage(w_0) union
221-
/// template_param_usage(w_1) union
222-
/// ...
223-
/// template_param_usage(w_n)
224-
/// ```
225-
///
226-
/// Where `v` has direct edges in the IR graph to each of `w_0`, `w_1`,
227-
/// ..., `w_n` (for example, if `v` were a struct type and `x` and `y`
228-
/// were the types of two of `v`'s fields). We ignore certain edges, such
229-
/// as edges from a template declaration to its template parameters'
230-
/// definitions for this analysis. If we didn't, then we would mistakenly
231-
/// determine that ever template parameter is always used.
232-
///
233-
/// Finally, `self_template_param_usage` is defined with the following cases:
234-
///
235-
/// * If `T` is a template parameter:
218+
/// * If `T` is a named template type parameter, it trivially uses itself:
236219
///
237220
/// ```ignore
238-
/// self_template_param_usage(T) = { T }
221+
/// template_param_usage(T) = { T }
239222
/// ```
240223
///
241224
/// * If `inst` is a template instantiation, `inst.args` are the template
242-
/// instantiation's template arguments, and `inst.decl` is the template
243-
/// declaration being instantiated:
225+
/// instantiation's template arguments, and `inst.def` is the template
226+
/// definition being instantiated:
244227
///
245228
/// ```ignore
246-
/// self_template_param_usage(inst) =
247-
/// { T: for T in inst.args, if T in template_param_usage(inst.decl) }
229+
/// template_param_usage(inst) =
230+
/// { T: for T in inst.args, if T in template_param_usage(inst.def) }
248231
/// ```
249232
///
250-
/// * And for all other IR items, the result is the empty set:
233+
/// * Finally, for all other IR item kinds, we use our lattice's `join`
234+
/// operation: set union with each successor of the given item's template
235+
/// parameter usage:
251236
///
252237
/// ```ignore
253-
/// self_template_param_usage(_) = { }
238+
/// template_param_usage(v) =
239+
/// union(template_param_usage(w) for w in successors(v))
254240
/// ```
241+
///
242+
/// Note that we ignore certain edges in the graph, such as edges from a
243+
/// template declaration to its template parameters' definitions for this
244+
/// analysis. If we didn't, then we would mistakenly determine that ever
245+
/// template parameter is always used.
255246
#[derive(Debug, Clone)]
256247
pub struct UsedTemplateParameters<'ctx, 'gen>
257248
where 'gen: 'ctx,

0 commit comments

Comments
 (0)