Drop an unused Result

This commit is contained in:
Richard Feldman 2022-10-27 03:45:25 -04:00
parent 6fbafad3ff
commit f11b2d21cb
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 13 additions and 20 deletions

View file

@ -11,7 +11,6 @@ use roc_load::{EntryPoint, MonomorphizedModule};
use roc_mono::ir::OptLevel; use roc_mono::ir::OptLevel;
use roc_mono::layout::Layout; use roc_mono::layout::Layout;
use roc_parse::ast::Expr; use roc_parse::ast::Expr;
use roc_parse::parser::SyntaxError;
use roc_repl_eval::eval::jit_to_ast; use roc_repl_eval::eval::jit_to_ast;
use roc_repl_eval::gen::{compile_to_mono, format_answer, ReplOutput}; use roc_repl_eval::gen::{compile_to_mono, format_answer, ReplOutput};
use roc_repl_eval::{ReplApp, ReplAppMemory}; use roc_repl_eval::{ReplApp, ReplAppMemory};
@ -27,14 +26,14 @@ pub fn gen_and_eval_llvm<'a>(
target: Triple, target: Triple,
opt_level: OptLevel, opt_level: OptLevel,
val_name: String, val_name: String,
) -> Result<ReplOutput, SyntaxError<'a>> { ) -> ReplOutput {
let arena = Bump::new(); let arena = Bump::new();
let target_info = TargetInfo::from(&target); let target_info = TargetInfo::from(&target);
let mut loaded = match compile_to_mono(&arena, src, target_info, DEFAULT_PALETTE) { let mut loaded = match compile_to_mono(&arena, src, target_info, DEFAULT_PALETTE) {
Ok(x) => x, Ok(x) => x,
Err(prob_strings) => { Err(prob_strings) => {
return Ok(ReplOutput::Problems(prob_strings)); return ReplOutput::Problems(prob_strings);
} }
}; };
@ -55,11 +54,11 @@ pub fn gen_and_eval_llvm<'a>(
let (_, main_fn_layout) = match loaded.procedures.keys().find(|(s, _)| *s == main_fn_symbol) { let (_, main_fn_layout) = match loaded.procedures.keys().find(|(s, _)| *s == main_fn_symbol) {
Some(layout) => *layout, Some(layout) => *layout,
None => { None => {
return Ok(ReplOutput::NoProblems { return ReplOutput::NoProblems {
expr: "<function>".to_string(), expr: "<function>".to_string(),
expr_type: expr_type_str, expr_type: expr_type_str,
val_name, val_name,
}); };
} }
}; };
@ -82,7 +81,7 @@ pub fn gen_and_eval_llvm<'a>(
target_info, target_info,
); );
Ok(format_answer(&arena, res_answer, expr_type_str, val_name)) format_answer(&arena, res_answer, expr_type_str, val_name)
} }
struct CliApp { struct CliApp {

View file

@ -5,8 +5,8 @@ use const_format::concatcp;
use roc_mono::ir::OptLevel; use roc_mono::ir::OptLevel;
use roc_parse::ast::{Expr, TypeDef, ValueDef}; use roc_parse::ast::{Expr, TypeDef, ValueDef};
use roc_parse::expr::{parse_single_def, ExprParseOptions, SingleDef}; use roc_parse::expr::{parse_single_def, ExprParseOptions, SingleDef};
use roc_parse::parser::Either;
use roc_parse::parser::{EClosure, EExpr}; use roc_parse::parser::{EClosure, EExpr};
use roc_parse::parser::{Either, SyntaxError};
use roc_parse::state::State; use roc_parse::state::State;
use roc_repl_eval::gen::ReplOutput; use roc_repl_eval::gen::ReplOutput;
use rustyline::highlight::{Highlighter, PromptInfo}; use rustyline::highlight::{Highlighter, PromptInfo};
@ -81,10 +81,7 @@ impl ReplState {
self.pending_src.clear(); self.pending_src.clear();
self.eval_and_format(&src).map_err(|_| { Ok(self.eval_and_format(&src))
// This seems to be unreachable in practice.
unreachable!();
})
} else { } else {
// The previous line wasn't blank, but there's some pending source. // The previous line wasn't blank, but there's some pending source.
// This could mean that, for example, you're writing a multiline `when` // This could mean that, for example, you're writing a multiline `when`
@ -101,9 +98,7 @@ impl ReplState {
ParseOutcome::Expr(_) ParseOutcome::Expr(_)
| ParseOutcome::ValueDef(_) | ParseOutcome::ValueDef(_)
| ParseOutcome::TypeDef(_) | ParseOutcome::TypeDef(_)
| ParseOutcome::Incomplete => self.eval_and_format(trim_line).map_err(|fail| { | ParseOutcome::Incomplete => Ok(self.eval_and_format(trim_line)),
todo!("gracefully report parse error in repl: {:?}", fail);
}),
ParseOutcome::Help => { ParseOutcome::Help => {
// TODO add link to repl tutorial(does not yet exist). // TODO add link to repl tutorial(does not yet exist).
Ok(format!("\n{}\n", TIPS)) Ok(format!("\n{}\n", TIPS))
@ -112,7 +107,7 @@ impl ReplState {
} }
} }
pub fn eval_and_format<'a>(&mut self, src: &str) -> Result<String, SyntaxError<'a>> { pub fn eval_and_format<'a>(&mut self, src: &str) -> String {
let src = if self.pending_src.is_empty() { let src = if self.pending_src.is_empty() {
src src
} else { } else {
@ -142,7 +137,7 @@ impl ReplState {
self.pending_src.push('\n'); self.pending_src.push('\n');
// Return without running eval or clearing pending_src. // Return without running eval or clearing pending_src.
return Ok(String::new()); return String::new();
} }
ValueDef::Body(_loc_pattern, _loc_expr) ValueDef::Body(_loc_pattern, _loc_expr)
| ValueDef::AnnotatedBody { | ValueDef::AnnotatedBody {
@ -166,17 +161,16 @@ impl ReplState {
ParseOutcome::Empty | ParseOutcome::Help | ParseOutcome::Exit => unreachable!(), ParseOutcome::Empty | ParseOutcome::Help | ParseOutcome::Exit => unreachable!(),
}; };
let answer = gen_and_eval_llvm( let output = format_output(gen_and_eval_llvm(
src, src,
Triple::host(), Triple::host(),
OptLevel::Normal, OptLevel::Normal,
"TODOval1".to_string(), "TODOval1".to_string(),
) ));
.map(format_output);
self.pending_src.clear(); self.pending_src.clear();
answer output
} }
/// Wrap the given expresssion in the appropriate past defs /// Wrap the given expresssion in the appropriate past defs