mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-17 13:47:26 +03:00
thread top-level expect region through
This commit is contained in:
parent
7e5476aa58
commit
9d294b459e
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3920,6 +3920,7 @@ dependencies = [
|
||||
"roc_module",
|
||||
"roc_mono",
|
||||
"roc_parse",
|
||||
"roc_region",
|
||||
"roc_repl_eval",
|
||||
"roc_reporting",
|
||||
"roc_std",
|
||||
|
@ -9,10 +9,10 @@ use roc_collections::VecMap;
|
||||
use roc_error_macros::{internal_error, user_error};
|
||||
use roc_gen_llvm::llvm::build::LlvmBackendMode;
|
||||
use roc_load::{Expectations, LoadingProblem, Threading};
|
||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||
use roc_module::symbol::{Interns, ModuleId};
|
||||
use roc_mono::ir::OptLevel;
|
||||
use roc_region::all::Region;
|
||||
use roc_repl_cli::expect_mono_module_to_dylib;
|
||||
use roc_repl_cli::{expect_mono_module_to_dylib, ToplevelExpect};
|
||||
use roc_target::TargetInfo;
|
||||
use std::env;
|
||||
use std::ffi::{CString, OsStr};
|
||||
@ -423,10 +423,10 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
||||
0,
|
||||
);
|
||||
|
||||
for (expect_symbol, expect_name) in expects {
|
||||
for expect in expects {
|
||||
libc::memset(shared_ptr.cast(), 0, SHM_SIZE as _);
|
||||
|
||||
let result: Result<(), String> = try_run_jit_function!(lib, expect_name, (), |v: ()| v);
|
||||
let result: Result<(), String> = try_run_jit_function!(lib, expect.name, (), |v: ()| v);
|
||||
|
||||
let shared_memory_ptr: *const u8 = shared_ptr.cast();
|
||||
|
||||
@ -436,7 +436,7 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
||||
failed += 1;
|
||||
render_expect_panic(
|
||||
arena,
|
||||
expect_symbol,
|
||||
expect,
|
||||
&roc_panic_message,
|
||||
&mut expectations,
|
||||
interns,
|
||||
@ -1023,12 +1023,53 @@ unsafe fn roc_run_native_debug(
|
||||
|
||||
fn render_expect_panic<'a>(
|
||||
_arena: &'a Bump,
|
||||
_expect_symbol: Symbol,
|
||||
expect: ToplevelExpect,
|
||||
message: &str,
|
||||
_expectations: &mut VecMap<ModuleId, Expectations>,
|
||||
_interns: &'a Interns,
|
||||
expectations: &mut VecMap<ModuleId, Expectations>,
|
||||
interns: &'a Interns,
|
||||
) {
|
||||
println!("Expect panicked: {}", message);
|
||||
use roc_reporting::report::Report;
|
||||
use roc_reporting::report::RocDocAllocator;
|
||||
use ven_pretty::DocAllocator;
|
||||
|
||||
let module_id = expect.symbol.module_id();
|
||||
let data = expectations.get_mut(&module_id).unwrap();
|
||||
|
||||
// TODO cache these line offsets?
|
||||
let path = &data.path;
|
||||
let filename = data.path.to_owned();
|
||||
let file_string = std::fs::read_to_string(path).unwrap();
|
||||
let src_lines: Vec<_> = file_string.lines().collect();
|
||||
|
||||
let line_info = roc_region::all::LineInfo::new(&file_string);
|
||||
let line_col_region = line_info.convert_region(expect.region);
|
||||
|
||||
let alloc = RocDocAllocator::new(&src_lines, module_id, interns);
|
||||
|
||||
let doc = alloc.stack([
|
||||
alloc.text("This expectation panicked:"),
|
||||
alloc.region(line_col_region),
|
||||
alloc.text("With this panic message:"),
|
||||
alloc.text(message),
|
||||
]);
|
||||
|
||||
let report = Report {
|
||||
title: "EXPECT FAILED".into(),
|
||||
doc,
|
||||
filename,
|
||||
severity: roc_reporting::report::Severity::RuntimeError,
|
||||
};
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
report.render(
|
||||
roc_reporting::report::RenderTarget::ColorTerminal,
|
||||
&mut buf,
|
||||
&alloc,
|
||||
&roc_reporting::report::DEFAULT_PALETTE,
|
||||
);
|
||||
|
||||
println!("{}", buf);
|
||||
}
|
||||
|
||||
fn render_expect_failure<'a>(
|
||||
|
@ -118,6 +118,10 @@ impl<K: PartialEq, V> VecMap<K, V> {
|
||||
(self.keys, self.values)
|
||||
}
|
||||
|
||||
pub fn unzip_slices(&self) -> (&[K], &[V]) {
|
||||
(&self.keys, &self.values)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// keys and values must have the same length, and there must not
|
||||
|
@ -672,7 +672,7 @@ pub struct MonomorphizedModule<'a> {
|
||||
pub can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
|
||||
pub type_problems: MutMap<ModuleId, Vec<solve::TypeError>>,
|
||||
pub procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||
pub toplevel_expects: Vec<Symbol>,
|
||||
pub toplevel_expects: VecMap<Symbol, Region>,
|
||||
pub entry_point: EntryPoint<'a>,
|
||||
pub exposed_to_host: ExposedToHost,
|
||||
pub sources: MutMap<ModuleId, (PathBuf, Box<str>)>,
|
||||
@ -767,7 +767,7 @@ enum Msg<'a> {
|
||||
solved_subs: Solved<Subs>,
|
||||
module_timing: ModuleTiming,
|
||||
abilities_store: AbilitiesStore,
|
||||
toplevel_expects: std::vec::Vec<Symbol>,
|
||||
toplevel_expects: VecMap<Symbol, Region>,
|
||||
},
|
||||
MadeSpecializations {
|
||||
module_id: ModuleId,
|
||||
@ -855,7 +855,7 @@ struct State<'a> {
|
||||
pub module_cache: ModuleCache<'a>,
|
||||
pub dependencies: Dependencies<'a>,
|
||||
pub procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||
pub toplevel_expects: Vec<Symbol>,
|
||||
pub toplevel_expects: VecMap<Symbol, Region>,
|
||||
pub exposed_to_host: ExposedToHost,
|
||||
|
||||
/// This is the "final" list of IdentIds, after canonicalization and constraint gen
|
||||
@ -924,7 +924,7 @@ impl<'a> State<'a> {
|
||||
module_cache: ModuleCache::default(),
|
||||
dependencies,
|
||||
procedures: MutMap::default(),
|
||||
toplevel_expects: Vec::new(),
|
||||
toplevel_expects: VecMap::default(),
|
||||
exposed_to_host: ExposedToHost::default(),
|
||||
exposed_types,
|
||||
arc_modules,
|
||||
@ -4715,7 +4715,7 @@ fn build_pending_specializations<'a>(
|
||||
let find_specializations_start = SystemTime::now();
|
||||
|
||||
let mut module_thunks = bumpalo::collections::Vec::new_in(arena);
|
||||
let mut toplevel_expects = std::vec::Vec::new();
|
||||
let mut toplevel_expects = VecMap::default();
|
||||
|
||||
let mut procs_base = ProcsBase {
|
||||
partial_procs: BumpMap::default(),
|
||||
@ -5014,7 +5014,9 @@ fn build_pending_specializations<'a>(
|
||||
is_self_recursive: false,
|
||||
};
|
||||
|
||||
toplevel_expects.push(symbol);
|
||||
let region = declarations.expressions[index].region;
|
||||
|
||||
toplevel_expects.insert(symbol, region);
|
||||
procs_base.partial_procs.insert(symbol, proc);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ rustyline = {git = "https://github.com/rtfeldman/rustyline", rev = "e74333c"}
|
||||
rustyline-derive = {git = "https://github.com/rtfeldman/rustyline", rev = "e74333c"}
|
||||
target-lexicon = "0.12.2"
|
||||
|
||||
# TODO: make llvm optional
|
||||
roc_build = {path = "../compiler/build"}
|
||||
roc_builtins = {path = "../compiler/builtins"}
|
||||
roc_collections = {path = "../compiler/collections"}
|
||||
@ -35,7 +34,7 @@ roc_reporting = {path = "../reporting"}
|
||||
roc_std = {path = "../roc_std", default-features = false}
|
||||
roc_target = {path = "../compiler/roc_target"}
|
||||
roc_types = {path = "../compiler/types"}
|
||||
|
||||
roc_region = { path = "../compiler/region" }
|
||||
roc_module = { path = "../compiler/module" }
|
||||
|
||||
[lib]
|
||||
|
@ -1,9 +1,11 @@
|
||||
use bumpalo::collections::Vec as BumpVec;
|
||||
use bumpalo::Bump;
|
||||
use const_format::concatcp;
|
||||
use inkwell::context::Context;
|
||||
use libloading::Library;
|
||||
use roc_gen_llvm::llvm::build::LlvmBackendMode;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_region::all::Region;
|
||||
use roc_types::subs::Subs;
|
||||
use rustyline::highlight::{Highlighter, PromptInfo};
|
||||
use rustyline::validate::{self, ValidationContext, ValidationResult, Validator};
|
||||
@ -193,19 +195,20 @@ impl ReplAppMemory for CliMemory {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ToplevelExpect<'a> {
|
||||
pub name: &'a str,
|
||||
pub symbol: Symbol,
|
||||
pub region: Region,
|
||||
}
|
||||
|
||||
pub fn expect_mono_module_to_dylib<'a>(
|
||||
arena: &'a Bump,
|
||||
target: Triple,
|
||||
loaded: MonomorphizedModule<'a>,
|
||||
opt_level: OptLevel,
|
||||
mode: LlvmBackendMode,
|
||||
) -> Result<
|
||||
(
|
||||
libloading::Library,
|
||||
bumpalo::collections::Vec<'a, (Symbol, &'a str)>,
|
||||
),
|
||||
libloading::Error,
|
||||
> {
|
||||
) -> Result<(libloading::Library, BumpVec<'a, ToplevelExpect<'a>>), libloading::Error> {
|
||||
let target_info = TargetInfo::from(&target);
|
||||
|
||||
let MonomorphizedModule {
|
||||
@ -250,13 +253,20 @@ pub fn expect_mono_module_to_dylib<'a>(
|
||||
let expect_names = roc_gen_llvm::llvm::build::build_procedures_expose_expects(
|
||||
&env,
|
||||
opt_level,
|
||||
&toplevel_expects,
|
||||
toplevel_expects.unzip_slices().0,
|
||||
procedures,
|
||||
entry_point,
|
||||
);
|
||||
|
||||
let expects = bumpalo::collections::Vec::from_iter_in(
|
||||
toplevel_expects.into_iter().zip(expect_names.into_iter()),
|
||||
toplevel_expects
|
||||
.into_iter()
|
||||
.zip(expect_names.into_iter())
|
||||
.map(|((symbol, region), name)| ToplevelExpect {
|
||||
symbol,
|
||||
region,
|
||||
name,
|
||||
}),
|
||||
env.arena,
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user