1
Fork 0

Make locals field private

This commit is contained in:
Kirby Linvill 2023-10-25 21:28:18 +01:00
parent f4d80a5f09
commit 372c533532
No known key found for this signature in database
GPG key ID: E304CE3F028E6E3F

View file

@ -7,12 +7,12 @@ use crate::{ty::Ty, Span};
pub struct Body {
pub blocks: Vec<BasicBlock>,
/// Declarations of locals.
// Declarations of locals within the function.
//
// The first local is the return value pointer, followed by `arg_count`
// locals for the function arguments, followed by any user-declared
// variables and temporaries.
pub locals: LocalDecls,
locals: LocalDecls,
// The number of arguments this function takes.
arg_count: usize,
@ -22,12 +22,12 @@ impl Body {
/// Constructs a `Body`.
///
/// A constructor is required to build a `Body` from outside the crate
/// because the `arg_count` field is private.
/// because the `arg_count` and `locals` fields are private.
pub fn new(blocks: Vec<BasicBlock>, locals: LocalDecls, arg_count: usize) -> Self {
// If locals doesn't contain enough entries, it can lead to panics in
// `ret_local` and `arg_locals`.
// `ret_local`, `arg_locals`, and `internal_locals`.
assert!(
locals.len() >= arg_count + 1,
locals.len() > arg_count,
"A Body must contain at least a local for the return value and each of the function's arguments"
);
Self { blocks, locals, arg_count }