Skip to content

Commit 036b2bc

Browse files
authored
Merge pull request #411 from jackh726/rustc_updates
Use FxHashMap/FxHashSet and add well-formed clause for tuples
2 parents f5d1427 + 8364200 commit 036b2bc

File tree

9 files changed

+30
-34
lines changed

9 files changed

+30
-34
lines changed

chalk-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ proc-macro = true
1414
[dependencies]
1515
synstructure = "0.12.1"
1616
quote = "1.0.2"
17-
proc-macro2 = "1.0.6"
17+
proc-macro2 = "1.0.3"
1818

1919
[dependencies.syn]
2020
version = "1.0.5"

chalk-integration/src/db.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use chalk_ir::Parameter;
1717
use chalk_ir::ProgramClause;
1818
use chalk_ir::StructId;
1919
use chalk_ir::TraitId;
20-
use chalk_ir::TypeName;
2120
use chalk_ir::{ProgramClauses, UCanonical};
2221
use chalk_rust_ir::AssociatedTyDatum;
2322
use chalk_rust_ir::AssociatedTyValue;
@@ -115,10 +114,6 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
115114
self.program_ir().unwrap().struct_datum(id)
116115
}
117116

118-
fn as_struct_id(&self, type_name: &TypeName<ChalkIr>) -> Option<StructId<ChalkIr>> {
119-
self.program_ir().unwrap().as_struct_id(type_name)
120-
}
121-
122117
fn impls_for_trait(
123118
&self,
124119
trait_id: TraitId<ChalkIr>,

chalk-integration/src/program.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use chalk_ir::tls;
66
use chalk_ir::{
77
debug::SeparatorTraitRef, AliasTy, ApplicationTy, AssocTypeId, Goal, Goals, ImplId, Lifetime,
88
OpaqueTy, OpaqueTyId, Parameter, ProgramClause, ProgramClauseImplication, ProgramClauses,
9-
ProjectionTy, StructId, Substitution, TraitId, Ty, TypeName,
9+
ProjectionTy, StructId, Substitution, TraitId, Ty,
1010
};
1111
use chalk_rust_ir::{
1212
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ImplDatum, ImplType, OpaqueTyDatum,
@@ -332,13 +332,6 @@ impl RustIrDatabase<ChalkIr> for Program {
332332
self.struct_data[&id].clone()
333333
}
334334

335-
fn as_struct_id(&self, type_name: &TypeName<ChalkIr>) -> Option<StructId<ChalkIr>> {
336-
match type_name {
337-
TypeName::Struct(struct_id) => Some(*struct_id),
338-
_ => None,
339-
}
340-
}
341-
342335
fn impls_for_trait(
343336
&self,
344337
trait_id: TraitId<ChalkIr>,

chalk-ir/src/interner.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
201201
///
202202
/// Returns `None` to fallback to the default debug output (e.g.,
203203
/// if no info about current program is available from TLS).
204+
#[allow(unused_variables)]
204205
fn debug_opaque_ty_id(
205206
opaque_ty_id: OpaqueTyId<Self>,
206207
fmt: &mut fmt::Formatter<'_>,
207-
) -> Option<fmt::Result>;
208+
) -> Option<fmt::Result> {
209+
None
210+
}
208211

209212
/// Prints the debug representation of an alias. To get good
210213
/// results, this requires inspecting TLS, and is difficult to
@@ -225,10 +228,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
225228
///
226229
/// Returns `None` to fallback to the default debug output (e.g.,
227230
/// if no info about current program is available from TLS).
231+
#[allow(unused_variables)]
228232
fn debug_projection_ty(
229233
projection_ty: &ProjectionTy<Self>,
230234
fmt: &mut fmt::Formatter<'_>,
231-
) -> Option<fmt::Result>;
235+
) -> Option<fmt::Result> {
236+
None
237+
}
232238

233239
/// Prints the debug representation of an OpaqueTy. To get good
234240
/// results, this requires inspecting TLS, and is difficult to
@@ -237,10 +243,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
237243
///
238244
/// Returns `None` to fallback to the default debug output (e.g.,
239245
/// if no info about current program is available from TLS).
246+
#[allow(unused_variables)]
240247
fn debug_opaque_ty(
241248
opaque_ty: &OpaqueTy<Self>,
242249
fmt: &mut fmt::Formatter<'_>,
243-
) -> Option<fmt::Result>;
250+
) -> Option<fmt::Result> {
251+
None
252+
}
244253

245254
/// Prints the debug representation of an type. To get good
246255
/// results, this requires inspecting TLS, and is difficult to

chalk-solve/src/clauses.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,12 @@ fn program_clauses_that_could_match<I: Interner>(
185185
let trait_datum = db.trait_datum(trait_id);
186186
if trait_datum.is_auto_trait() {
187187
match trait_ref.self_type_parameter(interner).data(interner) {
188-
TyData::Apply(apply) => {
189-
if let Some(struct_id) = db.as_struct_id(&apply.name) {
190-
push_auto_trait_impls(builder, trait_id, struct_id);
188+
TyData::Apply(apply) => match &apply.name {
189+
TypeName::Struct(struct_id) => {
190+
push_auto_trait_impls(builder, trait_id, *struct_id);
191191
}
192-
}
192+
_ => {}
193+
},
193194
TyData::InferenceVar(_) | TyData::BoundVar(_) => {
194195
return Err(Floundered);
195196
}
@@ -461,7 +462,9 @@ fn match_type_name<I: Interner>(
461462
TypeName::Scalar(_) => {
462463
builder.push_fact(WellFormed::Ty(application.clone().intern(interner)))
463464
}
464-
TypeName::Tuple(_) => (),
465+
TypeName::Tuple(_) => {
466+
builder.push_fact(WellFormed::Ty(application.clone().intern(interner)))
467+
}
465468
}
466469
}
467470

chalk-solve/src/clauses/generalize.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use chalk_ir::{
1313
Binders, BoundVar, DebruijnIndex, Lifetime, LifetimeData, ParameterKind, ParameterKinds, Ty,
1414
TyData,
1515
};
16-
use std::collections::HashMap;
16+
use rustc_hash::FxHashMap;
1717

1818
pub struct Generalize<'i, I: Interner> {
1919
binders: Vec<ParameterKind<()>>,
20-
mapping: HashMap<BoundVar, usize>,
20+
mapping: FxHashMap<BoundVar, usize>,
2121
interner: &'i I,
2222
}
2323

@@ -29,7 +29,7 @@ impl<I: Interner> Generalize<'_, I> {
2929
{
3030
let mut generalize = Generalize {
3131
binders: Vec::new(),
32-
mapping: HashMap::new(),
32+
mapping: FxHashMap::default(),
3333
interner,
3434
};
3535
let value = value

chalk-solve/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ pub trait RustIrDatabase<I: Interner>: Debug {
4343
/// Returns the `OpaqueTyDatum` with the given id.
4444
fn opaque_ty_data(&self, id: OpaqueTyId<I>) -> Arc<OpaqueTyDatum<I>>;
4545

46-
/// If `id` is a struct id, returns `Some(id)` (but cast to `StructId`).
47-
fn as_struct_id(&self, id: &TypeName<I>) -> Option<StructId<I>>;
48-
4946
/// Returns a list of potentially relevant impls for a given
5047
/// trait-id; we also supply the type parameters that we are
5148
/// trying to match (if known: these parameters may contain

chalk-solve/src/recursive/fulfill.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use infer::{
1111
InferenceTable, ParameterEnaVariable, ParameterEnaVariableExt,
1212
};
1313
use interner::HasInterner;
14-
use std::collections::HashSet;
14+
use rustc_hash::FxHashSet;
1515
use std::fmt::Debug;
1616
use zip::Zip;
1717

@@ -77,7 +77,7 @@ pub(crate) struct Fulfill<'s, 'db, I: Interner> {
7777

7878
/// Lifetime constraints that must be fulfilled for a solution to be fully
7979
/// validated.
80-
constraints: HashSet<InEnvironment<Constraint<I>>>,
80+
constraints: FxHashSet<InEnvironment<Constraint<I>>>,
8181

8282
/// Record that a goal has been processed that can neither be proved nor
8383
/// refuted. In such a case the solution will be either `CannotProve`, or `Err`
@@ -99,7 +99,7 @@ impl<'s, 'db, I: Interner> Fulfill<'s, 'db, I> {
9999
solver,
100100
infer,
101101
obligations: vec![],
102-
constraints: HashSet::new(),
102+
constraints: FxHashSet::default(),
103103
cannot_prove: false,
104104
};
105105
(fulfill, subst, canonical_goal)

chalk-solve/src/recursive/search_graph.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashMap;
21
use std::ops::Add;
32
use std::ops::Index;
43
use std::ops::IndexMut;
@@ -12,7 +11,7 @@ use chalk_ir::{interner::Interner, ClausePriority};
1211
use rustc_hash::FxHashMap;
1312

1413
pub(super) struct SearchGraph<I: Interner> {
15-
indices: HashMap<UCanonicalGoal<I>, DepthFirstNumber>,
14+
indices: FxHashMap<UCanonicalGoal<I>, DepthFirstNumber>,
1615
nodes: Vec<Node<I>>,
1716
}
1817

@@ -41,7 +40,7 @@ pub(super) struct Node<I: Interner> {
4140
impl<I: Interner> SearchGraph<I> {
4241
pub(crate) fn new() -> Self {
4342
SearchGraph {
44-
indices: HashMap::new(),
43+
indices: FxHashMap::default(),
4544
nodes: vec![],
4645
}
4746
}

0 commit comments

Comments
 (0)