Skip to content

Commit

Permalink
wip: implement hir dialect ops, flesh out remaining core ir infra
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Sep 23, 2024
1 parent b8ee446 commit db1aca0
Show file tree
Hide file tree
Showing 43 changed files with 3,871 additions and 672 deletions.
8 changes: 1 addition & 7 deletions Cargo.lock

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

12 changes: 12 additions & 0 deletions hir-symbol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ impl Ord for Symbol {
self.as_str().cmp(other.as_str())
}
}
impl AsRef<str> for Symbol {
#[inline(always)]
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl core::borrow::Borrow<str> for Symbol {
#[inline(always)]
fn borrow(&self) -> &str {
self.as_str()
}
}
impl<T: Deref<Target = str>> PartialEq<T> for Symbol {
fn eq(&self, other: &T) -> bool {
self.as_str() == other.deref()
Expand Down
5 changes: 5 additions & 0 deletions hir-type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ impl Type {
matches!(self, Self::Array(_, _))
}

#[inline]
pub fn is_list(&self) -> bool {
matches!(self, Self::List(_))
}

/// Returns true if `self` and `other` are compatible operand types for a binary operator, e.g.
/// `add`
///
Expand Down
4 changes: 2 additions & 2 deletions hir2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition.workspace = true

[features]
default = ["std"]
std = ["rustc-demangle/std"]
std = ["rustc-demangle/std", "compact_str/std"]
serde = [
"dep:serde",
"dep:serde_repr",
Expand All @@ -33,7 +33,7 @@ blink-alloc = { version = "0.3", default-features = false, features = [
] }
either.workspace = true
cranelift-entity.workspace = true
downcast-rs = { version = "1.2", default-features = false }
compact_str.workspace = true
hashbrown.workspace = true
intrusive-collections.workspace = true
inventory.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions hir2/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod call_conv;
mod linkage;
mod overflow;
mod visibility;

pub use self::{call_conv::CallConv, linkage::Linkage, overflow::Overflow};
pub use self::{call_conv::CallConv, overflow::Overflow, visibility::Visibility};
66 changes: 0 additions & 66 deletions hir2/src/attributes/linkage.rs

This file was deleted.

48 changes: 48 additions & 0 deletions hir2/src/attributes/visibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use core::{fmt, str::FromStr};

/// The types of visibility that a [Symbol] may have
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum Visibility {
/// The symbol is public and may be referenced anywhere internal or external to the visible
/// references in the IR.
///
/// Public visibility implies that we cannot remove the symbol even if we are unaware of any
/// references, and no other constraints apply, as we must assume that the symbol has references
/// we don't know about.
#[default]
Public,
/// The symbol is private and may only be referenced by ops local to operations within the
/// current symbol table.
///
/// Private visibility implies that we know all uses of the symbol, and that those uses must
/// all exist within the current symbol table.
Private,
/// The symbol is public, but may only be referenced by symbol tables in the current compilation
/// graph, thus retaining the ability to observe all uses, and optimize based on that
/// information.
///
/// Nested visibility implies that we know all uses of the symbol, but that there may be uses
/// in other symbol tables in addition to the current one.
Nested,
}
impl fmt::Display for Visibility {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Public => f.write_str("public"),
Self::Private => f.write_str("private"),
Self::Nested => f.write_str("nested"),
}
}
}
impl FromStr for Visibility {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"public" => Ok(Self::Public),
"private" => Ok(Self::Private),
"nested" => Ok(Self::Nested),
_ => Err(()),
}
}
}
Loading

0 comments on commit db1aca0

Please sign in to comment.