Skip to content

Encode unknown generic type parameters with (declare-forall-sort)#93

Draft
coeff-aij wants to merge 12 commits into
coord-e:mainfrom
coeff-aij:forall-sort
Draft

Encode unknown generic type parameters with (declare-forall-sort)#93
coeff-aij wants to merge 12 commits into
coord-e:mainfrom
coeff-aij:forall-sort

Conversation

@coeff-aij
Copy link
Copy Markdown
Collaborator

This PR introduces an extension to SMT-LIB2 to encode unknown type parameters (like T in f<T: PartialOrd>()) as a universally quantified sort.

For example, a universally quantified sort a0 is first declared using (declare-forall-sort a0) and then used everywhere like a normal sort.
This feature lays the groundwork for the future verification of generic functions involving unknown types.

Example

  • Input:
#[thrust_macros::context]
trait A {
    #[thrust_macros::requires(Self::p(x))]
    #[thrust_macros::ensures(Self::p(result))]
    fn f(&self, x: i64) -> i64;

    #[thrust_macros::predicate]
    fn p(x: i64) -> bool;
}

#[thrust_macros::requires(T::p(x))]
#[thrust_macros::ensures(T::p(result))]
fn target<T: A>(a: &T, x: i64) -> i64 {
    let mut v = x;
    let mut i = 0;
    while i < 3 {
        v = a.f(v);
        i += 1;
    }

    v
}

fn main() {}
  • output:
(set-logic HORN)

(declare-forall-sort a0)

; span=refine_fn_def 
(declare-fun p0 (Int a0) Bool)

; span=refine_fn_def 
(declare-fun p1 (Int a0 Int) Bool)

... (snip)

Comment thread src/rty/params.rs
termcolor::ColorSpec::new()
}
}
pub type TypeParamIdx = chc::ForallSortIdx;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It looks like ForallSortIdx could replace TypeParamIdx.
Should we unify them into ForallSortIdx, or keep both in ParamType?

Comment thread src/chc.rs
Comment on lines +1836 to +1837
pub forall_sorts: Vec<ForallSortIdx>,
pub num_forall_sort_idx: ForallSortIdx,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

forall_sorts is actually redundant because we know it only contains the range 0..num_forall_sort_idx.

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.

1 participant