Switch to PathBuf to avoid Path turning into a fat pointer. Avoids growing Constraints

This commit is contained in:
Brendan Hansknecht 2023-04-09 21:14:05 -07:00
parent 9a87675368
commit c440b2ca05
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
4 changed files with 17 additions and 13 deletions

View file

@ -1,5 +1,5 @@
use std::cell::Cell;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use crate::abilities::SpecializationId;
@ -680,15 +680,15 @@ impl Constraints {
pub fn ingested_file(
&mut self,
type_index: TypeOrVar,
file_path: Box<Path>,
file_path: Box<PathBuf>,
bytes: Arc<Vec<u8>>,
) -> Constraint {
Constraint::IngestedFile(type_index, file_path, bytes)
}
}
roc_error_macros::assert_sizeof_default!(Constraint, 4 * 8);
roc_error_macros::assert_sizeof_aarch64!(Constraint, 4 * 8);
roc_error_macros::assert_sizeof_default!(Constraint, 3 * 8);
roc_error_macros::assert_sizeof_aarch64!(Constraint, 3 * 8);
impl std::ops::Index<ExpectedTypeIndex> for Constraints {
type Output = Expected<TypeOrVar>;
@ -786,7 +786,7 @@ pub enum Constraint {
Resolve(OpportunisticResolve),
CheckCycle(Index<Cycle>, IllegalCycleMark),
IngestedFile(TypeOrVar, Box<Path>, Arc<Vec<u8>>),
IngestedFile(TypeOrVar, Box<PathBuf>, Arc<Vec<u8>>),
}
#[derive(Debug, Clone, Copy, Default)]

View file

@ -29,7 +29,7 @@ use roc_types::types::{Alias, Category, IndexOrField, LambdaSet, OptAbleVar, Typ
use std::fmt::{Debug, Display};
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use std::{char, u32};
@ -105,7 +105,7 @@ pub enum Expr {
},
// An ingested files, it's bytes, and the type variable.
IngestedFile(Box<Path>, Arc<Vec<u8>>, Variable),
IngestedFile(Box<PathBuf>, Arc<Vec<u8>>, Variable),
// Lookups
Var(Symbol, Variable),
@ -742,7 +742,11 @@ pub fn canonicalize_expr<'a>(
let mut bytes = vec![];
match file.read_to_end(&mut bytes) {
Ok(_) => (
Expr::IngestedFile((*file_path).into(), Arc::new(bytes), var_store.fresh()),
Expr::IngestedFile(
file_path.to_path_buf().into(),
Arc::new(bytes),
var_store.fresh(),
),
Output::default(),
),
Err(e) => {

View file

@ -1,5 +1,5 @@
//! Provides types to describe problems that can occur during solving.
use std::{path::Path, str::Utf8Error};
use std::{path::PathBuf, str::Utf8Error};
use roc_can::expected::{Expected, PExpected};
use roc_module::{ident::Lowercase, symbol::Symbol};
@ -31,8 +31,8 @@ pub enum TypeError {
expected_opaque: Symbol,
found_opaque: Symbol,
},
IngestedFileBadUtf8(Box<Path>, Utf8Error),
IngestedFileUnsupportedType(Box<Path>, ErrorType),
IngestedFileBadUtf8(Box<PathBuf>, Utf8Error),
IngestedFileUnsupportedType(Box<PathBuf>, ErrorType),
}
impl TypeError {

View file

@ -15,7 +15,7 @@ use roc_module::symbol::{Interns, Symbol};
use roc_region::all::{Loc, Region};
use std::fmt;
use std::fmt::Write;
use std::path::Path;
use std::path::PathBuf;
pub const TYPE_NUM: &str = "Num";
pub const TYPE_INTEGER: &str = "Integer";
@ -3782,7 +3782,7 @@ pub enum Category {
List,
Str,
Character,
IngestedFile(Box<Path>),
IngestedFile(Box<PathBuf>),
// records
Record,