Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work towards chalkify-ing the engine #49837

Merged
merged 9 commits into from
Apr 24, 2018

Conversation

nikomatsakis
Copy link
Contributor

This work towards creating a "all program clauses needed for this goal" query

r? @scalexm

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 10, 2018
@nikomatsakis
Copy link
Contributor Author

D'oh, have to rebase =)

@nikomatsakis
Copy link
Contributor Author

@bors delegate=scalexm

@bors
Copy link
Contributor

bors commented Apr 10, 2018

✌️ @scalexm can now approve this pull request

time(sess,
"dumping chalk-like clauses",
|| rustc_traits::lowering::dump_program_clauses(tcx));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit that when writing this code, I just put the compiler pass at the end of the function without thinking too much about it. What's the precise reason for preferring it to be placed before "death checking" etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, it's a subtle thing. when you invoke check_name to test the name of an attribute, you also implicitly mark the attribute as "used" (at least by default):

rust/src/libsyntax/attr.rs

Lines 208 to 214 in 43e994c

pub fn check_name(&self, name: &str) -> bool {
let matches = self.path == name;
if matches {
mark_used(self);
}
matches
}

this info is then used by the "unused attribute" lint. Since we were running this pass before the lint fired, that info was not available when the unused attribute lint executed, producing lint warnings of "unused attribute" in some cases (only the new tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that whole scheme needs to be rewritten for the query system at some point...

);
mem::swap(&mut next_round, &mut last_round);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good, we should be able to retrieve all the clauses that are of interest to us. One point though, we will want to run this algorithm not only for our environment, but also for goals we want to prove, e.g.:

impl<T: Clone> Clone for Vec<T> { ... }
// Implemented(Vec<T>: Clone) :- Implemented(T: Clone) (*)

fn foo<T: Clone>(a: Vec<T>) {
// it doesn't seem like the `T: Clone` in the environment will enable us to reach
// the (*) rule above

// We must prove `Implemented(Vec<T>: Clone)` here: if we run the transitive
// closure algorithm for this goal, we will reach the (*) rule
    let b = a.clone();
}

so could we just change the name program_clauses_for_env to something more general? Like program_clauses_for_goals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating about this-- specifically, what the key for the query should be, and how we should cache this information. I was sort of assuming that there would be some higher-level procedure that was, given a goal and its environment, assembling the full set of clauses (and caching the result, no doubt). Therefore, I figured this "for-env" query would just be a small part of it.

@scalexm
Copy link
Member

scalexm commented Apr 10, 2018

this is cool 👍🏻

@nikomatsakis
Copy link
Contributor Author

I'll try to rebase today.

@nikomatsakis
Copy link
Contributor Author

rebased

@scalexm
Copy link
Member

scalexm commented Apr 12, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Apr 12, 2018

📌 Commit e2f3781 has been approved by scalexm

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 12, 2018
@bors
Copy link
Contributor

bors commented Apr 12, 2018

