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

Support cycles in encoders #47

Merged
merged 7 commits into from
May 14, 2024
Merged

Conversation

Aurel300
Copy link
Owner

The task encoder framework now supports cyclic dependencies (better).

Previously, requesting the same task key that is already higher up the call stack would crash with a "cyclic error". There are situations (as happened with a recursive type) where this is not good enough.

Now, the repeated request will restart the encoder. The inner invocation should be able to progress further due to the intermediate dependency calls, since additional output refs will be available. The outer invocation will be aborted. This may result in some data being allocated multiple times, but it is hard to measure the cost here. However, the overhead in implementation is minor: deps.emit_ouput_ref and any deps.require_* call simply needs to be handled with a try operator ? to propagate errors.

Other changes:

  • There is now a type alias for the return type of do_encode_full, called EncodeFullResult<'vir, E>, where the generic type parameter is the encoder itself.
  • Got rid of the 'tcx lifetime, 'vir suffices.

@Aurel300
Copy link
Owner Author

Aurel300 commented May 10, 2024

@zgrannan Could you have a look at this? With this code I get an error which seems to be related to generics:

struct R(Option<Box<R>>);
fn main() {
    match R(None).0 {
        Some(_) => (),
        _ => (),
    }
}
Predicate p_Option could not be applied. Expected arg types: UnknownArityAny([Ref, Type]), Actual arg types: [Ref]

@zgrannan
Copy link

It looks like it was due to not including type parameters in the predicate application.
I've fixed this in the impure_generics branch with cf05f4f; I also refactored a little bit to make it harder to accidentally forget them in the future.

@Aurel300 Aurel300 force-pushed the feature/task-encoder-cycles branch from 5650c57 to f163ed0 Compare May 14, 2024 15:36
@Aurel300 Aurel300 merged commit c3b2a75 into rewrite-2023 May 14, 2024
trktby pushed a commit to trktby/prusti-dev that referenced this pull request Aug 12, 2024
* domain fields don't need a full encoding of their type yet

* type alias for do_encode_full result

* parameterise TaskEncoderDependencies by the owning encoder

* remove some dependency unwraps

* remove 'tcx lifetime, use 'vir

* check for cycles when requesting dependencies or emitting output ref

* add try operators for some emit output refs
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