Skip to content

Commit 2ee1c9d

Browse files
committed
Address comments / clarify docs
1 parent 3c126b2 commit 2ee1c9d

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

chalk-solve/src/clauses/program_clauses.rs

+22-27
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,20 @@ impl<I: Interner> ToProgramClauses<I> for AdtDatum<I> {
361361
/// ```notrust
362362
/// #[upstream]
363363
/// #[fundamental]
364-
/// struct Box<T> {}
364+
/// struct Box<T, U> {}
365365
/// ```
366366
///
367367
/// We generate the following clauses:
368368
///
369369
/// ```notrust
370-
/// forall<T> { IsLocal(Box<T>) :- IsLocal(T). }
370+
/// forall<T, U> { IsLocal(Box<T, U>) :- IsLocal(T). }
371+
/// forall<T, U> { IsLocal(Box<T, U>) :- IsLocal(U). }
371372
///
372-
/// forall<T> { IsUpstream(Box<T>) :- IsUpstream(T). }
373+
/// forall<T, U> { IsUpstream(Box<T, U>) :- IsUpstream(T), IsUpstream(U). }
373374
///
374375
/// // Generated for both upstream and local fundamental types
375-
/// forall<T> { DownstreamType(Box<T>) :- DownstreamType(T). }
376+
/// forall<T, U> { DownstreamType(Box<T, U>) :- DownstreamType(T). }
377+
/// forall<T, U> { DownstreamType(Box<T, U>) :- DownstreamType(U). }
376378
/// ```
377379
///
378380
#[instrument(level = "debug", skip(builder))]
@@ -395,27 +397,6 @@ impl<I: Interner> ToProgramClauses<I> for AdtDatum<I> {
395397
let self_appl_ty = application_ty(builder, id);
396398
let self_ty = self_appl_ty.clone().intern(interner);
397399

398-
// Fundamental types often have rules in the form of:
399-
// Goal(FundamentalType<T>) :- Goal(T)
400-
// This macro makes creating that kind of clause easy
401-
macro_rules! fundamental_rule {
402-
($goal:ident) => {
403-
// Fundamental types must always have at least one
404-
// type parameter for this rule to make any
405-
// sense.
406-
assert!(
407-
self_appl_ty.len_type_parameters(interner) >= 1,
408-
"Only fundamental types with type parameter are supported"
409-
);
410-
for type_param in self_appl_ty.type_parameters(interner) {
411-
builder.push_clause(
412-
DomainGoal::$goal(self_ty.clone()),
413-
Some(DomainGoal::$goal(type_param)),
414-
);
415-
}
416-
};
417-
}
418-
419400
// Types that are not marked `#[upstream]` satisfy IsLocal(TypeName)
420401
if !self.flags.upstream {
421402
// `IsLocalTy(Ty)` depends *only* on whether the type
@@ -425,7 +406,12 @@ impl<I: Interner> ToProgramClauses<I> for AdtDatum<I> {
425406
// If a type is `#[upstream]`, but is also
426407
// `#[fundamental]`, it satisfies IsLocal if and only
427408
// if its parameters satisfy IsLocal
428-
fundamental_rule!(IsLocal);
409+
for type_param in self_appl_ty.type_parameters(interner) {
410+
builder.push_clause(
411+
DomainGoal::IsLocal(self_ty.clone()),
412+
Some(DomainGoal::IsLocal(type_param)),
413+
);
414+
}
429415
builder.push_clause(
430416
DomainGoal::IsUpstream(self_ty.clone()),
431417
self_appl_ty
@@ -438,7 +424,16 @@ impl<I: Interner> ToProgramClauses<I> for AdtDatum<I> {
438424
}
439425

440426
if self.flags.fundamental {
441-
fundamental_rule!(DownstreamType);
427+
assert!(
428+
self_appl_ty.len_type_parameters(interner) >= 1,
429+
"Only fundamental types with type parameters are supported"
430+
);
431+
for type_param in self_appl_ty.type_parameters(interner) {
432+
builder.push_clause(
433+
DomainGoal::DownstreamType(self_ty.clone()),
434+
Some(DomainGoal::DownstreamType(type_param)),
435+
);
436+
}
442437
}
443438
});
444439
}

0 commit comments

Comments
 (0)