mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
DCE unused functions everywhere
This commit is contained in:
parent
58246ad572
commit
b6433f872a
3 changed files with 22 additions and 2 deletions
|
@ -2,6 +2,7 @@ use crate::repl::eval;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use inkwell::context::Context;
|
use inkwell::context::Context;
|
||||||
use roc_build::link::module_to_dylib;
|
use roc_build::link::module_to_dylib;
|
||||||
|
use roc_build::program::FunctionIterator;
|
||||||
use roc_collections::all::{MutMap, MutSet};
|
use roc_collections::all::{MutMap, MutSet};
|
||||||
use roc_fmt::annotation::Formattable;
|
use roc_fmt::annotation::Formattable;
|
||||||
use roc_fmt::annotation::{Newlines, Parens};
|
use roc_fmt::annotation::{Newlines, Parens};
|
||||||
|
@ -111,6 +112,15 @@ pub fn gen_and_eval(src: &[u8], target: Triple, opt_level: OptLevel) -> Result<R
|
||||||
let module = arena.alloc(roc_gen::llvm::build::module_from_builtins(&context, "app"));
|
let module = arena.alloc(roc_gen::llvm::build::module_from_builtins(&context, "app"));
|
||||||
let builder = context.create_builder();
|
let builder = context.create_builder();
|
||||||
|
|
||||||
|
// mark our zig-defined builtins as internal
|
||||||
|
use inkwell::module::Linkage;
|
||||||
|
for function in FunctionIterator::from_module(module) {
|
||||||
|
let name = function.get_name().to_str().unwrap();
|
||||||
|
if name.starts_with("roc_builtins") {
|
||||||
|
function.set_linkage(Linkage::Internal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
debug_assert_eq!(exposed_to_host.len(), 1);
|
debug_assert_eq!(exposed_to_host.len(), 1);
|
||||||
let (main_fn_symbol, main_fn_var) = exposed_to_host.iter().next().unwrap();
|
let (main_fn_symbol, main_fn_var) = exposed_to_host.iter().next().unwrap();
|
||||||
let main_fn_symbol = *main_fn_symbol;
|
let main_fn_symbol = *main_fn_symbol;
|
||||||
|
|
|
@ -170,12 +170,12 @@ pub fn gen_from_mono_module(
|
||||||
.expect("Writing .o file failed");
|
.expect("Writing .o file failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FunctionIterator<'ctx> {
|
pub struct FunctionIterator<'ctx> {
|
||||||
next: Option<FunctionValue<'ctx>>,
|
next: Option<FunctionValue<'ctx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx> FunctionIterator<'ctx> {
|
impl<'ctx> FunctionIterator<'ctx> {
|
||||||
fn from_module(module: &inkwell::module::Module<'ctx>) -> Self {
|
pub fn from_module(module: &inkwell::module::Module<'ctx>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
next: module.get_first_function(),
|
next: module.get_first_function(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use libloading::Library;
|
use libloading::Library;
|
||||||
use roc_build::link::module_to_dylib;
|
use roc_build::link::module_to_dylib;
|
||||||
|
use roc_build::program::FunctionIterator;
|
||||||
use roc_collections::all::{MutMap, MutSet};
|
use roc_collections::all::{MutMap, MutSet};
|
||||||
|
|
||||||
fn promote_expr_to_module(src: &str) -> String {
|
fn promote_expr_to_module(src: &str) -> String {
|
||||||
|
@ -154,6 +155,15 @@ pub fn helper<'a>(
|
||||||
|
|
||||||
let (dibuilder, compile_unit) = roc_gen::llvm::build::Env::new_debug_info(module);
|
let (dibuilder, compile_unit) = roc_gen::llvm::build::Env::new_debug_info(module);
|
||||||
|
|
||||||
|
// mark our zig-defined builtins as internal
|
||||||
|
use inkwell::module::Linkage;
|
||||||
|
for function in FunctionIterator::from_module(module) {
|
||||||
|
let name = function.get_name().to_str().unwrap();
|
||||||
|
if name.starts_with("roc_builtins") {
|
||||||
|
function.set_linkage(Linkage::Internal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Compile and add all the Procs before adding main
|
// Compile and add all the Procs before adding main
|
||||||
let env = roc_gen::llvm::build::Env {
|
let env = roc_gen::llvm::build::Env {
|
||||||
arena: &arena,
|
arena: &arena,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue