1
- use chalk_integration:: db:: ChalkDatabase ;
2
- use chalk_integration:: query:: LoweringDatabase ;
3
1
use chalk_ir:: interner:: ChalkIr ;
4
2
use chalk_ir:: AssocTypeId ;
5
- use chalk_ir:: Goal ;
6
3
use chalk_ir:: ImplId ;
7
- use chalk_ir:: InEnvironment ;
8
4
use chalk_ir:: OpaqueTyId ;
9
5
use chalk_ir:: Parameter ;
10
6
use chalk_ir:: ProgramClause ;
11
7
use chalk_ir:: StructId ;
12
8
use chalk_ir:: TraitId ;
13
9
use chalk_ir:: TypeName ;
14
- use chalk_ir:: UCanonical ;
15
10
use chalk_rust_ir:: AssociatedTyDatum ;
16
11
use chalk_rust_ir:: AssociatedTyValue ;
17
12
use chalk_rust_ir:: AssociatedTyValueId ;
@@ -21,96 +16,96 @@ use chalk_rust_ir::StructDatum;
21
16
use chalk_rust_ir:: TraitDatum ;
22
17
use chalk_rust_ir:: WellKnownTrait ;
23
18
use chalk_solve:: RustIrDatabase ;
24
- use chalk_solve:: Solution ;
25
19
use chalk_solve:: SolverChoice ;
26
20
use std:: sync:: Arc ;
27
21
28
22
#[ derive( Debug , Default ) ]
29
23
struct MockDatabase {
30
- chalk_db : ChalkDatabase ,
31
24
panic : bool ,
32
25
}
33
26
34
- impl MockDatabase {
35
- pub fn with ( program_text : & str , solver_choice : SolverChoice ) -> Self {
36
- Self {
37
- chalk_db : ChalkDatabase :: with ( program_text, solver_choice) ,
38
- panic : false ,
39
- }
40
- }
41
-
42
- pub fn solve (
43
- & self ,
44
- goal : & UCanonical < InEnvironment < Goal < ChalkIr > > > ,
45
- ) -> Option < Solution < ChalkIr > > {
46
- let solver = self . chalk_db . solver ( ) ;
47
- let solution = solver. lock ( ) . unwrap ( ) . solve ( self , goal) ;
48
- solution
49
- }
50
- }
51
-
27
+ #[ allow( unused_variables) ]
52
28
impl RustIrDatabase < ChalkIr > for MockDatabase {
53
29
fn custom_clauses ( & self ) -> Vec < ProgramClause < ChalkIr > > {
54
30
if self . panic {
55
- unimplemented ! ( )
31
+ panic ! ( "test panic" ) ;
56
32
} else {
57
- self . chalk_db . custom_clauses ( )
33
+ vec ! [ ]
58
34
}
59
35
}
60
36
61
37
fn associated_ty_data ( & self , ty : AssocTypeId < ChalkIr > ) -> Arc < AssociatedTyDatum < ChalkIr > > {
62
- self . chalk_db . associated_ty_data ( ty )
38
+ unimplemented ! ( )
63
39
}
64
40
65
41
fn trait_datum ( & self , id : TraitId < ChalkIr > ) -> Arc < TraitDatum < ChalkIr > > {
66
- self . chalk_db . trait_datum ( id)
42
+ assert_eq ! ( id. 0 . index, 0 ) ;
43
+ return Arc :: new ( chalk_rust_ir:: TraitDatum {
44
+ id,
45
+ binders : chalk_ir:: Binders :: new (
46
+ chalk_ir:: ParameterKinds :: new ( & ChalkIr ) ,
47
+ chalk_rust_ir:: TraitDatumBound {
48
+ where_clauses : vec ! [ ] ,
49
+ } ,
50
+ ) ,
51
+ flags : chalk_rust_ir:: TraitFlags {
52
+ auto : false ,
53
+ marker : false ,
54
+ upstream : false ,
55
+ fundamental : false ,
56
+ non_enumerable : false ,
57
+ coinductive : false ,
58
+ } ,
59
+ associated_ty_ids : vec ! [ ] ,
60
+ well_known : None ,
61
+ } ) ;
67
62
}
68
63
69
64
fn impl_datum ( & self , id : ImplId < ChalkIr > ) -> Arc < ImplDatum < ChalkIr > > {
70
- self . chalk_db . impl_datum ( id )
65
+ unimplemented ! ( )
71
66
}
72
67
73
68
fn associated_ty_value (
74
69
& self ,
75
70
id : AssociatedTyValueId < ChalkIr > ,
76
71
) -> Arc < AssociatedTyValue < ChalkIr > > {
77
- self . chalk_db . associated_ty_value ( id )
72
+ unimplemented ! ( )
78
73
}
79
74
80
75
fn opaque_ty_data ( & self , id : OpaqueTyId < ChalkIr > ) -> Arc < OpaqueTyDatum < ChalkIr > > {
81
- self . chalk_db . opaque_ty_data ( id )
76
+ unimplemented ! ( )
82
77
}
83
78
84
79
fn struct_datum ( & self , id : StructId < ChalkIr > ) -> Arc < StructDatum < ChalkIr > > {
85
- self . chalk_db . struct_datum ( id )
80
+ unimplemented ! ( )
86
81
}
87
82
88
83
fn as_struct_id ( & self , type_name : & TypeName < ChalkIr > ) -> Option < StructId < ChalkIr > > {
89
- self . chalk_db . as_struct_id ( type_name )
84
+ unimplemented ! ( )
90
85
}
91
86
92
87
fn impls_for_trait (
93
88
& self ,
94
89
trait_id : TraitId < ChalkIr > ,
95
90
parameters : & [ Parameter < ChalkIr > ] ,
96
91
) -> Vec < ImplId < ChalkIr > > {
97
- self . chalk_db . impls_for_trait ( trait_id , parameters )
92
+ unimplemented ! ( )
98
93
}
99
94
100
95
fn local_impls_to_coherence_check ( & self , trait_id : TraitId < ChalkIr > ) -> Vec < ImplId < ChalkIr > > {
101
- self . chalk_db . local_impls_to_coherence_check ( trait_id )
96
+ unimplemented ! ( )
102
97
}
103
98
104
99
fn impl_provided_for (
105
100
& self ,
106
101
auto_trait_id : TraitId < ChalkIr > ,
107
102
struct_id : StructId < ChalkIr > ,
108
103
) -> bool {
109
- self . chalk_db . impl_provided_for ( auto_trait_id , struct_id )
104
+ unimplemented ! ( )
110
105
}
111
106
112
107
fn well_known_trait_id ( & self , well_known_trait : WellKnownTrait ) -> Option < TraitId < ChalkIr > > {
113
- self . chalk_db . well_known_trait_id ( well_known_trait )
108
+ unimplemented ! ( )
114
109
}
115
110
116
111
fn interner ( & self ) -> & ChalkIr {
@@ -121,12 +116,11 @@ impl RustIrDatabase<ChalkIr> for MockDatabase {
121
116
#[ test]
122
117
fn unwind_safety ( ) {
123
118
use self :: MockDatabase ;
124
- use chalk_integration:: lowering:: LowerGoal ;
125
- use chalk_integration:: query:: LoweringDatabase ;
126
- use chalk_solve:: ext:: GoalExt ;
119
+ use chalk_ir:: * ;
127
120
use std:: panic;
128
121
129
122
// lower program
123
+ /*
130
124
let mut db = lower_program_with_db! {
131
125
program {
132
126
struct Foo { }
@@ -137,24 +131,43 @@ fn unwind_safety() {
137
131
};
138
132
139
133
let program = db.chalk_db.checked_program().unwrap();
140
-
141
- // lower goal
142
- let goal = lower_goal ! {
143
- goal {
144
- Foo : Bar
145
- }
146
- program & * program
134
+ */
135
+ let mut db = MockDatabase { panic : false } ;
136
+
137
+ let peeled_goal: UCanonical < InEnvironment < Goal < ChalkIr > > > = UCanonical {
138
+ canonical : Canonical {
139
+ binders : CanonicalVarKinds :: new ( & ChalkIr ) ,
140
+ value : InEnvironment {
141
+ environment : Environment :: new ( & ChalkIr ) ,
142
+ goal : GoalData :: DomainGoal ( DomainGoal :: Holds ( WhereClause :: Implemented ( TraitRef {
143
+ trait_id : TraitId ( interner:: RawId { index : 0 } ) ,
144
+ substitution : Substitution :: from1 (
145
+ & ChalkIr ,
146
+ ParameterKind :: Ty (
147
+ TyData :: Apply ( ApplicationTy {
148
+ name : TypeName :: Struct ( StructId ( interner:: RawId { index : 1 } ) ) ,
149
+ substitution : Substitution :: empty ( & ChalkIr ) ,
150
+ } )
151
+ . intern ( & ChalkIr ) ,
152
+ )
153
+ . intern ( & ChalkIr ) ,
154
+ ) ,
155
+ } ) ) )
156
+ . intern ( & ChalkIr ) ,
157
+ } ,
158
+ } ,
159
+ universes : 1 ,
147
160
} ;
148
- let peeled_goal = goal. into_peeled_goal ( db. interner ( ) ) ;
149
161
162
+ let mut solver = SolverChoice :: slg_default ( ) . into_solver ( ) ;
150
163
// solve goal but this will panic
151
164
db. panic = true ;
152
- let result = panic:: catch_unwind ( || {
153
- db . solve ( & peeled_goal) ;
154
- } ) ;
165
+ let result = panic:: catch_unwind ( panic :: AssertUnwindSafe ( || {
166
+ solver . solve ( & db , & peeled_goal) ;
167
+ } ) ) ;
155
168
assert ! ( result. is_err( ) == true ) ;
156
169
157
170
// solve again but without panicking this time
158
171
db. panic = false ;
159
- assert ! ( db . solve( & peeled_goal) . is_some( ) ) ;
172
+ assert ! ( solver . solve( & db , & peeled_goal) . is_some( ) ) ;
160
173
}
0 commit comments