Skip to content

Commit

Permalink
WIP: better generics
Browse files Browse the repository at this point in the history
- channel.wait is removed, because it's a performance trap and to make
  specializing Channel possible

This fixes #502.

Changelog: changed
  • Loading branch information
yorickpeterse committed Oct 12, 2023
1 parent e977342 commit 93d8f57
Show file tree
Hide file tree
Showing 77 changed files with 4,398 additions and 3,704 deletions.
21 changes: 11 additions & 10 deletions compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use crate::config::{Config, SOURCE, SOURCE_EXT, TESTS};
use crate::hir;
use crate::linker::link;
use crate::llvm;
use crate::mir::passes as mir;
use crate::mir::printer::to_dot;
use crate::mir::{passes as mir, Mir};
use crate::mir::specialize::Specialize;
use crate::mir::Mir;
use crate::modules_parser::{ModulesParser, ParsedModule};
use crate::state::State;
use crate::type_check::define_types::{
Expand Down Expand Up @@ -131,12 +133,12 @@ impl Compiler {
}

let mut mir = Mir::new();
let state = &mut self.state;

mir::check_global_limits(&mut self.state)
.map_err(CompileError::Internal)?;
mir::check_global_limits(state).map_err(CompileError::Internal)?;

if mir::DefineConstants::run_all(&mut self.state, &mut mir, &modules)
&& mir::LowerToMir::run_all(&mut self.state, &mut mir, modules)
if mir::DefineConstants::run_all(state, &mut mir, &modules)
&& mir::LowerToMir::run_all(state, &mut mir, modules)
{
Ok(mir)
} else {
Expand Down Expand Up @@ -185,8 +187,7 @@ impl Compiler {
}

fn optimise_mir(&mut self, mir: &mut Mir) {
mir::ExpandDrop::run_all(&self.state.db, mir);
mir::ExpandReference::run_all(&self.state.db, mir);
Specialize::run_all(&mut self.state, mir);
mir::clean_up_basic_blocks(mir);
}

Expand All @@ -200,9 +201,9 @@ impl Compiler {
for module in mir.modules.values() {
let mut methods = Vec::new();

for cid in &module.classes {
for mid in &mir.classes[cid].methods {
methods.push(&mir.methods[mid]);
for class in &module.classes {
for method in &mir.classes[class].methods {
methods.push(&mir.methods[method]);
}
}

Expand Down
24 changes: 22 additions & 2 deletions compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub(crate) struct BuildDirectories {
/// The directory to store object files in.
pub(crate) objects: PathBuf,

/// The directory to store LLVM IR files in.
pub(crate) llvm_ir: PathBuf,

/// The directory to place executable files in.
pub(crate) bin: PathBuf,

Expand All @@ -56,10 +59,11 @@ impl BuildDirectories {
.map_or(config.build.clone(), |p| config.build.join(p));

let objects = build.join("objects");
let llvm_ir = build.join("llvm");
let dot = build.join("dot");
let bin = build.clone();

BuildDirectories { build, objects, bin, dot }
BuildDirectories { build, objects, llvm_ir, bin, dot }
}

pub(crate) fn create(&self) -> Result<(), String> {
Expand All @@ -71,6 +75,10 @@ impl BuildDirectories {
pub(crate) fn create_dot(&self) -> Result<(), String> {
create_directory(&self.dot)
}

pub(crate) fn create_llvm(&self) -> Result<(), String> {
create_directory(&self.llvm_ir)
}
}

/// A type describing to what degree a program should be optimised.
Expand Down Expand Up @@ -135,7 +143,7 @@ pub struct Config {
pub build: PathBuf,

/// A list of base source directories to search through.
pub sources: Vec<PathBuf>,
pub(crate) sources: Vec<PathBuf>,

/// The path to save the executable at.
pub output: Output,
Expand All @@ -155,6 +163,12 @@ pub struct Config {
/// If MIR should be printed to DOT files.
pub dot: bool,

/// If LLVM IR should be verified as part of code generation.
pub verify_llvm: bool,

/// If LLVM IR should be written to disk.
pub write_llvm: bool,

/// If C libraries should be linked statically or not.
pub static_linking: bool,
}
Expand All @@ -178,6 +192,8 @@ impl Config {
target: Target::native(),
opt: Opt::Balanced,
dot: false,
verify_llvm: false,
write_llvm: false,
static_linking: false,
}
}
Expand All @@ -192,6 +208,10 @@ impl Config {
self.implicit_imports.push(ModuleName::std_init());
}

pub fn add_source_directory(&mut self, path: PathBuf) {
self.sources.push(path.canonicalize().unwrap_or(path));
}

pub fn set_presenter(&mut self, format: &str) -> Result<(), String> {
self.presenter = match format {
"text" => Box::new(TextPresenter::with_colors()),
Expand Down
Loading

0 comments on commit 93d8f57

Please sign in to comment.