Revert "Try having build_expr return Either"

This reverts commit 2f065f05892fdc188cfdd8f42e878bebe79879cf.
This commit is contained in:
Richard Feldman 2020-07-08 23:00:29 -04:00
parent 70ceaac9ff
commit dd1cc5d24e
3 changed files with 9 additions and 16 deletions

1
Cargo.lock generated
View file

@ -1930,7 +1930,6 @@ name = "roc_gen"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"either",
"im", "im",
"im-rc", "im-rc",
"indoc", "indoc",

View file

@ -40,7 +40,6 @@ inlinable_string = "0.1"
# This way, GitHub Actions works and nobody's builds get broken. # This way, GitHub Actions works and nobody's builds get broken.
inkwell = { git = "https://github.com/rtfeldman/inkwell", tag = "llvm10-0.release1" } inkwell = { git = "https://github.com/rtfeldman/inkwell", tag = "llvm10-0.release1" }
target-lexicon = "0.10" target-lexicon = "0.10"
either = "1.5" # this should be the same version as the one Inkwell uses
[dev-dependencies] [dev-dependencies]
roc_can = { path = "../can" } roc_can = { path = "../can" }

View file

@ -5,7 +5,6 @@ use crate::llvm::convert::{
}; };
use bumpalo::collections::Vec; use bumpalo::collections::Vec;
use bumpalo::Bump; use bumpalo::Bump;
use either::Either::{self, *};
use inkwell::builder::Builder; use inkwell::builder::Builder;
use inkwell::context::Context; use inkwell::context::Context;
use inkwell::memory_buffer::MemoryBuffer; use inkwell::memory_buffer::MemoryBuffer;
@ -14,7 +13,7 @@ use inkwell::passes::{PassManager, PassManagerBuilder};
use inkwell::types::{BasicTypeEnum, FunctionType, IntType, PointerType, StructType}; use inkwell::types::{BasicTypeEnum, FunctionType, IntType, PointerType, StructType};
use inkwell::values::BasicValueEnum::{self, *}; use inkwell::values::BasicValueEnum::{self, *};
use inkwell::values::{ use inkwell::values::{
BasicValue, FloatValue, FunctionValue, InstructionValue, IntValue, PointerValue, StructValue, FloatValue, FunctionValue, InstructionValue, IntValue, PointerValue, StructValue,
}; };
use inkwell::AddressSpace; use inkwell::AddressSpace;
use inkwell::{IntPredicate, OptimizationLevel}; use inkwell::{IntPredicate, OptimizationLevel};
@ -174,14 +173,14 @@ pub fn build_expr<'a, 'ctx, 'env>(
scope: &Scope<'a, 'ctx>, scope: &Scope<'a, 'ctx>,
parent: FunctionValue<'ctx>, parent: FunctionValue<'ctx>,
expr: &Expr<'a>, expr: &Expr<'a>,
) -> Either<BasicValueEnum<'ctx>, InstructionValue<'ctx>> { ) -> BasicValueEnum<'ctx> {
use roc_mono::expr::Expr::*; use roc_mono::expr::Expr::*;
match expr { match expr {
Int(num) => Left(env.context.i64_type().const_int(*num as u64, true).into()), Int(num) => env.context.i64_type().const_int(*num as u64, true).into(),
Float(num) => Left(env.context.f64_type().const_float(*num).into()), Float(num) => env.context.f64_type().const_float(*num).into(),
Bool(b) => Left(env.context.bool_type().const_int(*b as u64, false).into()), Bool(b) => env.context.bool_type().const_int(*b as u64, false).into(),
Byte(b) => Left(env.context.i8_type().const_int(*b as u64, false).into()), Byte(b) => env.context.i8_type().const_int(*b as u64, false).into(),
Cond { Cond {
branch_symbol, branch_symbol,
pass: (pass_stores, pass_expr), pass: (pass_stores, pass_expr),
@ -213,11 +212,7 @@ pub fn build_expr<'a, 'ctx, 'env>(
// build then block // build then block
builder.position_at_end(then_block); builder.position_at_end(then_block);
let then_val: &'a dyn BasicValue<'ctx> = let then_val = build_expr(env, layout_ids, scope, parent, pass);
match build_expr(env, layout_ids, scope, parent, pass) {
Left(val) => env.arena.alloc(val),
Right(inst) => env.arena.alloc(inst),
};
builder.build_unconditional_branch(cont_block); builder.build_unconditional_branch(cont_block);
let then_block = builder.get_insert_block().unwrap(); let then_block = builder.get_insert_block().unwrap();
@ -234,9 +229,9 @@ pub fn build_expr<'a, 'ctx, 'env>(
let phi = builder.build_phi(ret_type, "branch"); let phi = builder.build_phi(ret_type, "branch");
phi.add_incoming(&[(then_val, then_block), (&else_val, else_block)]); phi.add_incoming(&[(&then_val, then_block), (&else_val, else_block)]);
Left(phi.as_basic_value()) phi.as_basic_value()
} }
_ => panic!( _ => panic!(
"Tried to make a branch out of an invalid condition: cond_expr = {:?}", "Tried to make a branch out of an invalid condition: cond_expr = {:?}",