Skip to content

Commit 733f12f

Browse files
authored
Merge pull request #140 from sunjay/implallowed
Rename IsLocal to ImplAllowed
2 parents 1b9140c + 6658d35 commit 733f12f

File tree

9 files changed

+31
-23
lines changed

9 files changed

+31
-23
lines changed

chalk-parse/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub enum WhereClause {
218218
UnifyLifetimes { a: Lifetime, b: Lifetime },
219219
TraitInScope { trait_name: Identifier },
220220
Derefs { source: Ty, target: Ty },
221-
TyIsLocal { ty: Ty },
221+
IsLocal { ty: Ty },
222222
}
223223

224224
pub struct QuantifiedWhereClause {

chalk-parse/src/parser.lalrpop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ WhereClause: WhereClause = {
273273
"InScope" "(" <t:Id> ")" => WhereClause::TraitInScope { trait_name: t },
274274
"Derefs" "(" <source:Ty> "," <target:Ty> ")" => WhereClause::Derefs { source, target },
275275

276-
"IsLocal" "(" <ty:Ty> ")" => WhereClause::TyIsLocal { ty },
276+
"IsLocal" "(" <ty:Ty> ")" => WhereClause::IsLocal { ty },
277277
};
278278

279279
QuantifiedWhereClause: QuantifiedWhereClause = {

src/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ enum_fold!(PolarizedTraitRef[] { Positive(a), Negative(a) });
425425
enum_fold!(ParameterKind[T,L] { Ty(a), Lifetime(a) } where T: Fold, L: Fold);
426426
enum_fold!(WhereClauseAtom[] { Implemented(a), ProjectionEq(a) });
427427
enum_fold!(DomainGoal[] { Holds(a), WellFormed(a), FromEnv(a), Normalize(a), UnselectedNormalize(a),
428-
WellFormedTy(a), FromEnvTy(a), InScope(a), Derefs(a), IsLocalTy(a), IsLocalTraitRef(a) });
428+
WellFormedTy(a), FromEnvTy(a), InScope(a), Derefs(a), IsLocal(a), LocalImplAllowed(a) });
429429
enum_fold!(LeafGoal[] { EqGoal(a), DomainGoal(a) });
430430
enum_fold!(Constraint[] { LifetimeEq(a, b) });
431431
enum_fold!(Goal[] { Quantified(qkind, subgoal), Implies(wc, subgoal), And(g1, g2), Not(g),

src/ir.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub enum InlineBound {
269269

270270
impl InlineBound {
271271
/// Applies the `InlineBound` to `self_ty` and lowers to a [`DomainGoal`].
272-
///
272+
///
273273
/// Because an `InlineBound` does not know anything about what it's binding,
274274
/// you must provide that type as `self_ty`.
275275
crate fn lower_with_self(&self, self_ty: Ty) -> Vec<DomainGoal> {
@@ -691,8 +691,16 @@ pub enum DomainGoal {
691691
/// True if a type is considered to have been "defined" by the current crate. This is true for
692692
/// a `struct Foo { }` but false for a `extern struct Foo { }`. However, for fundamental types
693693
/// like `Box<T>`, it is true if `T` is local.
694-
IsLocalTy(Ty),
695-
IsLocalTraitRef(TraitRef),
694+
IsLocal(Ty),
695+
696+
/// Used to dictate when trait impls are allowed in the current (local) crate based on the
697+
/// orphan rules.
698+
///
699+
/// `LocalImplAllowed(T: Trait)` is true if the type T is allowed to impl trait Trait in
700+
/// the current crate. Under the current rules, this is unconditionally true for all types if
701+
/// the Trait is considered to be "defined" in the current crate. If that is not the case, then
702+
/// `LocalImplAllowed(T: Trait)` can still be true if `IsLocal(T)` is true.
703+
LocalImplAllowed(TraitRef),
696704
}
697705

698706
pub type QuantifiedDomainGoal = Binders<DomainGoal>;

src/ir/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ impl Debug for DomainGoal {
206206
DomainGoal::FromEnvTy(t) => write!(fmt, "FromEnv({:?})", t),
207207
DomainGoal::InScope(n) => write!(fmt, "InScope({:?})", n),
208208
DomainGoal::Derefs(n) => write!(fmt, "Derefs({:?})", n),
209-
DomainGoal::IsLocalTy(n) => write!(fmt, "IsLocalTy({:?})", n),
210-
DomainGoal::IsLocalTraitRef(n) => write!(fmt, "IsLocalTraitRef({:?})", n),
209+
DomainGoal::IsLocal(n) => write!(fmt, "IsLocal({:?})", n),
210+
DomainGoal::LocalImplAllowed(n) => write!(fmt, "LocalImplAllowed({:?})", n),
211211
}
212212
}
213213
}

src/ir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ impl LowerWhereClause<ir::DomainGoal> for WhereClause {
494494
target: target.lower(env)?
495495
})
496496
],
497-
WhereClause::TyIsLocal { ty } => vec![
498-
ir::DomainGoal::IsLocalTy(ty.lower(env)?)
497+
WhereClause::IsLocal { ty } => vec![
498+
ir::DomainGoal::IsLocal(ty.lower(env)?)
499499
],
500500
};
501501
Ok(goals)
@@ -527,7 +527,7 @@ impl LowerWhereClause<ir::LeafGoal> for WhereClause {
527527
| WhereClause::TyFromEnv { .. }
528528
| WhereClause::TraitRefFromEnv { .. }
529529
| WhereClause::Derefs { .. }
530-
| WhereClause::TyIsLocal { .. } => {
530+
| WhereClause::IsLocal { .. } => {
531531
let goals: Vec<ir::DomainGoal> = self.lower(env)?;
532532
goals.into_iter().casted().collect()
533533
}

src/rules.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl ir::StructDatum {
294294
//
295295
// If the type Foo is not marked `extern`, we also generate:
296296
//
297-
// forall<T> { IsLocalTy(Foo<T>) }
297+
// forall<T> { IsLocal(Foo<T>) }
298298
//
299299
// Given an `extern` type that is also fundamental:
300300
//
@@ -303,7 +303,7 @@ impl ir::StructDatum {
303303
//
304304
// We generate the following clause:
305305
//
306-
// forall<T> { IsLocalTy(Box<T>) :- IsLocalTy(T) }
306+
// forall<T> { IsLocal(Box<T>) :- IsLocal(T) }
307307

308308
let wf = self.binders.map_ref(|bound_datum| {
309309
ir::ProgramClauseImplication {
@@ -323,16 +323,16 @@ impl ir::StructDatum {
323323

324324
// Types that are not marked `extern` satisfy IsLocal(TypeName)
325325
if !self.binders.value.flags.external {
326-
// `IsLocalTy(Ty)` depends *only* on whether the type is marked extern and nothing else
326+
// `IsLocal(Ty)` depends *only* on whether the type is marked extern and nothing else
327327
let is_local = self.binders.map_ref(|bound_datum| ir::ProgramClauseImplication {
328-
consequence: ir::DomainGoal::IsLocalTy(bound_datum.self_ty.clone().cast()),
328+
consequence: ir::DomainGoal::IsLocal(bound_datum.self_ty.clone().cast()),
329329
conditions: Vec::new(),
330330
}).cast();
331331

332332
clauses.push(is_local);
333333
} else if self.binders.value.flags.fundamental {
334-
// If a type is `extern`, but is also `#[fundamental]`, it satisfies IsLocalTy
335-
// if and only if its parameters satisfy IsLocalTy
334+
// If a type is `extern`, but is also `#[fundamental]`, it satisfies IsLocal
335+
// if and only if its parameters satisfy IsLocal
336336

337337
// Fundamental types must always have at least one type parameter for this rule to
338338
// make any sense. We currently do not have have any fundamental types with more than
@@ -343,9 +343,9 @@ impl ir::StructDatum {
343343
"Only fundamental types with a single parameter are supported");
344344

345345
let local_fundamental = self.binders.map_ref(|bound_datum| ir::ProgramClauseImplication {
346-
consequence: ir::DomainGoal::IsLocalTy(bound_datum.self_ty.clone().cast()),
346+
consequence: ir::DomainGoal::IsLocal(bound_datum.self_ty.clone().cast()),
347347
conditions: vec![
348-
ir::DomainGoal::IsLocalTy(
348+
ir::DomainGoal::IsLocal(
349349
// This unwrap is safe because we asserted above for the presence of a type
350350
// parameter
351351
bound_datum.self_ty.first_type_parameter().unwrap()

src/rules/wf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ impl FoldInputTypes for DomainGoal {
143143
DomainGoal::FromEnv(..) |
144144
DomainGoal::WellFormedTy(..) |
145145
DomainGoal::FromEnvTy(..) |
146-
DomainGoal::IsLocalTy(..) |
147-
DomainGoal::IsLocalTraitRef(..) |
146+
DomainGoal::IsLocal(..) |
147+
DomainGoal::LocalImplAllowed(..) |
148148
DomainGoal::Derefs(..) => panic!("unexpected where clause"),
149149

150150
DomainGoal::InScope(..) => (),

src/zip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ enum_zip!(DomainGoal {
227227
FromEnvTy,
228228
InScope,
229229
Derefs,
230-
IsLocalTy,
231-
IsLocalTraitRef
230+
IsLocal,
231+
LocalImplAllowed
232232
});
233233
enum_zip!(LeafGoal { DomainGoal, EqGoal });
234234
enum_zip!(ProgramClause { Implies, ForAll });

0 commit comments

Comments
 (0)