Skip to content

Commit 371eb58

Browse files
GearsDatapackslpil
authored andcommitted
Document new_without_type_variables
1 parent e6d3341 commit 371eb58

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

compiler-core/src/type_/printer.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,24 @@ impl<'a> Printer<'a> {
333333
}
334334
}
335335

336+
/// In the AST, type variables are represented by their IDs, not their names.
337+
/// This means that when we are printing a type variable, we either need to
338+
/// find its name that was given by the programmer, or generate a new one.
339+
/// Type variable names are local to functions, meaning there can be one
340+
/// named `a` in one function, and a different one named `a` in another
341+
/// function. However, there can't be two named `a` in the same function.
342+
///
343+
/// By default, the printer avoids duplicating type variable names entirely.
344+
/// This is because we don't have easy access to information about which type
345+
/// variables belong to this function. In order to ensure no accidental,
346+
/// collisions, we treat all type variables from the module as in scope, even
347+
/// though this isn't the case.
348+
///
349+
/// When sufficient information is present to ensure type variables are not
350+
/// duplicated, `new_without_type_variables` can be used, in combination with
351+
/// `register_type_variables` in order to precisely control which variables
352+
/// are in scope.
353+
///
336354
pub fn new_without_type_variables(names: &'a Names) -> Self {
337355
Printer {
338356
names,

0 commit comments

Comments
 (0)