Skip to content

Commit 2eb8bf0

Browse files
committed
Add initial pretty printing for core types
1 parent e1a959a commit 2eb8bf0

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

compiler-core/checking/src/check/kind.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ pub fn infer_surface_kind<S: TypeStorage>(
3232
(t, k)
3333
}
3434

35-
lowering::TypeKind::Forall { .. } => default,
35+
lowering::TypeKind::Forall { .. } => {
36+
let t = convert::type_to_core(state, context, id);
37+
let k = context.prim.t;
38+
(t, k)
39+
},
3640

3741
lowering::TypeKind::Hole => default,
3842

compiler-core/checking/src/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod debruijn;
2+
pub mod pretty;
23
pub mod storage;
34

45
pub use storage::TypeStorage;

compiler-core/checking/src/core/debruijn.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! and levels. The type checker uses a locally nameless representation
55
//! for type variables, with additional abstractions for implicitly
66
//! quantified type variables in permitted contexts like instance heads.
7-
use std::ops;
7+
use std::{fmt, ops};
88

99
use lowering::{GraphNodeId, ImplicitBindingId, TypeVariableBindingId};
1010
use rustc_hash::FxHashMap;
@@ -39,6 +39,12 @@ pub struct Bound {
3939
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4040
pub struct Level(u32);
4141

42+
impl fmt::Display for Level {
43+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44+
write!(f, "&{}", self.0)
45+
}
46+
}
47+
4248
/// A De Bruijn index.
4349
///
4450
/// De Bruijn indices are used to identify variables from the
@@ -52,6 +58,12 @@ pub struct Level(u32);
5258
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5359
pub struct Index(u32);
5460

61+
impl fmt::Display for Index {
62+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63+
write!(f, "*{}", self.0)
64+
}
65+
}
66+
5567
impl Bound {
5668
/// Returns the current De Bruijn [`Level`].
5769
pub fn level(&self) -> Level {

compiler-core/checking/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use std::sync::Arc;
55

66
use building_types::QueryResult;
77
use files::FileId;
8-
use indexing::{IndexedModule, TermItemKind, TypeItemKind};
8+
use indexing::{IndexedModule, TypeItemKind};
99
use lowering::LoweredModule;
1010
use resolving::ResolvedModule;
1111

1212
use crate::{
13-
check::{CheckContext, CheckState, PrimCore, convert, kind},
14-
core::TypeStorage,
13+
check::{CheckContext, CheckState, PrimCore, kind},
14+
core::{TypeStorage, pretty::pretty_print},
1515
};
1616

1717
pub trait External {
@@ -49,7 +49,13 @@ pub fn check_module(
4949
lowered.info.get_type_item(id)
5050
{
5151
let result = signature.map(|id| kind::infer_surface_kind(&mut state, &context, id));
52-
dbg!(result);
52+
if let Some((t, k)) = result {
53+
println!(
54+
"{} :: {}",
55+
pretty_print(external, &state, &context, t),
56+
pretty_print(external, &state, &context, k)
57+
)
58+
}
5359
}
5460
}
5561

tests-integration/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ test = 1 + 2 * 3 + 4
101101
r#"
102102
module Main where
103103
104-
foreign import data Proxy :: Constraint
104+
foreign import data Proxy :: forall a b. a -> b -> a
105105
"#,
106106
);
107107

@@ -132,6 +132,5 @@ foreign import data Proxy :: Constraint
132132

133133
let mut storage = InlineStorage::default();
134134
checking::check_module(&mut engine, &mut storage, id).unwrap();
135-
dbg!(storage);
136135
}
137136
}

0 commit comments

Comments
 (0)