Skip to content

Commit 48e05f1

Browse files
committed
Remove debug implementations in favor of PrettyPrint
1 parent 94ff4bd commit 48e05f1

File tree

3 files changed

+7
-158
lines changed

3 files changed

+7
-158
lines changed

crates/sml-core/src/elaborate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<'ar> Context<'ar> {
938938
_ => {
939939
self.diags.push(Diagnostic::error(
940940
pat.span,
941-
format!("Non-constructor {:?} applied to pattern {:?}", con, p),
941+
format!("Non-constructor applied to pattern"),
942942
));
943943
Pat::new(
944944
self.arena.pats.wild(),

crates/sml-core/src/lib.rs

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct Pat<'ar> {
7575
pub span: Span,
7676
}
7777

78-
#[derive(Copy, Clone, Debug)]
78+
#[derive(Copy, Clone)]
7979
pub struct Rule<'ar> {
8080
pub pat: Pat<'ar>,
8181
pub expr: Expr<'ar>,
@@ -184,136 +184,3 @@ impl<T> std::ops::Deref for SortedRecord<T> {
184184
&self.rows
185185
}
186186
}
187-
188-
impl<T: fmt::Debug> fmt::Debug for SortedRecord<T> {
189-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
190-
write!(
191-
f,
192-
"{{ {} }}",
193-
self.rows
194-
.iter()
195-
.map(|r| format!("{:?}={:?}", r.label, r.data))
196-
.collect::<Vec<String>>()
197-
.join(",")
198-
)
199-
}
200-
}
201-
202-
impl<'ar> fmt::Debug for ExprKind<'ar> {
203-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
204-
use ExprKind::*;
205-
match self {
206-
App(e1, e2) => write!(f, "{:?} {:?}", e1, e2),
207-
Case(casee, rules) => write!(
208-
f,
209-
"(case {:?} of\n{})",
210-
casee,
211-
rules
212-
.into_iter()
213-
.map(|r| format!("| {:?} => {:?}\n", r.pat.pat, r.expr))
214-
.collect::<String>()
215-
),
216-
Con(con, tys) => write!(f, "{:?} [{:?}]", con, tys),
217-
Const(c) => write!(f, "{:?}", c),
218-
Handle(tryy, sym, handler) => write!(f, "{:?} handle {:?}", tryy, handler),
219-
Lambda(lam) => write!(f, "{:?}", lam),
220-
Let(decls, body) => write!(f, "let {:?} in {:?} end", decls, body),
221-
List(exprs) => write!(f, "{:?}", exprs),
222-
Primitive(sym) => write!(f, "primitive {:?}", sym),
223-
Raise(e) => write!(f, "raise {:?}", e),
224-
Record(rows) => write!(
225-
f,
226-
"{{ {} }}",
227-
rows.iter()
228-
.map(|r| format!("{:?}={:?}", r.label, r.data))
229-
.collect::<Vec<String>>()
230-
.join(",")
231-
),
232-
Seq(exprs) => write!(f, "{:?}", exprs),
233-
Var(s) => write!(f, "{:?}", s),
234-
}
235-
}
236-
}
237-
238-
impl<'ar> fmt::Debug for PatKind<'ar> {
239-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
240-
use PatKind::*;
241-
match self {
242-
App(e1, Some(e2)) => write!(f, "{:?} {:?}", e1.name, e2),
243-
App(e1, None) => write!(f, "{:?}", e1.name),
244-
// Con(con, tys) => write!(f, "{:?} [{:?}]", con, tys),
245-
Const(c) => write!(f, "{:?}", c),
246-
Record(rows) => write!(
247-
f,
248-
"{{ {} }}",
249-
rows.iter()
250-
.map(|r| format!("{:?}={:?}", r.label, r.data))
251-
.collect::<Vec<String>>()
252-
.join(",")
253-
),
254-
// List(exprs) => write!(f, "{:?}", exprs),
255-
Var(s) => write!(f, "{:?}", s),
256-
Wild => write!(f, "_"),
257-
}
258-
}
259-
}
260-
261-
impl<'ar> fmt::Debug for Expr<'ar> {
262-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
263-
write!(f, "{:?}", self.expr)
264-
}
265-
}
266-
267-
impl<'ar> fmt::Debug for Pat<'ar> {
268-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
269-
write!(f, "{:?}", self.pat)
270-
}
271-
}
272-
273-
impl<'ar> fmt::Debug for Lambda<'ar> {
274-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
275-
write!(f, "fn ({:?} : {:?}) => {:?}", self.arg, self.ty, self.body)
276-
}
277-
}
278-
279-
impl<'ar> fmt::Debug for Decl<'ar> {
280-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
281-
match self {
282-
Decl::Val(rule) => write!(f, "val {:?} = {:?}", rule.pat, rule.expr),
283-
Decl::Fun(_, binds) => {
284-
let s = binds
285-
.iter()
286-
.map(|(n, l)| format!("val {:?} = {:?}", n, l))
287-
.collect::<Vec<String>>()
288-
.join(";\n");
289-
writeln!(f, "{}", s)
290-
}
291-
Decl::Datatype(dt) => {
292-
let vars = dt
293-
.tyvars
294-
.iter()
295-
.map(|u| types::fresh_name(*u))
296-
.collect::<Vec<String>>()
297-
.join(",");
298-
let cons = dt
299-
.constructors
300-
.iter()
301-
.map(|(con, ty)| match ty {
302-
Some(ty) => format!("{:?} of {:?}", con.name, ty),
303-
None => format!("{:?}", con.name),
304-
})
305-
.collect::<Vec<String>>()
306-
.join(" | ");
307-
match dt.tyvars.len() {
308-
0 => writeln!(f, "datatype {:?} = {}", dt.tycon.name, cons),
309-
1 => writeln!(f, "datatype {} {:?} = {}", vars, dt.tycon.name, cons),
310-
_ => writeln!(f, "datatype ({}) {:?} = {}", vars, dt.tycon.name, cons),
311-
}
312-
}
313-
Decl::Exn(con, ty) => match ty {
314-
Some(ty) => writeln!(f, "exception {:?} of {:?}", con.name, ty),
315-
None => writeln!(f, "exception {:?}", con.name),
316-
},
317-
}
318-
}
319-
}

