Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/mun_abi/src/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ impl<'a> TypeDefinition<'a> {

/// Returns the size of the type in bytes
pub fn size_in_bytes(&self) -> usize {
((self.size_in_bits + 7) / 8)
self.size_in_bits
.div_ceil(8)
.try_into()
.expect("cannot covert size in bytes to platform size")
}
Expand Down
1 change: 0 additions & 1 deletion crates/mun_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ apple-codesign = { workspace = true }
array-init = { workspace = true }
by_address = { workspace = true }
bytemuck = { workspace = true }
mun_db = { version = "0.6.0-dev", path = "../mun_db" }
mun_hir = { version = "0.6.0-dev", path = "../mun_hir" }
mun_hir_input = { version = "0.6.0-dev", path = "../mun_hir_input" }
inkwell = { workspace = true, features = ["llvm14-0", "target-x86", "target-aarch64"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/code_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ impl<'db, 'ink> CodeGenContext<'db, 'ink> {
Self {
context,
rust_types: RefCell::new(HashMap::default()),
hir_types: HirTypeCache::new(context, db.upcast(), target_machine.get_target_data()),
hir_types: HirTypeCache::new(context, db, target_machine.get_target_data()),
optimization_level: db.optimization_level(),
target_machine,
db: db.upcast(),
db,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/code_gen/symbols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn gen_struct_info<'ink>(
.len()
.try_into()
.expect("could not convert num_fields to smaller bit size"),
memory_kind: hir_struct.data(db.upcast()).memory_kind,
memory_kind: hir_struct.data(db).memory_kind,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{AssemblyIr, ModuleGroupId, ModulePartition, TargetAssembly};
/// generation cache is pretty granular there is still a benefit to not having
/// to recompile assemblies if not required.
#[salsa::query_group(CodeGenDatabaseStorage)]
pub trait CodeGenDatabase: mun_hir::HirDatabase + mun_db::Upcast<dyn mun_hir::HirDatabase> {
pub trait CodeGenDatabase: mun_hir::HirDatabase {
/// Set the optimization level used to generate assemblies
#[salsa::input]
fn optimization_level(&self) -> inkwell::OptimizationLevel;
Expand Down
22 changes: 9 additions & 13 deletions crates/mun_codegen/src/ir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
.map(|(idx, ty)| {
let param = self.fn_value.get_nth_param(idx as u32).unwrap();
if let Some(s) = ty.as_struct() {
if s.data(self.db.upcast()).memory_kind == abi::StructMemoryKind::Value {
if s.data(self.db).memory_kind == abi::StructMemoryKind::Value {
deref_heap_value(&self.builder, param)
} else {
param
Expand Down Expand Up @@ -199,9 +199,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
self.builder.build_return(None);
} else if let Some(value) = ret_value {
let ret_value = if let Some(hir_struct) = fn_ret_type.as_struct() {
if hir_struct.data(self.db.upcast()).memory_kind
== mun_hir::StructMemoryKind::Value
{
if hir_struct.data(self.db).memory_kind == mun_hir::StructMemoryKind::Value {
self.gen_struct_alloc_on_heap(hir_struct, value.into_struct_value())
} else {
value
Expand All @@ -224,8 +222,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
tail,
} => self.gen_block(expr, statements, *tail),
Expr::Path(ref p) => {
let resolver =
mun_hir::resolver_for_expr(self.db.upcast(), self.body.owner(), expr);
let resolver = mun_hir::resolver_for_expr(self.db, self.body.owner(), expr);
Some(self.gen_path_expr(p, expr, &resolver))
}
Expr::Literal(lit) => Some(self.gen_literal(lit, expr)),
Expand Down Expand Up @@ -372,7 +369,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
}
let struct_lit = value.into_struct_value();

match hir_struct.data(self.db.upcast()).memory_kind {
match hir_struct.data(self.db).memory_kind {
mun_hir::StructMemoryKind::Value => struct_lit.into(),
mun_hir::StructMemoryKind::Gc => {
// TODO: Root memory in GC
Expand Down Expand Up @@ -573,7 +570,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
resolver: &Resolver,
) -> inkwell::values::BasicValueEnum<'ink> {
match resolver
.resolve_path_as_value_fully(self.db.upcast(), path)
.resolve_path_as_value_fully(self.db, path)
.expect("unknown path")
.0
{
Expand Down Expand Up @@ -603,7 +600,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
) -> BasicValueEnum<'ink> {
let ty = &self.infer[expr];
if let Some(s) = ty.as_struct() {
if s.data(self.db.upcast()).memory_kind == mun_hir::StructMemoryKind::Gc {
if s.data(self.db).memory_kind == mun_hir::StructMemoryKind::Gc {
return deref_heap_value(&self.builder, value);
}
}
Expand All @@ -618,7 +615,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
resolver: &Resolver,
) -> inkwell::values::PointerValue<'ink> {
match resolver
.resolve_path_as_value_fully(self.db.upcast(), path)
.resolve_path_as_value_fully(self.db, path)
.expect("unknown path")
.0
{
Expand Down Expand Up @@ -647,7 +644,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
TyKind::Float(_) => self.gen_binary_op_float(lhs, rhs, op),
TyKind::Int(ty) => self.gen_binary_op_int(lhs, rhs, op, ty.signedness),
TyKind::Struct(s) => {
if s.data(self.db.upcast()).memory_kind == mun_hir::StructMemoryKind::Value {
if s.data(self.db).memory_kind == mun_hir::StructMemoryKind::Value {
self.gen_binary_op_value_struct(lhs, rhs, op)
} else {
self.gen_binary_op_heap_struct(lhs, rhs, op)
Expand Down Expand Up @@ -1064,8 +1061,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
let body = self.body.clone();
match &body[expr] {
Expr::Path(ref p) => {
let resolver =
mun_hir::resolver_for_expr(self.db.upcast(), self.body.owner(), expr);
let resolver = mun_hir::resolver_for_expr(self.db, self.body.owner(), expr);
Some(self.gen_path_place_expr(p, expr, &resolver))
}
Expr::Field {
Expand Down
6 changes: 2 additions & 4 deletions crates/mun_codegen/src/ir/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ fn collect_expr<'ink>(
}

if let Expr::Path(path) = expr {
let resolver = mun_hir::resolver_for_expr(db.upcast(), body.owner(), expr_id);
if let Some((ValueNs::StructId(_), _)) =
resolver.resolve_path_as_value_fully(db.upcast(), path)
{
let resolver = mun_hir::resolver_for_expr(db, body.owner(), expr_id);
if let Some((ValueNs::StructId(_), _)) = resolver.resolve_path_as_value_fully(db, path) {
collect_intrinsic(context, target, &intrinsics::new, intrinsics);
// self.collect_intrinsic( module, entries, &intrinsics::drop);
*needs_alloc = true;
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'db, 'ink> HirTypeCache<'db, 'ink> {
/// that should be used for variables.
pub fn get_struct_reference_type(&self, struct_ty: mun_hir::Struct) -> BasicTypeEnum<'ink> {
let ir_ty = self.get_struct_type(struct_ty);
match struct_ty.data(self.db.upcast()).memory_kind {
match struct_ty.data(self.db).memory_kind {
mun_hir::StructMemoryKind::Gc => {
// GC values are pointers to pointers
// struct Foo {}
Expand Down
30 changes: 0 additions & 30 deletions crates/mun_codegen/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,6 @@ impl salsa::Database for MockDatabase {
}
}

impl mun_db::Upcast<dyn mun_hir::AstDatabase> for MockDatabase {
fn upcast(&self) -> &(dyn mun_hir::AstDatabase + 'static) {
self
}
}

impl mun_db::Upcast<dyn SourceDatabase> for MockDatabase {
fn upcast(&self) -> &(dyn SourceDatabase + 'static) {
self
}
}

impl mun_db::Upcast<dyn mun_hir::DefDatabase> for MockDatabase {
fn upcast(&self) -> &(dyn mun_hir::DefDatabase + 'static) {
self
}
}

impl mun_db::Upcast<dyn mun_hir::HirDatabase> for MockDatabase {
fn upcast(&self) -> &(dyn mun_hir::HirDatabase + 'static) {
self
}
}

impl mun_db::Upcast<dyn CodeGenDatabase> for MockDatabase {
fn upcast(&self) -> &(dyn CodeGenDatabase + 'static) {
self
}
}

impl Default for MockDatabase {
fn default() -> Self {
let mut db = MockDatabase {
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/module_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ModuleGroup {
.get(&visible_mod.into())
// If all its children are also part of the module group we can keep the
// function internal, so there is no need to export it.
.map_or(true, |&includes_subtree| !includes_subtree)
.is_none_or(|&includes_subtree| !includes_subtree)
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions crates/mun_codegen/src/module_partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,17 @@ impl Index<ModuleGroupId> for ModulePartition {
/// Builds a module partition from the contents of the database
pub(crate) fn build_partition(db: &dyn CodeGenDatabase) -> Arc<ModulePartition> {
let mut partition = ModulePartition::default();
for module in mun_hir::Package::all(db.upcast())
for module in mun_hir::Package::all(db)
.into_iter()
.flat_map(|package| package.modules(db.upcast()))
.flat_map(|package| package.modules(db))
{
let name = if module.name(db.upcast()).is_some() {
module.full_name(db.upcast())
let name = if module.name(db).is_some() {
module.full_name(db)
} else {
String::from("mod")
};

partition.add_group(
db.upcast(),
ModuleGroup::new(db.upcast(), name, vec![module]),
);
partition.add_group(db, ModuleGroup::new(db, name, vec![module]));
}
Arc::new(partition)
}
9 changes: 4 additions & 5 deletions crates/mun_codegen/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::cell::RefCell;

use inkwell::{context::Context, OptimizationLevel};
use mun_db::Upcast;
use mun_hir::{diagnostics::DiagnosticSink, HirDatabase};
use mun_hir_input::{SourceDatabase, WithFixture};
use mun_target::spec::Target;
Expand Down Expand Up @@ -1100,18 +1099,18 @@ fn test_snapshot_with_optimization(name: &str, text: &str, opt: OptimizationLeve
diag.message()
));
});
for module in mun_hir::Package::all(db.upcast())
for module in mun_hir::Package::all(&db)
.into_iter()
.flat_map(|package| package.modules(db.upcast()))
.flat_map(|package| package.modules(&db))
{
module.diagnostics(db.upcast(), &mut sink);
module.diagnostics(&db, &mut sink);
}
drop(sink);
let messages = messages.into_inner();

// Setup code generation
let llvm_context = Context::create();
let code_gen = CodeGenContext::new(&llvm_context, db.upcast());
let code_gen = CodeGenContext::new(&llvm_context, &db);
let module_parition = db.module_partition();

let value = if messages.is_empty() {
Expand Down
1 change: 0 additions & 1 deletion crates/mun_compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ license.workspace = true
[dependencies]
mun_codegen = { version = "0.6.0-dev", path = "../mun_codegen" }
mun_syntax = { version = "0.6.0-dev", path = "../mun_syntax" }
mun_db = { version = "0.6.0-dev", path = "../mun_db" }
mun_hir_input = { version = "0.6.0-dev", path = "../mun_hir_input" }
mun_hir = { version = "0.6.0-dev", path = "../mun_hir" }
mun_paths = { version = "0.6.0-dev", path = "../mun_paths" }
Expand Down
32 changes: 0 additions & 32 deletions crates/mun_compiler/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use mun_codegen::{CodeGenDatabase, CodeGenDatabaseStorage};
use mun_db::Upcast;
use mun_hir::{salsa, HirDatabase};
use mun_hir_input::SourceDatabase;

use crate::Config;

Expand All @@ -18,36 +16,6 @@ pub struct CompilerDatabase {
storage: salsa::Storage<Self>,
}

impl Upcast<dyn mun_hir::AstDatabase> for CompilerDatabase {
fn upcast(&self) -> &(dyn mun_hir::AstDatabase + 'static) {
self
}
}

impl Upcast<dyn SourceDatabase> for CompilerDatabase {
fn upcast(&self) -> &(dyn SourceDatabase + 'static) {
self
}
}

impl Upcast<dyn mun_hir::DefDatabase> for CompilerDatabase {
fn upcast(&self) -> &(dyn mun_hir::DefDatabase + 'static) {
self
}
}

impl Upcast<dyn mun_hir::HirDatabase> for CompilerDatabase {
fn upcast(&self) -> &(dyn mun_hir::HirDatabase + 'static) {
self
}
}

impl Upcast<dyn CodeGenDatabase> for CompilerDatabase {
fn upcast(&self) -> &(dyn CodeGenDatabase + 'static) {
self
}
}

impl CompilerDatabase {
/// Constructs a new database
pub fn new(config: &Config) -> Self {
Expand Down
13 changes: 6 additions & 7 deletions crates/mun_compiler/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::{
time::Duration,
};

use mun_db::Upcast;
use mun_project::{Package, LOCKFILE_NAME};
use walkdir::WalkDir;

Expand Down Expand Up @@ -216,9 +215,9 @@ impl Driver {
let emit_colors = display_color.should_enable();
let mut has_error = false;

for package in mun_hir::Package::all(self.db.upcast()) {
for module in package.modules(self.db.upcast()) {
if let Some(file_id) = module.file_id(self.db.upcast()) {
for package in mun_hir::Package::all(&self.db) {
for module in package.modules(&self.db) {
if let Some(file_id) = module.file_id(&self.db) {
let parse = self.db.parse(file_id);
let source_code = self.db.file_text(file_id);
let relative_file_path = self.db.file_relative_path(file_id);
Expand All @@ -240,7 +239,7 @@ impl Driver {
// Emit all HIR diagnostics
let mut error = None;
module.diagnostics(
self.db.upcast(),
&self.db,
&mut DiagnosticSink::new(|d| {
has_error = true;
if let Err(e) =
Expand Down Expand Up @@ -338,8 +337,8 @@ impl Driver {
let _lock = self.acquire_filesystem_output_lock();

// Create a copy of all current files
for package in mun_hir::Package::all(self.db.upcast()) {
for module in package.modules(self.db.upcast()) {
for package in mun_hir::Package::all(&self.db) {
for module in package.modules(&self.db) {
if self.emit_ir {
self.write_assembly_ir(module)?;
} else {
Expand Down
Loading
Loading