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

Initial support for traits in impure code #51

Open
wants to merge 4 commits into
base: rewrite-2023
Choose a base branch
from

Conversation

zgrannan
Copy link

Start support for traits in impure code.

This PR does not yet support encoding the traits themselves as domains in Viper yet.
No support for type-conditional spec refinement yet.

Comment on lines 263 to 274
let call_trait_substs =
ty::EarlyBinder::bind(trait_ref.args).instantiate(tcx, impl_method_substs);
let impl_substs = ty::List::identity_for_item(tcx, impl_def_id);
let trait_method_substs = tcx.mk_args_from_iter(
call_trait_substs
.iter()
.chain(impl_method_substs.iter().skip(impl_substs.len())),
);

// sanity check: do we now have the correct number of substs?
let identity_trait_method = ty::List::identity_for_item(tcx, trait_method_def_id);
assert_eq!(trait_method_substs.len(), identity_trait_method.len());
Copy link

Choose a reason for hiding this comment

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

I'm a bit fuzzy now, but I believe this is what rustc internally calls "rebasing" the substitution, no? Can we not just use that?

Copy link
Author

@zgrannan zgrannan May 21, 2024

Choose a reason for hiding this comment

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

Refactored to use rebase_onto. For some reason, the rebase_onto operation doesn't include the initial subst for Self in the trait generics (e.g. Foo -> Self for impl Trait for Foo), so that needs to be added back in. Nevermind, I wasn't using it correctly initially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants