diff --git a/cli/src/repl/gen.rs b/cli/src/repl/gen.rs index afc3bafc55..9278c26719 100644 --- a/cli/src/repl/gen.rs +++ b/cli/src/repl/gen.rs @@ -8,7 +8,7 @@ use roc_can::builtins::builtin_defs_map; use roc_collections::all::{MutMap, MutSet}; use roc_fmt::annotation::Formattable; use roc_fmt::annotation::{Newlines, Parens}; -use roc_gen::llvm::build::{add_intrinsics, build_proc, build_proc_header, OptLevel}; +use roc_gen::llvm::build::{build_proc, build_proc_header, OptLevel}; use roc_gen::llvm::externs::add_default_roc_externs; use roc_load::file::LoadingProblem; use roc_parse::parser::SyntaxError; @@ -133,12 +133,9 @@ pub fn gen_and_eval<'a>( let module = arena.alloc(roc_gen::llvm::build::module_from_builtins(&context, "")); // Add roc_alloc, roc_realloc, and roc_dealloc, since the repl has no - // platform to provide them. These must be added *before* adding intrinsics! + // platform to provide them. add_default_roc_externs(&context, module, &builder, ptr_bytes); - // Add LLVM intrinsics. - add_intrinsics(&context, &module); - // mark our zig-defined builtins as internal for function in FunctionIterator::from_module(module) { let name = function.get_name().to_str().unwrap(); diff --git a/compiler/build/src/program.rs b/compiler/build/src/program.rs index a3c89e293f..542118321a 100644 --- a/compiler/build/src/program.rs +++ b/compiler/build/src/program.rs @@ -3,9 +3,7 @@ use bumpalo::Bump; use inkwell::context::Context; use inkwell::targets::{CodeModel, FileType, RelocMode}; use inkwell::values::FunctionValue; -use roc_gen::llvm::build::{ - add_intrinsics, build_proc, build_proc_header, module_from_builtins, OptLevel, Scope, -}; +use roc_gen::llvm::build::{build_proc, build_proc_header, module_from_builtins, OptLevel, Scope}; use roc_load::file::MonomorphizedModule; use roc_mono::layout::LayoutIds; use std::path::{Path, PathBuf}; @@ -86,9 +84,6 @@ pub fn gen_from_mono_module( let context = Context::create(); let module = arena.alloc(module_from_builtins(&context, "app")); - // Add LLVM intrinsics. - add_intrinsics(&context, &module); - // strip Zig debug stuff // module.strip_debug_info(); diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index a380815862..e4cef3f0e7 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -318,10 +318,13 @@ pub fn module_from_builtins<'ctx>(ctx: &'ctx Context, module_name: &str) -> Modu let module = Module::parse_bitcode_from_buffer(&memory_buffer, ctx) .unwrap_or_else(|err| panic!("Unable to import builtins bitcode. LLVM error: {:?}", err)); + // Add LLVM intrinsics. + add_intrinsics(ctx, &module); + module } -pub fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { +fn add_intrinsics<'ctx>(ctx: &'ctx Context, module: &Module<'ctx>) { // List of all supported LLVM intrinsics: // // https://releases.llvm.org/10.0.0/docs/LangRef.html#standard-c-library-intrinsics diff --git a/compiler/test_gen/src/helpers/eval.rs b/compiler/test_gen/src/helpers/eval.rs index 95a52d843c..7e5b9bf41a 100644 --- a/compiler/test_gen/src/helpers/eval.rs +++ b/compiler/test_gen/src/helpers/eval.rs @@ -4,7 +4,6 @@ use roc_build::program::FunctionIterator; use roc_can::builtins::builtin_defs_map; use roc_can::def::Def; use roc_collections::all::{MutMap, MutSet}; -use roc_gen::llvm::build::add_intrinsics; use roc_gen::llvm::externs::add_default_roc_externs; use roc_module::symbol::Symbol; use roc_types::subs::VarStore; @@ -185,12 +184,9 @@ pub fn helper<'a>( let module = roc_gen::llvm::build::module_from_builtins(context, "app"); // Add roc_alloc, roc_realloc, and roc_dealloc, since the repl has no - // platform to provide them. These must be added *before* adding intrinsics! + // platform to provide them. add_default_roc_externs(context, &module, &builder, ptr_bytes); - // Add LLVM intrinsics. - add_intrinsics(context, &module); - // strip Zig debug stuff module.strip_debug_info();