@@ -375,19 +375,7 @@ impl<'arena> Context<'arena> {
375
375
( None , source) => on_message ( Message :: UnsolvedMetaVar { source } ) ,
376
376
// Yield messages of solved named holes
377
377
( Some ( expr) , MetaSource :: HoleExpr ( range, name) ) => {
378
- let term = self . quote_env ( ) . quote ( self . scope , expr) ;
379
- let surface_term = distillation:: Context :: new (
380
- self . scope ,
381
- & self . item_env . names ,
382
- & mut self . local_env . names ,
383
- & self . meta_env . sources ,
384
- )
385
- . check ( & term) ;
386
-
387
- let pretty_context = pretty:: Context :: new ( self . scope ) ;
388
- let doc = pretty_context. term ( & surface_term) . into_doc ( ) ;
389
- let expr = doc. pretty ( usize:: MAX ) . to_string ( ) ;
390
-
378
+ let expr = self . pretty_value ( expr) ;
391
379
on_message ( Message :: HoleSolution { range, name, expr } ) ;
392
380
}
393
381
// Ignore solutions of anything else
@@ -420,18 +408,18 @@ impl<'arena> Context<'arena> {
420
408
}
421
409
422
410
pub fn distillation_context < ' out_arena > (
423
- & mut self ,
411
+ & self ,
424
412
scope : & ' out_arena Scope < ' out_arena > ,
425
413
) -> distillation:: Context < ' out_arena , ' _ > {
426
414
distillation:: Context :: new (
427
415
scope,
428
416
& self . item_env . names ,
429
- & mut self . local_env . names ,
417
+ self . local_env . names . clone ( ) ,
430
418
& self . meta_env . sources ,
431
419
)
432
420
}
433
421
434
- fn pretty_print_value ( & mut self , value : & ArcValue < ' _ > ) -> String {
422
+ fn pretty_value ( & self , value : & ArcValue < ' _ > ) -> String {
435
423
let scope = self . scope ;
436
424
437
425
let term = self . quote_env ( ) . unfolding_metas ( ) . quote ( scope, value) ;
@@ -625,12 +613,10 @@ impl<'arena> Context<'arena> {
625
613
}
626
614
} ;
627
615
628
- let from = self . pretty_print_value ( & from) ;
629
- let to = self . pretty_print_value ( & to) ;
630
616
self . push_message ( Message :: FailedToUnify {
631
617
range,
632
- found : from,
633
- expected : to ,
618
+ found : self . pretty_value ( & from) ,
619
+ expected : self . pretty_value ( & to ) ,
634
620
error,
635
621
} ) ;
636
622
core:: Term :: Prim ( span, Prim :: ReportedError )
@@ -757,10 +743,9 @@ impl<'arena> Context<'arena> {
757
743
// Some((Prim::Array64Type, [len, _])) => todo!(),
758
744
Some ( ( Prim :: ReportedError , _) ) => None ,
759
745
_ => {
760
- let expected_type = self . pretty_print_value ( expected_type) ;
761
746
self . push_message ( Message :: StringLiteralNotSupported {
762
747
range : file_range,
763
- expected_type,
748
+ expected_type : self . pretty_value ( expected_type ) ,
764
749
} ) ;
765
750
None
766
751
}
@@ -785,10 +770,9 @@ impl<'arena> Context<'arena> {
785
770
Some ( ( Prim :: F64Type , [ ] ) ) => self . parse_number ( * range, * lit, Const :: F64 ) ,
786
771
Some ( ( Prim :: ReportedError , _) ) => None ,
787
772
_ => {
788
- let expected_type = self . pretty_print_value ( expected_type) ;
789
773
self . push_message ( Message :: NumericLiteralNotSupported {
790
774
range : file_range,
791
- expected_type,
775
+ expected_type : self . pretty_value ( expected_type ) ,
792
776
} ) ;
793
777
None
794
778
}
@@ -875,12 +859,10 @@ impl<'arena> Context<'arena> {
875
859
match self . unification_context ( ) . unify ( & r#type, expected_type) {
876
860
Ok ( ( ) ) => self . check_pattern ( pattern, & r#type) ,
877
861
Err ( error) => {
878
- let lhs = self . pretty_print_value ( & r#type) ;
879
- let rhs = self . pretty_print_value ( expected_type) ;
880
862
self . push_message ( Message :: FailedToUnify {
881
863
range : file_range,
882
- found : lhs ,
883
- expected : rhs ,
864
+ found : self . pretty_value ( & r#type ) ,
865
+ expected : self . pretty_value ( expected_type ) ,
884
866
error,
885
867
} ) ;
886
868
CheckedPattern :: ReportedError ( file_range)
@@ -1178,10 +1160,9 @@ impl<'arena> Context<'arena> {
1178
1160
return core:: Term :: Prim ( file_range. into ( ) , Prim :: ReportedError )
1179
1161
}
1180
1162
_ => {
1181
- let expected_type = self . pretty_print_value ( & expected_type) ;
1182
1163
self . push_message ( Message :: ArrayLiteralNotSupported {
1183
1164
range : file_range,
1184
- expected_type,
1165
+ expected_type : self . pretty_value ( & expected_type ) ,
1185
1166
} ) ;
1186
1167
return core:: Term :: Prim ( file_range. into ( ) , Prim :: ReportedError ) ;
1187
1168
}
@@ -1213,11 +1194,10 @@ impl<'arena> Context<'arena> {
1213
1194
self . check ( elem_expr, elem_type) ;
1214
1195
}
1215
1196
1216
- let expected_len = self . pretty_print_value ( len_value. unwrap ( ) ) ;
1217
1197
self . push_message ( Message :: MismatchedArrayLength {
1218
1198
range : file_range,
1219
1199
found_len : elem_exprs. len ( ) ,
1220
- expected_len,
1200
+ expected_len : self . pretty_value ( len_value . unwrap ( ) ) ,
1221
1201
} ) ;
1222
1202
1223
1203
core:: Term :: Prim ( file_range. into ( ) , Prim :: ReportedError )
@@ -1236,10 +1216,9 @@ impl<'arena> Context<'arena> {
1236
1216
// Some((Prim::Array64Type, [len, _])) => todo!(),
1237
1217
Some ( ( Prim :: ReportedError , _) ) => None ,
1238
1218
_ => {
1239
- let expected_type = self . pretty_print_value ( & expected_type) ;
1240
1219
self . push_message ( Message :: StringLiteralNotSupported {
1241
1220
range : file_range,
1242
- expected_type,
1221
+ expected_type : self . pretty_value ( & expected_type ) ,
1243
1222
} ) ;
1244
1223
None
1245
1224
}
@@ -1264,10 +1243,9 @@ impl<'arena> Context<'arena> {
1264
1243
Some ( ( Prim :: F64Type , [ ] ) ) => self . parse_number ( * range, * lit, Const :: F64 ) ,
1265
1244
Some ( ( Prim :: ReportedError , _) ) => None ,
1266
1245
_ => {
1267
- let expected_type = self . pretty_print_value ( & expected_type) ;
1268
1246
self . push_message ( Message :: NumericLiteralNotSupported {
1269
1247
range : file_range,
1270
- expected_type,
1248
+ expected_type : self . pretty_value ( & expected_type ) ,
1271
1249
} ) ;
1272
1250
return core:: Term :: Prim ( file_range. into ( ) , Prim :: ReportedError ) ;
1273
1251
}
@@ -1521,11 +1499,10 @@ impl<'arena> Context<'arena> {
1521
1499
if arg. plicity == * plicity {
1522
1500
( param_type, body_type)
1523
1501
} else {
1524
- let head_type = self . pretty_print_value ( & head_type) ;
1525
1502
self . messages . push ( Message :: PlicityArgumentMismatch {
1526
1503
head_range : self . file_range ( head_range) ,
1527
1504
head_plicity : Plicity :: Explicit ,
1528
- head_type,
1505
+ head_type : self . pretty_value ( & head_type ) ,
1529
1506
arg_range : self . file_range ( arg. term . range ( ) ) ,
1530
1507
arg_plicity : arg. plicity ,
1531
1508
} ) ;
@@ -1542,10 +1519,9 @@ impl<'arena> Context<'arena> {
1542
1519
_ => {
1543
1520
// NOTE: We could try to infer that this is a function type,
1544
1521
// but this takes more work to prevent cascading type errors
1545
- let head_type = self . pretty_print_value ( & head_type) ;
1546
1522
self . push_message ( Message :: UnexpectedArgument {
1547
1523
head_range : self . file_range ( head_range) ,
1548
- head_type,
1524
+ head_type : self . pretty_value ( & head_type ) ,
1549
1525
arg_range : self . file_range ( arg. term . range ( ) ) ,
1550
1526
} ) ;
1551
1527
return self . synth_reported_error ( * range) ;
@@ -1681,15 +1657,12 @@ impl<'arena> Context<'arena> {
1681
1657
_ => { }
1682
1658
}
1683
1659
1684
- let head_type = self . pretty_print_value ( & head_type) ;
1685
- let suggestion =
1686
- suggest_name ( * proj_label, labels. iter ( ) . map ( |( _, label) | * label) ) ;
1687
1660
self . push_message ( Message :: UnknownField {
1688
1661
head_range : self . file_range ( head_range) ,
1689
- head_type,
1662
+ head_type : self . pretty_value ( & head_type ) ,
1690
1663
label_range : self . file_range ( * label_range) ,
1691
1664
label : * proj_label,
1692
- suggestion,
1665
+ suggestion : suggest_name ( * proj_label , labels . iter ( ) . map ( | ( _ , l ) | * l ) ) ,
1693
1666
} ) ;
1694
1667
return self . synth_reported_error ( * range) ;
1695
1668
}
@@ -2005,15 +1978,13 @@ impl<'arena> Context<'arena> {
2005
1978
( Gte ( _) , Some ( ( ( S64Type , [ ] ) , ( S64Type , [ ] ) ) ) ) => ( S64Gte , BoolType ) ,
2006
1979
2007
1980
_ => {
2008
- let lhs_pretty = self . pretty_print_value ( & lhs_type) ;
2009
- let rhs_pretty = self . pretty_print_value ( & rhs_type) ;
2010
1981
self . push_message ( Message :: BinOpMismatchedTypes {
2011
1982
range : self . file_range ( range) ,
2012
1983
lhs_range : self . file_range ( lhs. range ( ) ) ,
2013
1984
rhs_range : self . file_range ( rhs. range ( ) ) ,
2014
1985
op : op. map_range ( |range| self . file_range ( range) ) ,
2015
- lhs : lhs_pretty ,
2016
- rhs : rhs_pretty ,
1986
+ lhs : self . pretty_value ( & lhs_type ) ,
1987
+ rhs : self . pretty_value ( & rhs_type ) ,
2017
1988
} ) ;
2018
1989
return self . synth_reported_error ( range) ;
2019
1990
}
0 commit comments