crates/sml-core/src/match_compile.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ fn preflight<'a>(ctx: &Context<'a>, rules: Vec<Rule<'a>>) -> (Vec<Decl<'a>>, Vec
164164
(decls, finished)
165165
}
166166

167-
#[derive(Debug, Clone)]
167+
#[derive(Clone)]
168168
pub enum Fact {
169169
Con(Constructor, Option<Symbol>),
170170
Record(SortedRecord<Symbol>),
171171
}
172172

173-
#[derive(Default, Debug, Clone)]
173+
#[derive(Default, Clone)]
174174
pub struct Facts {
175175
v: Vec<(Symbol, Fact)>,
176176
}
@@ -194,22 +194,22 @@ impl Facts {
194194
match pat.pat {
195195
PatKind::Var(x) => {
196196
if let Some(_) = map.insert(*x, (*var, pat.ty)) {
197-
panic!("Bug: Facts.bind rebinding of {:?} => {:?}", var, x)
197+
panic!("Bug: Facts.bind rebinding")
198198
}
199199
}
200200
PatKind::App(_, Some(pat)) => match facts.get(var) {
201201
Some(Fact::Con(_, Some(x))) => {
202202
queue.push_back((x, pat));
203203
}
204-
x => panic!("Bug: Facts.bind constructor {:?} {:?}", var, x),
204+
x => panic!("Bug: Facts.bind constructor"),
205205
},
206206
PatKind::Record(rp) => match facts.get(var) {
207207
Some(Fact::Record(rx)) => {
208208
for (rp, rx) in rp.iter().zip(rx.iter()) {
209209
queue.push_back((&rx.data, &rp.data));
210210
}
211211
}
212-
x => panic!("Bug: Facts.bind record {:?} {:?}", var, x),
212+
x => panic!("Bug: Facts.bind record"),
213213
},
214214
_ => continue,
215215
}
@@ -582,24 +582,6 @@ impl<'a, 'ctx> Matrix<'a, 'ctx> {
582582
}
583583
}
584584

585-
impl fmt::Debug for Matrix<'_, '_> {
586-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
587-
write!(f, "matrix {:?}\n", self.vars)?;
588-
for (pats, exprs) in self.pats.iter().zip(self.rules.iter()) {
589-
writeln!(
590-
f,
591-
"{:?} => {:?}",
592-
pats.iter()
593-
.map(|pat| format!("{:?}", pat))
594-
.collect::<Vec<String>>()
595-
.join(","),
596-
exprs
597-
)?;
598-
}
599-
Ok(())
600-
}
601-
}
602-
603585
fn collect_vars<'a>(pat: Pat<'a>) -> Vec<Var<'a>> {
604586
let mut v = Vec::new();
605587
let mut queue = VecDeque::new();

0 commit comments

Comments
 (0)