mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Consolidate variable pretty printing
This commit is contained in:
parent
3de35f7aa2
commit
a9507cf917
7 changed files with 28 additions and 43 deletions
|
@ -1937,7 +1937,7 @@ pub mod test_constrain {
|
|||
use roc_parse::parser::{SourceError, SyntaxError};
|
||||
use roc_region::all::Region;
|
||||
use roc_types::{
|
||||
pretty_print::{content_to_string, name_all_type_vars},
|
||||
pretty_print::name_and_print_var,
|
||||
solved_types::Solved,
|
||||
subs::{Subs, VarStore, Variable},
|
||||
};
|
||||
|
@ -2050,11 +2050,6 @@ pub mod test_constrain {
|
|||
|
||||
let subs = solved.inner_mut();
|
||||
|
||||
// name type vars
|
||||
let named_result = name_all_type_vars(var, subs);
|
||||
|
||||
let content = subs.get_content_without_compacting(var);
|
||||
|
||||
// Connect the ModuleId to it's IdentIds
|
||||
dep_idents.insert(mod_id, env.ident_ids);
|
||||
|
||||
|
@ -2063,7 +2058,7 @@ pub mod test_constrain {
|
|||
all_ident_ids: dep_idents,
|
||||
};
|
||||
|
||||
let actual_str = content_to_string(content, subs, mod_id, &interns, named_result);
|
||||
let actual_str = name_and_print_var(var, subs, mod_id, &interns);
|
||||
|
||||
assert_eq!(actual_str, expected_str);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ mod test_load {
|
|||
use roc_reporting::report::RenderTarget;
|
||||
use roc_reporting::report::RocDocAllocator;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_types::pretty_print::{content_to_string, name_all_type_vars};
|
||||
use roc_types::pretty_print::name_and_print_var;
|
||||
use roc_types::subs::Subs;
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -237,10 +237,7 @@ mod test_load {
|
|||
expected_types: &mut HashMap<&str, &str>,
|
||||
) {
|
||||
for (symbol, expr_var) in &def.pattern_vars {
|
||||
let named_result = name_all_type_vars(*expr_var, subs);
|
||||
|
||||
let content = subs.get_content_without_compacting(*expr_var);
|
||||
let actual_str = content_to_string(content, subs, home, interns, named_result);
|
||||
let actual_str = name_and_print_var(*expr_var, subs, home, interns);
|
||||
let fully_qualified = symbol.fully_qualified(interns, home).to_string();
|
||||
let expected_type = expected_types
|
||||
.remove(fully_qualified.as_str())
|
||||
|
|
|
@ -19,7 +19,7 @@ mod solve_expr {
|
|||
use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Region};
|
||||
use roc_reporting::report::{can_problem, type_problem, RocDocAllocator};
|
||||
use roc_solve::solve::TypeError;
|
||||
use roc_types::pretty_print::{content_to_string, name_all_type_vars};
|
||||
use roc_types::pretty_print::name_and_print_var;
|
||||
use std::path::PathBuf;
|
||||
|
||||
// HELPERS
|
||||
|
@ -174,10 +174,7 @@ mod solve_expr {
|
|||
|
||||
debug_assert!(exposed_to_host.len() == 1);
|
||||
let (_symbol, variable) = exposed_to_host.into_iter().next().unwrap();
|
||||
let named_result = name_all_type_vars(variable, subs);
|
||||
let content = subs.get_content_without_compacting(variable);
|
||||
|
||||
let actual_str = content_to_string(content, subs, home, &interns, named_result);
|
||||
let actual_str = name_and_print_var(variable, subs, home, &interns);
|
||||
|
||||
Ok((type_problems, can_problems, actual_str))
|
||||
}
|
||||
|
@ -276,9 +273,7 @@ mod solve_expr {
|
|||
let var = find_type_at(region, &decls)
|
||||
.expect(&format!("No type for {} ({:?})!", &text, region));
|
||||
|
||||
let named_result = name_all_type_vars(var, subs);
|
||||
let content = subs.get_content_without_compacting(var);
|
||||
let actual_str = content_to_string(content, subs, home, &interns, named_result);
|
||||
let actual_str = name_and_print_var(var, subs, home, &interns);
|
||||
|
||||
solved_queries.push(format!("{} : {}", text, actual_str));
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ struct Context<'a> {
|
|||
recursion_structs_to_expand: Vec<Variable>,
|
||||
}
|
||||
|
||||
pub fn content_to_string(
|
||||
fn content_to_string(
|
||||
content: &Content,
|
||||
subs: &Subs,
|
||||
home: ModuleId,
|
||||
|
@ -364,6 +364,17 @@ pub fn content_to_string(
|
|||
buf
|
||||
}
|
||||
|
||||
pub fn name_and_print_var(
|
||||
var: Variable,
|
||||
subs: &mut Subs,
|
||||
home: ModuleId,
|
||||
interns: &Interns,
|
||||
) -> String {
|
||||
let named_result = name_all_type_vars(var, subs);
|
||||
let content = subs.get_content_without_compacting(var);
|
||||
content_to_string(content, subs, home, interns, named_result)
|
||||
}
|
||||
|
||||
pub fn get_single_arg<'a>(subs: &'a Subs, args: &'a AliasVariables) -> &'a Content {
|
||||
debug_assert_eq!(args.len(), 1);
|
||||
|
||||
|
|
|
@ -59,10 +59,9 @@ use roc_collections::all::MutMap;
|
|||
use roc_module::ident::Lowercase;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_region::all::Region;
|
||||
use roc_types::pretty_print::name_all_type_vars;
|
||||
use roc_types::pretty_print::name_and_print_var;
|
||||
use roc_types::solved_types::Solved;
|
||||
use roc_types::subs::{Subs, Variable};
|
||||
use roc_types::{pretty_print::content_to_string, subs::VarStore};
|
||||
use roc_types::subs::{Subs, VarStore, Variable};
|
||||
use snafu::OptionExt;
|
||||
use threadpool::ThreadPool;
|
||||
use winit::event::VirtualKeyCode;
|
||||
|
@ -463,20 +462,10 @@ impl<'a> EdModel<'a> {
|
|||
|
||||
let subs = solved.inner_mut();
|
||||
|
||||
let named_result = name_all_type_vars(var, subs);
|
||||
let pretty_var =
|
||||
name_and_print_var(var, subs, self.module.env.home, &self.loaded_module.interns);
|
||||
|
||||
let content = subs.get_content_without_compacting(var);
|
||||
|
||||
PoolStr::new(
|
||||
&content_to_string(
|
||||
content,
|
||||
subs,
|
||||
self.module.env.home,
|
||||
&self.loaded_module.interns,
|
||||
named_result,
|
||||
),
|
||||
self.module.env.pool,
|
||||
)
|
||||
PoolStr::new(&pretty_var, self.module.env.pool)
|
||||
}
|
||||
|
||||
fn run_solve(
|
||||
|
|
|
@ -23,7 +23,7 @@ use roc_repl_eval::{ReplApp, ReplAppMemory};
|
|||
use roc_reporting::report::DEFAULT_PALETTE;
|
||||
use roc_std::RocStr;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_types::pretty_print::{content_to_string, name_all_type_vars};
|
||||
use roc_types::pretty_print::name_and_print_var;
|
||||
|
||||
const BLUE: &str = "\u{001b}[36m";
|
||||
const PINK: &str = "\u{001b}[35m";
|
||||
|
@ -227,9 +227,8 @@ fn gen_and_eval_llvm<'a>(
|
|||
let main_fn_var = *main_fn_var;
|
||||
|
||||
// pretty-print the expr type string for later.
|
||||
let named_result = name_all_type_vars(main_fn_var, &mut subs);
|
||||
let expr_type_str = name_and_print_var(main_fn_var, &mut subs, home, &interns);
|
||||
let content = subs.get_content_without_compacting(main_fn_var);
|
||||
let expr_type_str = content_to_string(content, &subs, home, &interns, named_result);
|
||||
|
||||
let (_, main_fn_layout) = match procedures.keys().find(|(s, _)| *s == main_fn_symbol) {
|
||||
Some(layout) => *layout,
|
||||
|
|
|
@ -12,7 +12,7 @@ use roc_repl_eval::{
|
|||
};
|
||||
use roc_reporting::report::DEFAULT_PALETTE_HTML;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_types::pretty_print::{content_to_string, name_all_type_vars};
|
||||
use roc_types::pretty_print::name_and_print_var;
|
||||
|
||||
use crate::{js_create_app, js_get_result_and_memory, js_run_app};
|
||||
|
||||
|
@ -184,9 +184,8 @@ pub async fn entrypoint_from_js(src: String) -> Result<String, String> {
|
|||
let main_fn_var = *main_fn_var;
|
||||
|
||||
// pretty-print the expr type string for later.
|
||||
let named_result = name_all_type_vars(main_fn_var, &mut subs);
|
||||
let expr_type_str = name_and_print_var(main_fn_var, &mut subs, module_id, &interns);
|
||||
let content = subs.get_content_without_compacting(main_fn_var);
|
||||
let expr_type_str = content_to_string(content, &subs, module_id, &interns, named_result);
|
||||
|
||||
let (_, main_fn_layout) = match procedures.keys().find(|(s, _)| *s == main_fn_symbol) {
|
||||
Some(layout) => *layout,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue