Provide roc_cache_dir everywhere

This commit is contained in:
Richard Feldman 2022-11-20 17:03:17 -05:00
parent 13bed30411
commit 721841fa1f
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
41 changed files with 303 additions and 114 deletions

View file

@ -13,18 +13,20 @@ roc_can = { path = "../can" }
roc_types = { path = "../types" }
roc_module = { path = "../module" }
roc_collections = { path = "../collections" }
roc_packaging = { path = "../../packaging" }
roc_reporting = { path = "../../reporting" }
bumpalo.workspace = true
bumpalo.workspace = true
[build-dependencies]
roc_builtins = { path = "../builtins" }
roc_module = { path = "../module" }
roc_packaging = { path = "../../packaging" }
roc_reporting = { path = "../../reporting" }
roc_target = { path = "../roc_target" }
roc_can = { path = "../can" }
bumpalo.workspace = true
bumpalo.workspace = true
[target.'cfg(not(windows))'.build-dependencies]
roc_load_internal = { path = "../load_internal" }

View file

@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
#[cfg(not(windows))]
use bumpalo::Bump;
use roc_module::symbol::ModuleId;
use roc_packaging::cache::RocCacheDir;
#[cfg(not(windows))]
const ROC_SKIP_SUBS_CACHE: &str = "ROC_SKIP_SUBS_CACHE";
@ -74,7 +75,7 @@ fn write_types_for_module_real(module_id: ModuleId, filename: &str, output_path:
use roc_load_internal::file::{LoadingProblem, Threading};
let arena = Bump::new();
let src_dir = PathBuf::from(".");
let cwd = std::env::current_dir().unwrap();
let source = roc_builtins::roc::module_source(module_id);
let target_info = roc_target::TargetInfo::default_x86_64();
@ -82,12 +83,12 @@ fn write_types_for_module_real(module_id: ModuleId, filename: &str, output_path:
&arena,
PathBuf::from(filename),
source,
src_dir,
cwd,
Default::default(),
target_info,
roc_reporting::report::RenderTarget::ColorTerminal,
roc_reporting::report::DEFAULT_PALETTE,
roc_cache_dir,
RocCacheDir::Disallowed,
Threading::AllAvailable,
);

View file

@ -4,6 +4,7 @@ use bumpalo::Bump;
use roc_can::module::{ExposedByModule, TypeState};
use roc_collections::all::MutMap;
use roc_module::symbol::ModuleId;
use roc_packaging::cache::RocCacheDir;
use roc_reporting::report::{Palette, RenderTarget};
use roc_target::TargetInfo;
use std::path::PathBuf;
@ -26,11 +27,19 @@ fn load<'a>(
arena: &'a Bump,
load_start: LoadStart<'a>,
exposed_types: ExposedByModule,
roc_cache_dir: RocCacheDir<'_>,
load_config: LoadConfig,
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
let cached_types = read_cached_types();
roc_load_internal::file::load(arena, load_start, exposed_types, cached_types, load_config)
roc_load_internal::file::load(
arena,
load_start,
exposed_types,
cached_types,
roc_cache_dir,
load_config,
)
}
/// Load using only a single thread; used when compiling to webassembly
@ -41,6 +50,7 @@ pub fn load_single_threaded<'a>(
target_info: TargetInfo,
render: RenderTarget,
palette: Palette,
roc_cache_dir: RocCacheDir<'_>,
exec_mode: ExecutionMode,
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
let cached_subs = read_cached_types();
@ -54,6 +64,7 @@ pub fn load_single_threaded<'a>(
render,
palette,
exec_mode,
roc_cache_dir,
)
}
@ -87,24 +98,26 @@ pub fn load_and_monomorphize_from_str<'a>(
src: &'a str,
src_dir: PathBuf,
exposed_types: ExposedByModule,
roc_cache_dir: RocCacheDir<'_>,
load_config: LoadConfig,
) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_str(arena, filename, src, src_dir)?;
let load_start = LoadStart::from_str(arena, filename, src, roc_cache_dir, src_dir)?;
match load(arena, load_start, exposed_types, load_config)? {
match load(arena, load_start, exposed_types, roc_cache_dir, load_config)? {
Monomorphized(module) => Ok(module),
TypeChecked(_) => unreachable!(""),
}
}
pub fn load_and_monomorphize(
arena: &Bump,
pub fn load_and_monomorphize<'a>(
arena: &'a Bump,
filename: PathBuf,
exposed_types: ExposedByModule,
roc_cache_dir: RocCacheDir<'_>,
load_config: LoadConfig,
) -> Result<MonomorphizedModule<'_>, LoadMonomorphizedError<'_>> {
) -> Result<MonomorphizedModule<'a>, LoadMonomorphizedError<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_path(
@ -115,18 +128,19 @@ pub fn load_and_monomorphize(
load_config.palette,
)?;
match load(arena, load_start, exposed_types, load_config)? {
match load(arena, load_start, exposed_types, roc_cache_dir, load_config)? {
Monomorphized(module) => Ok(module),
TypeChecked(module) => Err(LoadMonomorphizedError::ErrorModule(module)),
}
}
pub fn load_and_typecheck(
arena: &Bump,
pub fn load_and_typecheck<'a>(
arena: &'a Bump,
filename: PathBuf,
exposed_types: ExposedByModule,
roc_cache_dir: RocCacheDir<'_>,
load_config: LoadConfig,
) -> Result<LoadedModule, LoadingProblem<'_>> {
) -> Result<LoadedModule, LoadingProblem<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_path(
@ -137,7 +151,7 @@ pub fn load_and_typecheck(
load_config.palette,
)?;
match load(arena, load_start, exposed_types, load_config)? {
match load(arena, load_start, exposed_types, roc_cache_dir, load_config)? {
Monomorphized(_) => unreachable!(""),
TypeChecked(module) => Ok(module),
}
@ -152,11 +166,12 @@ pub fn load_and_typecheck_str<'a>(
exposed_types: ExposedByModule,
target_info: TargetInfo,
render: RenderTarget,
roc_cache_dir: RocCacheDir<'_>,
palette: Palette,
) -> Result<LoadedModule, LoadingProblem<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_str(arena, filename, source, src_dir)?;
let load_start = LoadStart::from_str(arena, filename, source, roc_cache_dir, src_dir)?;
// NOTE: this function is meant for tests, and so we use single-threaded
// solving so we don't use too many threads per-test. That gives higher
@ -168,6 +183,7 @@ pub fn load_and_typecheck_str<'a>(
target_info,
render,
palette,
roc_cache_dir,
ExecutionMode::Check,
)? {
Monomorphized(_) => unreachable!(""),

View file

@ -36,6 +36,7 @@ ven_pretty = { path = "../../vendor/pretty" }
bumpalo.workspace = true
parking_lot.workspace = true
crossbeam.workspace = true
tempfile.workspace = true
[dev-dependencies]
roc_test_utils = { path = "../../test_utils" }

View file

@ -36,7 +36,7 @@ use roc_mono::ir::{
use roc_mono::layout::{
CapturesNiche, LambdaName, Layout, LayoutCache, LayoutProblem, STLayoutInterner,
};
use roc_packaging::cache;
use roc_packaging::cache::{self, RocCacheDir};
use roc_parse::ast::{self, Defs, ExtractSpaces, Spaced, StrLiteral, TypeAnnotation};
use roc_parse::header::{ExposedName, ImportsEntry, PackageEntry, PlatformHeader, To, TypedIdent};
use roc_parse::header::{HeaderFor, ModuleNameEnum, PackageName};
@ -950,8 +950,6 @@ struct State<'a> {
type CachedTypeState = Arc<Mutex<MutMap<ModuleId, TypeState>>>;
const ROC_VERSION: &str = include_str!("../../../../version.txt");
impl<'a> State<'a> {
fn goal_phase(&self) -> Phase {
self.exec_mode.goal_phase()
@ -1211,7 +1209,7 @@ pub fn load_and_typecheck_str<'a>(
target_info: TargetInfo,
render: RenderTarget,
palette: Palette,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
threading: Threading,
) -> Result<LoadedModule, LoadingProblem<'a>> {
use LoadResult::*;
@ -1230,7 +1228,14 @@ pub fn load_and_typecheck_str<'a>(
exec_mode: ExecutionMode::Check,
};
match load(arena, load_start, exposed_types, cached_subs, load_config)? {
match load(
arena,
load_start,
exposed_types,
cached_subs,
roc_cache_dir,
load_config,
)? {
Monomorphized(_) => unreachable!(""),
TypeChecked(module) => Ok(module),
}
@ -1255,7 +1260,7 @@ impl<'a> LoadStart<'a> {
arena: &'a Bump,
filename: PathBuf,
render: RenderTarget,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
palette: Palette,
) -> Result<Self, LoadingProblem<'a>> {
let arc_modules = Arc::new(Mutex::new(PackageModuleIds::default()));
@ -1387,7 +1392,7 @@ impl<'a> LoadStart<'a> {
arena: &'a Bump,
filename: PathBuf,
src: &'a str,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
src_dir: PathBuf,
) -> Result<Self, LoadingProblem<'a>> {
let arc_modules = Arc::new(Mutex::new(PackageModuleIds::default()));
@ -1487,6 +1492,7 @@ pub fn load<'a>(
load_start: LoadStart<'a>,
exposed_types: ExposedByModule,
cached_types: MutMap<ModuleId, TypeState>,
roc_cache_dir: RocCacheDir<'_>,
load_config: LoadConfig,
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
enum Threads {
@ -1513,12 +1519,6 @@ pub fn load<'a>(
}
};
let roc_cache_dir = if let Some(dir) = cache::roc_cache_dir(ROC_VERSION) {
dir
} else {
return Err(LoadingProblem::CouldNotFindCacheDir);
};
match threads {
Threads::Single => load_single_threaded(
arena,
@ -1529,7 +1529,7 @@ pub fn load<'a>(
load_config.render,
load_config.palette,
load_config.exec_mode,
&roc_cache_dir,
roc_cache_dir,
),
Threads::Many(threads) => load_multi_threaded(
arena,
@ -1541,7 +1541,7 @@ pub fn load<'a>(
load_config.palette,
threads,
load_config.exec_mode,
&roc_cache_dir,
roc_cache_dir,
),
}
}
@ -1557,7 +1557,7 @@ pub fn load_single_threaded<'a>(
render: RenderTarget,
palette: Palette,
exec_mode: ExecutionMode,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
let LoadStart {
arc_modules,
@ -1618,7 +1618,7 @@ pub fn load_single_threaded<'a>(
&worker_msg_rx,
&msg_tx,
&src_dir,
&roc_cache_dir,
roc_cache_dir,
target_info,
);
@ -1813,7 +1813,7 @@ fn load_multi_threaded<'a>(
palette: Palette,
available_threads: usize,
exec_mode: ExecutionMode,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
let LoadStart {
arc_modules,
@ -1980,7 +1980,7 @@ fn worker_task_step<'a>(
worker_msg_rx: &crossbeam::channel::Receiver<WorkerMsg>,
msg_tx: &MsgSender<'a>,
src_dir: &Path,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
target_info: TargetInfo,
) -> Result<ControlFlow<(), ()>, LoadingProblem<'a>> {
match worker_msg_rx.try_recv() {
@ -2055,7 +2055,7 @@ fn worker_task<'a>(
worker_msg_rx: crossbeam::channel::Receiver<WorkerMsg>,
msg_tx: MsgSender<'a>,
src_dir: &Path,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
target_info: TargetInfo,
) -> Result<(), LoadingProblem<'a>> {
// Keep listening until we receive a Shutdown msg
@ -3167,7 +3167,7 @@ fn load_platform_module<'a>(
) -> Result<Msg<'a>, LoadingProblem<'a>> {
let module_start_time = Instant::now();
let file_io_start = Instant::now();
let file = fs::read(dbg!(filename));
let file = fs::read(filename);
let file_io_duration = file_io_start.elapsed();
match file {
@ -3304,7 +3304,7 @@ fn load_module<'a>(
module_name: PQModuleName<'a>,
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
arc_shorthands: Arc<Mutex<MutMap<&'a str, PackageName<'a>>>>,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
ident_ids_by_module: SharedIdentIdsByModule,
) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> {
let module_start_time = Instant::now();
@ -3492,7 +3492,7 @@ fn parse_header<'a>(
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
ident_ids_by_module: SharedIdentIdsByModule,
src_bytes: &'a [u8],
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
start_time: Instant,
) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> {
let parse_start = Instant::now();
@ -3731,7 +3731,7 @@ fn load_filename<'a>(
opt_expected_module_name: Option<PackageQualified<'a, ModuleName>>,
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
ident_ids_by_module: SharedIdentIdsByModule,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
module_start_time: Instant,
) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> {
let file_io_start = Instant::now();
@ -3768,7 +3768,7 @@ fn load_from_str<'a>(
src: &'a str,
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
ident_ids_by_module: SharedIdentIdsByModule,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
module_start_time: Instant,
) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> {
let file_io_start = Instant::now();
@ -5638,7 +5638,7 @@ fn run_task<'a>(
arena: &'a Bump,
src_dir: &Path,
msg_tx: MsgSender<'a>,
roc_cache_dir: &Path,
roc_cache_dir: RocCacheDir<'_>,
target_info: TargetInfo,
) -> Result<(), LoadingProblem<'a>> {
use BuildTask::*;

View file

@ -21,6 +21,7 @@ use roc_load_internal::file::{ExecutionMode, LoadConfig, Threading};
use roc_load_internal::file::{LoadResult, LoadStart, LoadedModule, LoadingProblem};
use roc_module::ident::ModuleName;
use roc_module::symbol::{Interns, ModuleId};
use roc_packaging::cache::RocCacheDir;
use roc_problem::can::Problem;
use roc_region::all::LineInfo;
use roc_reporting::report::RenderTarget;
@ -40,7 +41,13 @@ fn load_and_typecheck(
) -> Result<LoadedModule, LoadingProblem> {
use LoadResult::*;
let load_start = LoadStart::from_path(arena, filename, RenderTarget::Generic, DEFAULT_PALETTE)?;
let load_start = LoadStart::from_path(
arena,
filename,
RenderTarget::Generic,
RocCacheDir::Disallowed,
DEFAULT_PALETTE,
)?;
let load_config = LoadConfig {
target_info,
render: RenderTarget::Generic,
@ -54,6 +61,7 @@ fn load_and_typecheck(
load_start,
exposed_types,
Default::default(), // these tests will re-compile the builtins
RocCacheDir::Disallowed,
load_config,
)? {
Monomorphized(_) => unreachable!(""),

View file

@ -10,6 +10,7 @@ description = "The entry point of Roc's type inference system. Implements type i
roc_collections = { path = "../collections" }
roc_error_macros = { path = "../../error_macros" }
roc_exhaustive = { path = "../exhaustive" }
roc_packaging = { path = "../../packaging" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
roc_types = { path = "../types" }

View file

@ -18,6 +18,7 @@ mod solve_expr {
};
use roc_load::LoadedModule;
use roc_module::symbol::{Interns, ModuleId};
use roc_packaging::cache::RocCacheDir;
use roc_problem::can::Problem;
use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Region};
use roc_reporting::report::{can_problem, type_problem, RocDocAllocator};
@ -108,6 +109,7 @@ mod solve_expr {
exposed_types,
roc_target::TargetInfo::default_x86_64(),
roc_reporting::report::RenderTarget::Generic,
RocCacheDir::Disallowed,
roc_reporting::report::DEFAULT_PALETTE,
);
@ -7768,7 +7770,7 @@ mod solve_expr {
indoc!(
r#"
f : { x ? Str, y ? Str } -> {}
f {x : ""}
"#
),

View file

@ -20,6 +20,7 @@ roc_derive_key = { path = "../derive_key" }
roc_derive = { path = "../derive", features = ["debug-derived-symbols", "open-extension-vars"] }
roc_target = { path = "../roc_target" }
roc_types = { path = "../types" }
roc_packaging = { path = "../../packaging" }
roc_reporting = { path = "../../reporting" }
roc_constrain = { path = "../constrain" }
roc_region = { path = "../region" }

View file

@ -2,6 +2,7 @@ use std::fmt::Write as _; // import without risk of name clashing
use std::path::PathBuf;
use bumpalo::Bump;
use roc_packaging::cache::RocCacheDir;
use ven_pretty::DocAllocator;
use crate::pretty_print::{pretty_print_def, Ctx};
@ -490,6 +491,7 @@ where
target_info,
roc_reporting::report::RenderTarget::ColorTerminal,
roc_reporting::report::DEFAULT_PALETTE,
RocCacheDir::Disallowed,
Threading::AllAvailable,
)
.unwrap();

View file

@ -30,6 +30,7 @@ roc_unify = { path = "../unify" }
roc_utils = { path = "../../utils" }
roc_solve = { path = "../solve" }
roc_mono = { path = "../mono" }
roc_packaging = { path = "../../packaging" }
roc_reporting = { path = "../../reporting" }
roc_load = { path = "../load" }
roc_can = { path = "../can" }

View file

@ -9,6 +9,7 @@ use roc_gen_llvm::llvm::externs::add_default_roc_externs;
use roc_gen_llvm::{llvm::build::LlvmBackendMode, run_roc::RocCallResult};
use roc_load::{EntryPoint, ExecutionMode, LoadConfig, Threading};
use roc_mono::ir::OptLevel;
use roc_packaging::cache::RocCacheDir;
use roc_region::all::LineInfo;
use roc_reporting::report::{RenderTarget, DEFAULT_PALETTE};
use roc_utils::zig;
@ -80,6 +81,7 @@ fn create_llvm_module<'a>(
module_src,
src_dir,
Default::default(),
RocCacheDir::Disallowed,
load_config,
);

View file

@ -18,6 +18,7 @@ roc_load = { path = "../load" }
roc_can = { path = "../can" }
roc_mono = { path = "../mono" }
roc_target = { path = "../roc_target" }
roc_packaging = { path = "../../packaging" }
roc_reporting = { path = "../../reporting" }
roc_tracing = { path = "../../tracing" }

View file

@ -13,16 +13,15 @@ extern crate indoc;
#[allow(dead_code)]
const EXPANDED_STACK_SIZE: usize = 8 * 1024 * 1024;
use roc_collections::all::MutMap;
use roc_load::ExecutionMode;
use roc_load::LoadConfig;
use test_mono_macros::*;
use roc_collections::all::MutMap;
use roc_load::Threading;
use roc_module::symbol::Symbol;
use roc_mono::ir::Proc;
use roc_mono::ir::ProcLayout;
use roc_mono::layout::STLayoutInterner;
use test_mono_macros::*;
const TARGET_INFO: roc_target::TargetInfo = roc_target::TargetInfo::default_x86_64();
@ -76,6 +75,7 @@ fn promote_expr_to_module(src: &str) -> String {
fn compiles_to_ir(test_name: &str, src: &str) {
use bumpalo::Bump;
use roc_packaging::cache::RocCacheDir;
use std::path::PathBuf;
let arena = &Bump::new();
@ -107,6 +107,7 @@ fn compiles_to_ir(test_name: &str, src: &str) {
module_src,
src_dir,
Default::default(),
RocCacheDir::Disallowed,
load_config,
);
@ -1945,7 +1946,7 @@ fn unreachable_void_constructor() {
x : []
main = if Bool.true then Ok x else Err "abc"
main = if Bool.true then Ok x else Err "abc"
"#
)
}