DEBUG HACKS, DO NOT MERGE

This commit is contained in:
Brian Carroll 2022-02-14 22:24:51 +00:00
parent 3e511acbcc
commit e95d32e821
10 changed files with 120 additions and 7 deletions

3
Cargo.lock generated
View file

@ -3584,6 +3584,7 @@ dependencies = [
"roc_unify",
"tempfile",
"ven_pretty",
"wasm-bindgen",
]
[[package]]
@ -3698,6 +3699,7 @@ dependencies = [
"roc_reporting",
"roc_target",
"roc_types",
"wasm-bindgen",
]
[[package]]
@ -3763,6 +3765,7 @@ dependencies = [
"roc_types",
"roc_unify",
"tempfile",
"wasm-bindgen",
]
[[package]]

View file

@ -26,6 +26,7 @@ bumpalo = { version = "3.8.0", features = ["collections"] }
parking_lot = { version = "0.11.2" }
crossbeam = "0.8.1"
num_cpus = "1.13.0"
wasm-bindgen = "0.2.79"
[dev-dependencies]
tempfile = "3.2.0"

View file

@ -45,13 +45,26 @@ use std::path::{Path, PathBuf};
use std::str::from_utf8_unchecked;
use std::sync::Arc;
use std::{env, fs};
use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
// In-browser debugging
#[allow(unused_macros)]
macro_rules! console_log {
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}
use crate::work::{Dependencies, Phase};
#[cfg(not(target_family = "wasm"))]
use std::time::{Duration, SystemTime};
#[cfg(target_family = "wasm")]
use crate::wasm_system_time::{Duration, SystemTime};
#[cfg(not(target_family = "wasm"))]
use std::time::{Duration, SystemTime};
/// Default name for the binary generated for an app, if an invalid one was specified.
const DEFAULT_APP_OUTPUT_PATH: &str = "app";
@ -718,6 +731,7 @@ enum BuildTask<'a> {
},
}
#[derive(Debug)]
enum WorkerMsg {
Shutdown,
TaskAdded,
@ -831,6 +845,8 @@ pub fn load_and_monomorphize_from_str<'a>(
) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>> {
use LoadResult::*;
console_log!("load_and_monomorphize_from_str");
let load_start = LoadStart::from_str(arena, filename, src)?;
match load(
@ -997,6 +1013,8 @@ fn load<'a>(
goal_phase: Phase,
target_info: TargetInfo,
) -> Result<LoadResult<'a>, LoadingProblem<'a>> {
console_log!("load start");
let LoadStart {
arc_modules,
ident_ids_by_module,
@ -1008,10 +1026,14 @@ fn load<'a>(
let (msg_tx, msg_rx) = bounded(1024);
console_log!("before msg_tx.send");
msg_tx
.send(root_msg)
.map_err(|_| LoadingProblem::MsgChannelDied)?;
console_log!("after msg_tx.send");
let mut state = State {
root_id,
target_info,
@ -1038,15 +1060,21 @@ fn load<'a>(
// We'll add tasks to this, and then worker threads will take tasks from it.
let injector = Injector::new();
console_log!("after injector");
let (worker_msg_tx, worker_msg_rx) = bounded(1024);
let worker_listener = worker_msg_tx;
let worker_listeners = arena.alloc([worker_listener]);
console_log!("before Worker lifo");
let worker = Worker::new_lifo();
let stealer = worker.stealer();
let stealers = &[stealer];
console_log!("before loop");
loop {
console_log!("inside loop");
match state_thread_step(arena, state, worker_listeners, &injector, &msg_tx, &msg_rx) {
Ok(ControlFlow::Break(done)) => return Ok(done),
Ok(ControlFlow::Continue(new_state)) => {
@ -1054,8 +1082,9 @@ fn load<'a>(
}
Err(e) => return Err(e),
}
console_log!("after match");
match worker_task_step(
let control_flow = worker_task_step(
arena,
&worker,
&injector,
@ -1064,7 +1093,11 @@ fn load<'a>(
&msg_tx,
src_dir,
target_info,
) {
);
console_log!("control flow {:?}", control_flow);
match control_flow {
Ok(ControlFlow::Break(())) => panic!("the worker should not break!"),
Ok(ControlFlow::Continue(())) => {
// progress was made
@ -1453,7 +1486,10 @@ fn worker_task_step<'a>(
src_dir: &Path,
target_info: TargetInfo,
) -> Result<ControlFlow<(), ()>, LoadingProblem<'a>> {
match worker_msg_rx.try_recv() {
console_log!("worker_task_step");
let recv = worker_msg_rx.try_recv();
console_log!("recv {:?}", &recv);
match recv {
Ok(msg) => {
match msg {
WorkerMsg::Shutdown => {
@ -1474,8 +1510,10 @@ fn worker_task_step<'a>(
// added. In that case, do nothing, and keep waiting
// until we receive a Shutdown message.
if let Some(task) = find_task(&worker, injector, stealers) {
console_log!("found Some task {:?}", task);
let result =
run_task(task, worker_arena, src_dir, msg_tx.clone(), target_info);
console_log!("run_task result {:?}", &result);
match result {
Ok(()) => {}
@ -1495,6 +1533,7 @@ fn worker_task_step<'a>(
}
}
}
console_log!("after if let Some(task)");
Ok(ControlFlow::Continue(()))
}
@ -3129,12 +3168,15 @@ fn run_solve<'a>(
dep_idents: MutMap<ModuleId, IdentIds>,
unused_imports: MutMap<ModuleId, Region>,
) -> Msg<'a> {
console_log!("run_solve");
// We have more constraining work to do now, so we'll add it to our timings.
let constrain_start = SystemTime::now();
// Finish constraining the module by wrapping the existing Constraint
// in the ones we just computed. We can do this off the main thread.
let constraint = constrain_imports(imported_symbols, constraint, &mut var_store);
console_log!("after constrain_imports");
let constrain_end = SystemTime::now();
@ -3154,12 +3196,16 @@ fn run_solve<'a>(
let (solved_subs, solved_env, problems) =
roc_solve::module::run_solve(aliases, rigid_variables, constraint, var_store);
console_log!("after run_solve");
let mut exposed_vars_by_symbol: MutMap<Symbol, Variable> = solved_env.vars_by_symbol.clone();
exposed_vars_by_symbol.retain(|k, _| exposed_symbols.contains(k));
let solved_types =
roc_solve::module::make_solved_types(&solved_env, &solved_subs, &exposed_vars_by_symbol);
console_log!("after make_solved_types");
let solved_module = SolvedModule {
exposed_vars_by_symbol,
exposed_symbols: exposed_symbols.into_iter().collect::<Vec<_>>(),
@ -3175,6 +3221,8 @@ fn run_solve<'a>(
module_timing.constrain += constrain_elapsed;
module_timing.solve = solve_end.duration_since(constrain_end).unwrap();
console_log!("creating Msg::SolvedTypes");
// Send the subs to the main thread for processing,
Msg::SolvedTypes {
module_id,

View file

@ -14,6 +14,7 @@ roc_can = { path = "../can" }
roc_unify = { path = "../unify" }
arrayvec = "0.7.2"
bumpalo = { version = "3.8.0", features = ["collections"] }
wasm-bindgen = "0.2.79"
[dev-dependencies]
roc_load = { path = "../load" }

View file

@ -7,6 +7,20 @@ use roc_types::solved_types::{Solved, SolvedType};
use roc_types::subs::{Subs, VarStore, Variable};
use roc_types::types::Alias;
use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
// In-browser debugging
#[allow(unused_macros)]
macro_rules! console_log {
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}
#[derive(Debug)]
pub struct SolvedModule {
pub solved_types: MutMap<Symbol, SolvedType>,
@ -22,16 +36,20 @@ pub fn run_solve(
constraint: Constraint,
var_store: VarStore,
) -> (Solved<Subs>, solve::Env, Vec<solve::TypeError>) {
console_log!("run_solve");
let env = solve::Env {
vars_by_symbol: MutMap::default(),
aliases,
};
let mut subs = Subs::new_from_varstore(var_store);
console_log!("after new_from_varstore");
for (var, name) in rigid_variables {
subs.rigid_var(var, name);
}
console_log!("after rigid_var");
// Now that the module is parsed, canonicalized, and constrained,
// we need to type check it.
@ -39,6 +57,7 @@ pub fn run_solve(
// Run the solver to populate Subs.
let (solved_subs, solved_env) = solve::run(&env, &mut problems, subs, &constraint);
console_log!("after solve::run");
(solved_subs, solved_env, problems)
}

View file

@ -15,6 +15,22 @@ use roc_types::types::{gather_fields_unsorted_iter, Alias, Category, ErrorType,
use roc_unify::unify::{unify, Mode, Unified::*};
use std::collections::hash_map::Entry;
use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
// In-browser debugging
#[allow(unused_macros)]
macro_rules! console_log {
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}
// Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed
// https://github.com/elm/compiler
// Thank you, Evan!
@ -155,6 +171,7 @@ pub fn run_in_place(
subs: &mut Subs,
constraint: &Constraint,
) -> Env {
console_log!("run_in_place");
let mut pools = Pools::default();
let state = State {
env: env.clone(),
@ -186,6 +203,7 @@ fn solve(
subs: &mut Subs,
constraint: &Constraint,
) -> State {
console_log!("solve constraint {:?}", constraint);
match constraint {
True => state,
SaveTheEnvironment => {

View file

@ -7,6 +7,7 @@ version = "0.1.0"
[dependencies]
bumpalo = {version = "3.8.0", features = ["collections"]}
wasm-bindgen = "0.2.79"
roc_builtins = {path = "../compiler/builtins"}
roc_can = {path = "../compiler/can"}

View file

@ -8,9 +8,22 @@ use roc_load::file::{LoadingProblem, MonomorphizedModule};
use roc_parse::ast::Expr;
use roc_region::all::LineInfo;
use roc_target::TargetInfo;
use wasm_bindgen::prelude::wasm_bindgen;
use crate::eval::ToAstProblem;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
// In-browser debugging
#[allow(unused_macros)]
macro_rules! console_log {
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}
pub enum ReplOutput {
Problems(Vec<String>),
NoProblems { expr: String, expr_type: String },
@ -45,6 +58,8 @@ pub fn compile_to_mono<'a>(
src: &str,
target_info: TargetInfo,
) -> Result<MonomorphizedModule<'a>, Vec<String>> {
console_log!("compile_to_mono");
use roc_reporting::report::{
can_problem, mono_problem, type_problem, RocDocAllocator, DEFAULT_PALETTE,
};
@ -56,6 +71,9 @@ pub fn compile_to_mono<'a>(
let module_src = arena.alloc(promote_expr_to_module(src));
let exposed_types = MutMap::default();
console_log!("before load_and_monomorphize_from_str");
let loaded = roc_load::file::load_and_monomorphize_from_str(
arena,
filename,

View file

@ -31,7 +31,7 @@ extern "C" {
fn js_get_result_and_memory(buffer_alloc_addr: *mut u8) -> usize;
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
pub fn log(s: &str);
}
// In-browser debugging
@ -158,8 +158,10 @@ impl<'a> ReplApp<'a> for WasmReplApp<'a> {
#[wasm_bindgen]
pub async fn entrypoint_from_js(src: String) -> Result<String, String> {
console_log!("entrypoint_from_js");
let arena = &Bump::new();
let pre_linked_binary: &'static [u8] = include_bytes!("../data/pre_linked_binary.o");
console_log!("pre_linked_binary {}", pre_linked_binary.len());
// Compile the app
let target_info = TargetInfo::default_wasm32();

View file

@ -17,7 +17,9 @@ WWW_DIR="repl_www/build"
mkdir -p $WWW_DIR
cp repl_www/public/* $WWW_DIR
# Pass all script arguments through to wasm-pack (such as --release)
# Pass all script arguments through to wasm-pack
# For debugging, pass the --profiling option, which enables optimizations + debug info
# (We need optimizations to get rid of dead code that otherwise causes compile errors!)
wasm-pack build --target web "$@" repl_wasm
cp repl_wasm/pkg/*.wasm $WWW_DIR