conlang: add lang items, remove Empty, and shuffle typeck
This commit is contained in:
@@ -224,7 +224,6 @@ pub struct Ty {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum TyKind {
|
||||
Never,
|
||||
Empty,
|
||||
Infer,
|
||||
Path(Path),
|
||||
Array(TyArray),
|
||||
|
||||
@@ -165,7 +165,6 @@ impl Display for Function {
|
||||
let Self { name, gens, sign: sign @ TyFn { args, rety }, bind, body } = self;
|
||||
let types = match args.kind {
|
||||
TyKind::Tuple(TyTuple { ref types }) => types.as_slice(),
|
||||
TyKind::Empty => Default::default(),
|
||||
_ => {
|
||||
write!(f, "Invalid function signature: {sign}")?;
|
||||
Default::default()
|
||||
@@ -191,7 +190,9 @@ impl Display for Function {
|
||||
write!(f, "{arg}: {ty}")?;
|
||||
}
|
||||
}
|
||||
if TyKind::Empty != rety.kind {
|
||||
if let TyKind::Tuple(TyTuple { types }) = &rety.kind
|
||||
&& !types.as_slice().is_empty()
|
||||
{
|
||||
write!(f, " -> {rety}")?
|
||||
}
|
||||
|
||||
@@ -295,7 +296,6 @@ impl Display for TyKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
TyKind::Never => "!".fmt(f),
|
||||
TyKind::Empty => "()".fmt(f),
|
||||
TyKind::Infer => "_".fmt(f),
|
||||
TyKind::Path(v) => v.fmt(f),
|
||||
TyKind::Array(v) => v.fmt(f),
|
||||
@@ -349,8 +349,10 @@ impl Display for TyFn {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { args, rety } = self;
|
||||
write!(f, "fn {args}")?;
|
||||
if TyKind::Empty != rety.kind {
|
||||
write!(f, " -> {rety}")?;
|
||||
if let TyKind::Tuple(TyTuple { types }) = &rety.kind
|
||||
&& !types.as_slice().is_empty()
|
||||
{
|
||||
write!(f, " -> {rety}")?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ impl WeightOf for Ty {
|
||||
impl WeightOf for TyKind {
|
||||
fn weight_of(&self) -> usize {
|
||||
match self {
|
||||
TyKind::Never | TyKind::Empty | TyKind::Infer => size_of_val(self),
|
||||
TyKind::Never | TyKind::Infer => size_of_val(self),
|
||||
TyKind::Path(v) => v.weight_of(),
|
||||
TyKind::Array(v) => v.weight_of(),
|
||||
TyKind::Slice(v) => v.weight_of(),
|
||||
|
||||
@@ -531,7 +531,6 @@ pub fn or_fold_use_tree<F: Fold + ?Sized>(folder: &mut F, tree: UseTree) -> UseT
|
||||
pub fn or_fold_ty_kind<F: Fold + ?Sized>(folder: &mut F, kind: TyKind) -> TyKind {
|
||||
match kind {
|
||||
TyKind::Never => TyKind::Never,
|
||||
TyKind::Empty => TyKind::Empty,
|
||||
TyKind::Infer => TyKind::Infer,
|
||||
TyKind::Path(p) => TyKind::Path(folder.fold_path(p)),
|
||||
TyKind::Array(a) => TyKind::Array(folder.fold_ty_array(a)),
|
||||
|
||||
@@ -369,7 +369,6 @@ impl Walk for TyKind {
|
||||
fn children<'a, V: Visit<'a>>(&'a self, v: &mut V) {
|
||||
match self {
|
||||
TyKind::Never => {}
|
||||
TyKind::Empty => {}
|
||||
TyKind::Infer => {}
|
||||
TyKind::Path(value) => value.visit_in(v),
|
||||
TyKind::Array(value) => value.visit_in(v),
|
||||
|
||||
Reference in New Issue
Block a user