Move src_dir into LoadStart

This commit is contained in:
Richard Feldman 2022-07-08 17:55:56 -04:00
parent 1364f1e518
commit a6d99aa357
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
9 changed files with 38 additions and 41 deletions

View file

@ -40,7 +40,7 @@ fn write_subs_for_module(module_id: ModuleId, filename: &str) {
&arena,
PathBuf::from(filename),
source,
&src_dir,
src_dir,
Default::default(),
target_info,
roc_reporting::report::RenderTarget::ColorTerminal,

View file

@ -7,7 +7,7 @@ use roc_module::symbol::{ModuleId, Symbol};
use roc_reporting::report::RenderTarget;
use roc_target::TargetInfo;
use roc_types::subs::{Subs, Variable};
use std::path::{Path, PathBuf};
use std::path::PathBuf;
pub use roc_load_internal::docs;
pub use roc_load_internal::file::{
@ -18,7 +18,6 @@ pub use roc_load_internal::file::{
fn load<'a>(
arena: &'a Bump,
load_start: LoadStart<'a>,
src_dir: &Path,
exposed_types: ExposedByModule,
goal_phase: Phase,
target_info: TargetInfo,
@ -30,7 +29,6 @@ fn load<'a>(
roc_load_internal::file::load(
arena,
load_start,
src_dir,
exposed_types,
goal_phase,
target_info,
@ -44,7 +42,6 @@ fn load<'a>(
pub fn load_single_threaded<'a>(
arena: &'a Bump,
load_start: LoadStart<'a>,
src_dir: &Path,
exposed_types: ExposedByModule,
goal_phase: Phase,
target_info: TargetInfo,
@ -55,7 +52,6 @@ pub fn load_single_threaded<'a>(
roc_load_internal::file::load_single_threaded(
arena,
load_start,
src_dir,
exposed_types,
goal_phase,
target_info,
@ -69,7 +65,7 @@ pub fn load_and_monomorphize_from_str<'a>(
arena: &'a Bump,
filename: PathBuf,
src: &'a str,
src_dir: &Path,
src_dir: PathBuf,
exposed_types: ExposedByModule,
target_info: TargetInfo,
render: RenderTarget,
@ -77,12 +73,11 @@ pub fn load_and_monomorphize_from_str<'a>(
) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_str(arena, filename, src)?;
let load_start = LoadStart::from_str(arena, filename, src, src_dir)?;
match load(
arena,
load_start,
src_dir,
exposed_types,
Phase::MakeSpecializations,
target_info,
@ -97,7 +92,7 @@ pub fn load_and_monomorphize_from_str<'a>(
pub fn load_and_monomorphize<'a>(
arena: &'a Bump,
filename: PathBuf,
src_dir: &Path,
src_dir: PathBuf,
exposed_types: ExposedByModule,
target_info: TargetInfo,
render: RenderTarget,
@ -105,12 +100,11 @@ pub fn load_and_monomorphize<'a>(
) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_path(arena, filename, render)?;
let load_start = LoadStart::from_path(arena, src_dir, filename, render)?;
match load(
arena,
load_start,
src_dir,
exposed_types,
Phase::MakeSpecializations,
target_info,
@ -125,7 +119,7 @@ pub fn load_and_monomorphize<'a>(
pub fn load_and_typecheck<'a>(
arena: &'a Bump,
filename: PathBuf,
src_dir: &Path,
src_dir: PathBuf,
exposed_types: ExposedByModule,
target_info: TargetInfo,
render: RenderTarget,
@ -133,12 +127,11 @@ pub fn load_and_typecheck<'a>(
) -> Result<LoadedModule, LoadingProblem<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_path(arena, filename, render)?;
let load_start = LoadStart::from_path(arena, src_dir, filename, render)?;
match load(
arena,
load_start,
src_dir,
exposed_types,
Phase::SolveTypes,
target_info,
@ -154,14 +147,14 @@ pub fn load_and_typecheck_str<'a>(
arena: &'a Bump,
filename: PathBuf,
source: &'a str,
src_dir: &Path,
src_dir: PathBuf,
exposed_types: ExposedByModule,
target_info: TargetInfo,
render: RenderTarget,
) -> Result<LoadedModule, LoadingProblem<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_str(arena, filename, source)?;
let load_start = LoadStart::from_str(arena, filename, source, 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
@ -169,7 +162,6 @@ pub fn load_and_typecheck_str<'a>(
match load_single_threaded(
arena,
load_start,
src_dir,
exposed_types,
Phase::SolveTypes,
target_info,

View file

@ -1067,7 +1067,7 @@ pub fn load_and_typecheck_str<'a>(
arena: &'a Bump,
filename: PathBuf,
source: &'a str,
src_dir: &Path,
src_dir: PathBuf,
exposed_types: ExposedByModule,
target_info: TargetInfo,
render: RenderTarget,
@ -1075,7 +1075,7 @@ pub fn load_and_typecheck_str<'a>(
) -> Result<LoadedModule, LoadingProblem<'a>> {
use LoadResult::*;
let load_start = LoadStart::from_str(arena, filename, source)?;
let load_start = LoadStart::from_str(arena, filename, source, src_dir)?;
// this function is used specifically in the case
// where we want to regenerate the cached data
@ -1084,7 +1084,6 @@ pub fn load_and_typecheck_str<'a>(
match load(
arena,
load_start,
src_dir,
exposed_types,
Phase::SolveTypes,
target_info,
@ -1108,11 +1107,13 @@ pub struct LoadStart<'a> {
ident_ids_by_module: SharedIdentIdsByModule,
root_id: ModuleId,
root_msg: Msg<'a>,
src_dir: PathBuf,
}
impl<'a> LoadStart<'a> {
pub fn from_path(
arena: &'a Bump,
mut src_dir: PathBuf,
filename: PathBuf,
render: RenderTarget,
) -> Result<Self, LoadingProblem<'a>> {
@ -1166,6 +1167,7 @@ impl<'a> LoadStart<'a> {
Ok(LoadStart {
arc_modules,
ident_ids_by_module,
src_dir,
root_id,
root_msg,
})
@ -1175,6 +1177,7 @@ impl<'a> LoadStart<'a> {
arena: &'a Bump,
filename: PathBuf,
src: &'a str,
src_dir: PathBuf,
) -> Result<Self, LoadingProblem<'a>> {
let arc_modules = Arc::new(Mutex::new(PackageModuleIds::default()));
let root_exposed_ident_ids = IdentIds::exposed_builtins(0);
@ -1196,6 +1199,7 @@ impl<'a> LoadStart<'a> {
Ok(LoadStart {
arc_modules,
src_dir,
ident_ids_by_module,
root_id,
root_msg,
@ -1269,7 +1273,6 @@ pub enum Threading {
pub fn load<'a>(
arena: &'a Bump,
load_start: LoadStart<'a>,
src_dir: &Path,
exposed_types: ExposedByModule,
goal_phase: Phase,
target_info: TargetInfo,
@ -1305,7 +1308,6 @@ pub fn load<'a>(
Threads::Single => load_single_threaded(
arena,
load_start,
src_dir,
exposed_types,
goal_phase,
target_info,
@ -1315,7 +1317,6 @@ pub fn load<'a>(
Threads::Many(threads) => load_multi_threaded(
arena,
load_start,
src_dir,
exposed_types,
goal_phase,
target_info,
@ -1331,7 +1332,6 @@ pub fn load<'a>(
pub fn load_single_threaded<'a>(
arena: &'a Bump,
load_start: LoadStart<'a>,
src_dir: &Path,
exposed_types: ExposedByModule,
goal_phase: Phase,
target_info: TargetInfo,
@ -1343,6 +1343,7 @@ pub fn load_single_threaded<'a>(
ident_ids_by_module,
root_id,
root_msg,
src_dir,
..
} = load_start;
@ -1394,7 +1395,7 @@ pub fn load_single_threaded<'a>(
stealers,
&worker_msg_rx,
&msg_tx,
src_dir,
&src_dir,
target_info,
);
@ -1532,7 +1533,6 @@ fn state_thread_step<'a>(
fn load_multi_threaded<'a>(
arena: &'a Bump,
load_start: LoadStart<'a>,
src_dir: &Path,
exposed_types: ExposedByModule,
goal_phase: Phase,
target_info: TargetInfo,
@ -1545,6 +1545,7 @@ fn load_multi_threaded<'a>(
ident_ids_by_module,
root_id,
root_msg,
src_dir,
..
} = load_start;
@ -1622,8 +1623,9 @@ fn load_multi_threaded<'a>(
// We only want to move a *reference* to the main task queue's
// injector in the thread, not the injector itself
// (since other threads need to reference it too).
// (since other threads need to reference it too). Same with src_dir.
let injector = &injector;
let src_dir = &src_dir;
// Record this thread's handle so the main thread can join it later.
let res_join_handle = thread_scope