☔ The latest upstream changes (presumably #49558) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 12, 2018
@nikomatsakis nikomatsakis force-pushed the chalkify-engine branch 2 times, most recently from a61da9a to d8c6d03 Compare April 13, 2018 00:21
@nikomatsakis
Copy link
Contributor Author

Rebased. However, the final results look a bit funny:

error: program clause dump
  --> $DIR/lower_env1.rs:18:1
   |
LL | #[rustc_dump_env_program_clauses] //~ ERROR program clause dump
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: Implemented(Self: std::marker::Sized) :- FromEnv(Self: std::marker::Sized).
   = note: Implemented(Self: Bar) :- FromEnv(Self: Bar).
   = note: FromEnv(Self: Bar) :- FromEnv(Self: Bar).
   = note: Implemented(Self: Foo) :- FromEnv(Self: Foo).

error: aborting due to previous error

In particular:

   = note: FromEnv(Self: Bar) :- FromEnv(Self: Bar).

but I don't think that is a problem that is due to this PR... I didn't investigate yet.

@rust-lang rust-lang deleted a comment from rust-highfive Apr 13, 2018
@bors
Copy link
Contributor

bors commented Apr 13, 2018

☔ The latest upstream changes (presumably #49800) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis nikomatsakis force-pushed the chalkify-engine branch 2 times, most recently from 72869cb to 64c0247 Compare April 13, 2018 20:28
@rust-lang rust-lang deleted a comment from rust-highfive Apr 13, 2018
@nikomatsakis
Copy link
Contributor Author

@bors r=scalexm

@bors
Copy link
Contributor

bors commented Apr 13, 2018

📌 Commit 64c0247 has been approved by scalexm

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 13, 2018
@bors
Copy link
Contributor

bors commented Apr 14, 2018

⌛ Testing commit 64c0247972adfae02d6a58d08d6e57e577b310aa with merge 04de83c7b7e488cfb82d61f022588551550dcd4d...

Chalk wants to be able to pass these constraints around. Also, the
form we were using in our existing queries was not as general as we
are going to need.
(rather than issuing multiple errors)

Also, reorder so that the annotations are considered "used" when the
lint runs.
This computes the transitive closure of traits that appear in the
environment and then appends their clauses. It needs some work, but
it's in the right direction.
Also, introduce `Clauses` and `Goals` type alises for readability.
@nikomatsakis
Copy link
Contributor Author

@bors r=scalexm

@bors
Copy link
Contributor

bors commented Apr 23, 2018

📌 Commit 2c5fbe2 has been approved by scalexm

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 23, 2018
@kennytm
Copy link
Member

kennytm commented Apr 24, 2018

@bors p=3

@bors
Copy link
Contributor

bors commented Apr 24, 2018

⌛ Testing commit 2c5fbe2 with merge 898c9f7...

bors added a commit that referenced this pull request Apr 24, 2018
work towards chalkify-ing the engine

This work towards creating a "all program clauses needed for this goal" query

r? @scalexm
@bors
Copy link
Contributor

bors commented Apr 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: scalexm
Pushing 898c9f7 to master...

/// An associated type **declaration** (i.e., in a trait)
AssocTypeInTrait(InternedString),
/// An associated type **value** (i.e., in an impl)
AssocTypeInImpl(InternedString),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this split done? Also, why "declaration vs value" and not "declaration vs definition"?

match tcx.def_key(def_id).disambiguated_data.data {
DefPathData::Trait(_) => program_clauses_for_trait(tcx, def_id),
DefPathData::Impl => program_clauses_for_impl(tcx, def_id),
DefPathData::AssocTypeInImpl(..) => program_clauses_for_associated_type_value(tcx, def_id),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I approve of using DefPathData outside of path-specific logic.
Maybe we need a new enum that's something in between DefPathData and Def?
"DefKind" comes to mind as a possible name.

cc @oli-obk @varkor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have

pub enum Def {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "something in between DefPathData and Def" I meant "not Def itself" - ideally, a plain enum with no DefIds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and Def should probably be renamed to Res(olution), as it's too specific to name resolution to deserve a more general name.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 19, 2018

So... We could make Def a struct Def { kind: DefKind, id: Option<DefId> } ?

@varkor
Copy link
Member

varkor commented Dec 19, 2018

The variants of Def aren't quite so homogeneous (e.g. SelfTy(Option<DefId>, Option<DefId>), StructCtor(DefId, CtorKind), etc.), so I'm not sure it'd make such a clean refactoring. It would probably end up duplicating the Def enum and stripping out the unnecessary data.

@eddyb
Copy link
Member

eddyb commented Jan 30, 2019

@oli-obk @varkor My preferred solution would be to have Res::Def(DefKind, DefId) (if we even want to bother with duplicating the DefKind there instead of having a map/query from DefId to DefKind)

That is, Def would become Res, it would keep all of its variants which don't just refer to definitions (in the sense of having a DefId), e.g. SelfTy, Local, etc. and gain a new Def(DefKind, DefId) variant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants