-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IR traits #21
IR traits #21
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,7 +429,7 @@ impl NameTracker { | |
// Check if there are any unresolved forward label references. | ||
for (id, op) in label_scope { | ||
if matches!(op, LabelRef::ForwardRef(_)) { | ||
input_err!(loc.clone(), UnresolvedReference(id.clone()))? | ||
return input_err!(loc.clone(), UnresolvedReference(id.clone()))?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops, I wanted to clean that up. I had a conflict with the commit introducing locations when rebasing |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
//! | ||
//! The [impl_type](crate::impl_type) macro can be used to implement [Type] for a rust type. | ||
|
||
use crate::common_traits::Verify; | ||
use crate::common_traits::{Qualified, Verify}; | ||
use crate::context::{private::ArenaObj, ArenaCell, Context, Ptr}; | ||
use crate::dialect::{Dialect, DialectName}; | ||
use crate::error::Result; | ||
|
@@ -122,6 +122,50 @@ pub trait Type: Printable + Verify + Downcast + Sync + Debug { | |
} | ||
impl_downcast!(Type); | ||
|
||
impl Qualified for dyn Type { | ||
type Qualifier = TypeId; | ||
|
||
fn get_qualifier(&self, _ctx: &Context) -> Self::Qualifier { | ||
self.get_type_id() | ||
} | ||
} | ||
|
||
/// Trait for objects that have a direct type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pub trait Typed { | ||
/// Get the [Type] of the current object. | ||
fn get_type(&self, ctx: &Context) -> Ptr<TypeObj>; | ||
} | ||
|
||
impl Typed for Ptr<TypeObj> { | ||
fn get_type(&self, _ctx: &Context) -> Ptr<TypeObj> { | ||
*self | ||
} | ||
} | ||
|
||
impl Typed for dyn Type { | ||
fn get_type(&self, ctx: &Context) -> Ptr<TypeObj> { | ||
self.get_self_ptr(ctx) | ||
} | ||
} | ||
|
||
impl<T: Typed + ?Sized> Typed for &T { | ||
fn get_type(&self, ctx: &Context) -> Ptr<TypeObj> { | ||
(*self).get_type(ctx) | ||
} | ||
} | ||
|
||
impl<T: Typed + ?Sized> Typed for &mut T { | ||
fn get_type(&self, ctx: &Context) -> Ptr<TypeObj> { | ||
(**self).get_type(ctx) | ||
} | ||
} | ||
|
||
impl<T: Typed + ?Sized> Typed for Box<T> { | ||
fn get_type(&self, ctx: &Context) -> Ptr<TypeObj> { | ||
(**self).get_type(ctx) | ||
} | ||
} | ||
|
||
#[derive(Clone, Hash, PartialEq, Eq)] | ||
/// A Type's name (not including it's dialect). | ||
pub struct TypeName(Identifier); | ||
|
@@ -303,8 +347,8 @@ macro_rules! impl_type { | |
$structname: ident, $type_name: literal, $dialect_name: literal) => { | ||
$(#[$outer])* | ||
impl $crate::r#type::Type for $structname { | ||
fn hash_type(&self) -> TypeValueHash { | ||
TypeValueHash::new(self) | ||
fn hash_type(&self) -> $crate::storage_uniquer::TypeValueHash { | ||
$crate::storage_uniquer::TypeValueHash::new(self) | ||
} | ||
|
||
fn eq_type(&self, other: &dyn Type) -> bool { | ||
|
@@ -324,6 +368,14 @@ macro_rules! impl_type { | |
} | ||
} | ||
} | ||
|
||
impl $crate::common_traits::Qualified for $structname { | ||
type Qualifier = $crate::r#type::TypeId; | ||
|
||
fn get_qualifier(&self, _ctx: &$crate::context::Context) -> Self::Qualifier { | ||
Self::get_type_id_static() | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ use crate::{ | |
context::{Context, Ptr}, | ||
linked_list::{ContainsLinkedList, LinkedList}, | ||
operation::Operation, | ||
r#type::TypeObj, | ||
r#type::{TypeObj, Typed}, | ||
}; | ||
|
||
/// def-use chains are implemented for [Value]s and `Ptr<BasicBlock`. | ||
|
@@ -170,6 +170,12 @@ impl Value { | |
} | ||
} | ||
|
||
impl Typed for Value { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you see any problem if I just replace this function with the contents of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i.e., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem with that. I was thinking to propose this as a follow up :) |
||
fn get_type(&self, ctx: &Context) -> Ptr<TypeObj> { | ||
self.get_type(ctx) | ||
} | ||
} | ||
|
||
impl Named for Value { | ||
fn given_name(&self, ctx: &Context) -> Option<String> { | ||
match self { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObjectsIR entities