Skip to content

Commit

Permalink
hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Wuerker committed Feb 6, 2024
1 parent bfc2a7d commit a2bc54c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 51 deletions.
23 changes: 6 additions & 17 deletions crates/mir2/src/ir/constant.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
use hir::hir_def::{ModuleTreeNodeId, TypeId};
use hir::hir_def;
use num_bigint::BigInt;
use smol_str::SmolStr;

// use super::SourceInfo;

#[salsa::interned]
pub struct ConstantId {
pub struct ConstId {
#[return_ref]
pub data: Constant,
pub data: Const,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Constant {
/// A name of a constant.
pub name: SmolStr,

/// A value of a constant.
pub struct Const {
pub value: ConstantValue,

/// A type of a constant.
pub ty: TypeId,

/// A module where a constant is declared.
pub module_id: ModuleTreeNodeId,
// /// A span where a constant is declared.
// pub source: SourceInfo,
#[return_ref]
pub(crate) origin: hir_def::Const,
}

// /// An interned Id for [`Constant`].
Expand Down
2 changes: 1 addition & 1 deletion crates/mir2/src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod inst;
pub mod value;

pub use basic_block::{BasicBlock, BasicBlockId};
pub use constant::{Constant, ConstantId};
pub use constant::{Const, ConstId};
pub use function::{FunctionBody, FunctionId, FunctionParam, FunctionSignature};
pub use inst::{Inst, InstId};
// pub use types::{Type, TypeId, TypeKind};
Expand Down
8 changes: 4 additions & 4 deletions crates/mir2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod lower;
#[salsa::jar(db = MirDb)]
pub struct Jar(
// ir::Constant,
ir::ConstantId,
ir::ConstId,
// ir::FunctionBody,
// ir::FunctionId,
// ir::FunctionParam,
Expand Down Expand Up @@ -45,9 +45,9 @@ pub trait MirDb: salsa::DbWithJar<Jar> + HirDb {
// IdentId::prefill(self)
}

fn as_hir_db(&self) -> &dyn MirDb {
<Self as salsa::DbWithJar<Jar>>::as_jar_db::<'_>(self)
}
// fn as_hir_db(&self) -> &dyn MirDb {
// <Self as salsa::DbWithJar<Jar>>::as_jar_db::<'_>(self)
// }
}
impl<DB> MirDb for DB where DB: salsa::DbWithJar<Jar> + HirDb {}

Expand Down
36 changes: 7 additions & 29 deletions crates/mir2/src/lower/constant.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
use std::rc::Rc;

use hir::hir_def::TypeId;
use hir::hir_def::{Const, TypeId};

use crate::{
ir::{Constant, ConstantId},
ir::{Const, ConstId},
MirDb,
};

#[salsa::tracked]
pub fn mir_lowered_constant(db: &dyn MirDb, analyzer_const: hir::hir_def::Const) -> ConstantId {
// let name = analyzer_const.name(db.upcast());
// let value = analyzer_const.constant_value(db.upcast()).unwrap();
// let ty = analyzer_const.typ(db.upcast()).unwrap();
// let module_id = analyzer_const.module(db.upcast());
// let span = analyzer_const.span(db.upcast());
// let id = analyzer_const.node_id(db.upcast());
pub fn mir_lowered_constant(db: &dyn MirDb, hir_const: Const) -> ConstId {
let value = hir_const.constant_value(db.as_hir_db()).unwrap();

// let ty = db.mir_lowered_type(ty);

// let constant = Constant {
// name,
// value: value.into(),
// ty,
// module_id,
// };

// db.mir_intern_const(constant.into())
panic!()
}

impl ConstantId {
// pub fn data(self, db: &dyn MirDb) -> Rc<Constant> {
// db.lookup_mir_intern_const(self)
// }

pub fn ty(self, db: &dyn MirDb) -> TypeId {
self.data(db).ty
let constant = Const {
value: value.into(),
origin: hir_const,
}
}

0 comments on commit a2bc54c

Please sign in to comment.