mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
thread Mode through
This commit is contained in:
parent
dc199fe527
commit
ec7e8804ac
1 changed files with 38 additions and 19 deletions
|
@ -265,6 +265,7 @@ fn start_phase<'a>(module_id: ModuleId, phase: Phase, state: &mut State<'a>) ->
|
||||||
// so other modules can populate them as they load.
|
// so other modules can populate them as they load.
|
||||||
module_ids: Arc::clone(&state.arc_modules),
|
module_ids: Arc::clone(&state.arc_modules),
|
||||||
ident_ids_by_module: Arc::clone(&state.ident_ids_by_module),
|
ident_ids_by_module: Arc::clone(&state.ident_ids_by_module),
|
||||||
|
mode: state.stdlib.mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Phase::Parse => {
|
Phase::Parse => {
|
||||||
|
@ -715,6 +716,7 @@ enum BuildTask<'a> {
|
||||||
module_name: ModuleName,
|
module_name: ModuleName,
|
||||||
module_ids: Arc<Mutex<ModuleIds>>,
|
module_ids: Arc<Mutex<ModuleIds>>,
|
||||||
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||||
|
mode: Mode,
|
||||||
},
|
},
|
||||||
Parse {
|
Parse {
|
||||||
header: ModuleHeader<'a>,
|
header: ModuleHeader<'a>,
|
||||||
|
@ -810,7 +812,7 @@ pub fn load_and_typecheck(
|
||||||
) -> Result<LoadedModule, LoadingProblem> {
|
) -> Result<LoadedModule, LoadingProblem> {
|
||||||
use LoadResult::*;
|
use LoadResult::*;
|
||||||
|
|
||||||
let load_start = LoadStart::from_path(arena, filename)?;
|
let load_start = LoadStart::from_path(arena, filename, stdlib.mode)?;
|
||||||
|
|
||||||
match load(
|
match load(
|
||||||
arena,
|
arena,
|
||||||
|
@ -834,7 +836,7 @@ pub fn load_and_monomorphize<'a>(
|
||||||
) -> Result<MonomorphizedModule<'a>, LoadingProblem> {
|
) -> Result<MonomorphizedModule<'a>, LoadingProblem> {
|
||||||
use LoadResult::*;
|
use LoadResult::*;
|
||||||
|
|
||||||
let load_start = LoadStart::from_path(arena, filename)?;
|
let load_start = LoadStart::from_path(arena, filename, stdlib.mode)?;
|
||||||
|
|
||||||
match load(
|
match load(
|
||||||
arena,
|
arena,
|
||||||
|
@ -859,7 +861,7 @@ pub fn load_and_monomorphize_from_str<'a>(
|
||||||
) -> Result<MonomorphizedModule<'a>, LoadingProblem> {
|
) -> Result<MonomorphizedModule<'a>, LoadingProblem> {
|
||||||
use LoadResult::*;
|
use LoadResult::*;
|
||||||
|
|
||||||
let load_start = LoadStart::from_str(arena, filename, src)?;
|
let load_start = LoadStart::from_str(arena, filename, src, stdlib.mode)?;
|
||||||
|
|
||||||
match load(
|
match load(
|
||||||
arena,
|
arena,
|
||||||
|
@ -882,7 +884,11 @@ struct LoadStart<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LoadStart<'a> {
|
impl<'a> LoadStart<'a> {
|
||||||
pub fn from_path(arena: &'a Bump, filename: PathBuf) -> Result<Self, LoadingProblem> {
|
pub fn from_path(
|
||||||
|
arena: &'a Bump,
|
||||||
|
filename: PathBuf,
|
||||||
|
mode: Mode,
|
||||||
|
) -> Result<Self, LoadingProblem> {
|
||||||
let arc_modules = Arc::new(Mutex::new(ModuleIds::default()));
|
let arc_modules = Arc::new(Mutex::new(ModuleIds::default()));
|
||||||
let root_exposed_ident_ids = IdentIds::exposed_builtins(0);
|
let root_exposed_ident_ids = IdentIds::exposed_builtins(0);
|
||||||
let ident_ids_by_module = Arc::new(Mutex::new(root_exposed_ident_ids));
|
let ident_ids_by_module = Arc::new(Mutex::new(root_exposed_ident_ids));
|
||||||
|
@ -897,6 +903,7 @@ impl<'a> LoadStart<'a> {
|
||||||
Arc::clone(&arc_modules),
|
Arc::clone(&arc_modules),
|
||||||
Arc::clone(&ident_ids_by_module),
|
Arc::clone(&ident_ids_by_module),
|
||||||
root_start_time,
|
root_start_time,
|
||||||
|
mode,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -912,6 +919,7 @@ impl<'a> LoadStart<'a> {
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
src: &'a str,
|
src: &'a str,
|
||||||
|
mode: Mode,
|
||||||
) -> Result<Self, LoadingProblem> {
|
) -> Result<Self, LoadingProblem> {
|
||||||
let arc_modules = Arc::new(Mutex::new(ModuleIds::default()));
|
let arc_modules = Arc::new(Mutex::new(ModuleIds::default()));
|
||||||
let root_exposed_ident_ids = IdentIds::exposed_builtins(0);
|
let root_exposed_ident_ids = IdentIds::exposed_builtins(0);
|
||||||
|
@ -928,6 +936,7 @@ impl<'a> LoadStart<'a> {
|
||||||
Arc::clone(&arc_modules),
|
Arc::clone(&arc_modules),
|
||||||
Arc::clone(&ident_ids_by_module),
|
Arc::clone(&ident_ids_by_module),
|
||||||
root_start_time,
|
root_start_time,
|
||||||
|
mode,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1701,6 +1710,7 @@ fn load_module<'a>(
|
||||||
module_name: ModuleName,
|
module_name: ModuleName,
|
||||||
module_ids: Arc<Mutex<ModuleIds>>,
|
module_ids: Arc<Mutex<ModuleIds>>,
|
||||||
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||||
|
mode: Mode,
|
||||||
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
||||||
let module_start_time = SystemTime::now();
|
let module_start_time = SystemTime::now();
|
||||||
let mut filename = PathBuf::new();
|
let mut filename = PathBuf::new();
|
||||||
|
@ -1721,6 +1731,7 @@ fn load_module<'a>(
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
module_start_time,
|
module_start_time,
|
||||||
|
mode,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1756,6 +1767,7 @@ fn parse_header<'a>(
|
||||||
filename: PathBuf,
|
filename: PathBuf,
|
||||||
module_ids: Arc<Mutex<ModuleIds>>,
|
module_ids: Arc<Mutex<ModuleIds>>,
|
||||||
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||||
|
mode: Mode,
|
||||||
src_bytes: &'a [u8],
|
src_bytes: &'a [u8],
|
||||||
start_time: SystemTime,
|
start_time: SystemTime,
|
||||||
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
||||||
|
@ -1791,19 +1803,14 @@ fn parse_header<'a>(
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
module_timing,
|
module_timing,
|
||||||
)),
|
)),
|
||||||
Ok((ast::Module::Platform { header }, _parse_state)) => {
|
Ok((ast::Module::Platform { header }, _parse_state)) => fabricate_effects_module(
|
||||||
// TODO don't hardcode the mode
|
arena,
|
||||||
let mode = Mode::Standard;
|
module_ids,
|
||||||
|
ident_ids_by_module,
|
||||||
fabricate_effects_module(
|
mode,
|
||||||
arena,
|
header,
|
||||||
module_ids,
|
module_timing,
|
||||||
ident_ids_by_module,
|
),
|
||||||
mode,
|
|
||||||
header,
|
|
||||||
module_timing,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Err((fail, _)) => Err(LoadingProblem::ParsingFailed { filename, fail }),
|
Err((fail, _)) => Err(LoadingProblem::ParsingFailed { filename, fail }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1815,6 +1822,7 @@ fn load_filename<'a>(
|
||||||
module_ids: Arc<Mutex<ModuleIds>>,
|
module_ids: Arc<Mutex<ModuleIds>>,
|
||||||
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||||
module_start_time: SystemTime,
|
module_start_time: SystemTime,
|
||||||
|
mode: Mode,
|
||||||
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
||||||
let file_io_start = SystemTime::now();
|
let file_io_start = SystemTime::now();
|
||||||
let file = fs::read(&filename);
|
let file = fs::read(&filename);
|
||||||
|
@ -1827,6 +1835,7 @@ fn load_filename<'a>(
|
||||||
filename,
|
filename,
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
|
mode,
|
||||||
arena.alloc(bytes),
|
arena.alloc(bytes),
|
||||||
module_start_time,
|
module_start_time,
|
||||||
),
|
),
|
||||||
|
@ -1846,6 +1855,7 @@ fn load_from_str<'a>(
|
||||||
module_ids: Arc<Mutex<ModuleIds>>,
|
module_ids: Arc<Mutex<ModuleIds>>,
|
||||||
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||||
module_start_time: SystemTime,
|
module_start_time: SystemTime,
|
||||||
|
mode: Mode,
|
||||||
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
||||||
let file_io_start = SystemTime::now();
|
let file_io_start = SystemTime::now();
|
||||||
let file_io_duration = file_io_start.elapsed().unwrap();
|
let file_io_duration = file_io_start.elapsed().unwrap();
|
||||||
|
@ -1856,6 +1866,7 @@ fn load_from_str<'a>(
|
||||||
filename,
|
filename,
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
|
mode,
|
||||||
src.as_bytes(),
|
src.as_bytes(),
|
||||||
module_start_time,
|
module_start_time,
|
||||||
)
|
)
|
||||||
|
@ -3134,8 +3145,16 @@ fn run_task<'a>(
|
||||||
module_name,
|
module_name,
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
} => load_module(arena, src_dir, module_name, module_ids, ident_ids_by_module)
|
mode,
|
||||||
.map(|(_, msg)| msg),
|
} => load_module(
|
||||||
|
arena,
|
||||||
|
src_dir,
|
||||||
|
module_name,
|
||||||
|
module_ids,
|
||||||
|
ident_ids_by_module,
|
||||||
|
mode,
|
||||||
|
)
|
||||||
|
.map(|(_, msg)| msg),
|
||||||
Parse { header } => parse(arena, header),
|
Parse { header } => parse(arena, header),
|
||||||
CanonicalizeAndConstrain {
|
CanonicalizeAndConstrain {
|
||||||
parsed,
|
parsed,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue