Skip to content

Commit f942d5d

Browse files
committed
Get rid of TermKind in annot module
1 parent bee91bc commit f942d5d

File tree

3 files changed

+67
-103
lines changed

3 files changed

+67
-103
lines changed

src/analyze/annot.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use rustc_ast::ast::Attribute;
22
use rustc_ast::tokenstream::TokenStream;
33
use rustc_index::IndexVec;
4-
use rustc_middle::ty as mir_ty;
54
use rustc_span::symbol::{Ident, Symbol};
65

76
use crate::annot;
7+
use crate::chc;
88
use crate::rty;
99

1010
pub fn requires_path() -> [Symbol; 2] {
@@ -31,64 +31,50 @@ pub fn callable_path() -> [Symbol; 2] {
3131
[Symbol::intern("thrust"), Symbol::intern("callable")]
3232
}
3333

34-
fn ty_to_term_kind(ty: &mir_ty::Ty<'_>) -> annot::TermKind {
35-
match ty.kind() {
36-
mir_ty::TyKind::Ref(_, ty, mir_ty::Mutability::Mut) => {
37-
annot::TermKind::mut_(ty_to_term_kind(ty))
38-
}
39-
mir_ty::TyKind::Ref(_, ty, mir_ty::Mutability::Not) => {
40-
annot::TermKind::box_(ty_to_term_kind(ty))
41-
}
42-
mir_ty::TyKind::Adt(def, _) if def.is_box() => annot::TermKind::box_(ty_to_term_kind(ty)),
43-
_ => annot::TermKind::other(),
44-
}
45-
}
46-
4734
#[derive(Debug, Clone, Default)]
4835
pub struct ParamResolver {
49-
params: IndexVec<rty::FunctionParamIdx, (Symbol, annot::TermKind)>,
36+
params: IndexVec<rty::FunctionParamIdx, (Symbol, chc::Sort)>,
5037
}
5138

5239
impl annot::Resolver for ParamResolver {
5340
type Output = rty::FunctionParamIdx;
54-
fn resolve(&self, ident: Ident) -> Option<(Self::Output, annot::TermKind)> {
41+
fn resolve(&self, ident: Ident) -> Option<(Self::Output, chc::Sort)> {
5542
self.params
5643
.iter_enumerated()
5744
.find(|(_, (name, _))| name == &ident.name)
58-
.map(|(idx, (_, kind))| (idx, kind.clone()))
45+
.map(|(idx, (_, sort))| (idx, sort.clone()))
5946
}
6047
}
6148

6249
impl ParamResolver {
63-
pub fn push_param(&mut self, name: Symbol, ty: &mir_ty::Ty<'_>) {
64-
self.params.push((name, ty_to_term_kind(ty)));
50+
pub fn push_param(&mut self, name: Symbol, sort: chc::Sort) {
51+
self.params.push((name, sort));
6552
}
6653
}
6754

6855
#[derive(Debug, Clone)]
6956
pub struct ResultResolver {
7057
result_symbol: Symbol,
71-
result_kind: annot::TermKind,
58+
result_sort: chc::Sort,
7259
}
7360

7461
impl annot::Resolver for ResultResolver {
7562
type Output = rty::RefinedTypeVar<rty::FunctionParamIdx>;
76-
fn resolve(&self, ident: Ident) -> Option<(Self::Output, annot::TermKind)> {
63+
fn resolve(&self, ident: Ident) -> Option<(Self::Output, chc::Sort)> {
7764
if ident.name == self.result_symbol {
78-
Some((rty::RefinedTypeVar::Value, self.result_kind.clone()))
65+
Some((rty::RefinedTypeVar::Value, self.result_sort.clone()))
7966
} else {
8067
None
8168
}
8269
}
8370
}
8471

8572
impl ResultResolver {
86-
pub fn new(result_ty: &mir_ty::Ty<'_>) -> Self {
73+
pub fn new(result_sort: chc::Sort) -> Self {
8774
let result_symbol = Symbol::intern("result");
88-
let result_kind = ty_to_term_kind(result_ty);
8975
Self {
9076
result_symbol,
91-
result_kind,
77+
result_sort,
9278
}
9379
}
9480
}

src/analyze/crate_.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
120120

121121
let mut param_resolver = analyze::annot::ParamResolver::default();
122122
for (input_ident, input_ty) in self.tcx.fn_arg_names(def_id).iter().zip(sig.inputs()) {
123-
param_resolver.push_param(input_ident.name, input_ty);
123+
let input_ty = self.ctx.unrefined_ty(*input_ty);
124+
param_resolver.push_param(input_ident.name, input_ty.to_sort());
124125
}
125126

126127
let mut require_annot = self.extract_require_annot(&param_resolver, def_id);
127128
let mut ensure_annot = {
129+
let output_ty = self.ctx.unrefined_ty(sig.output());
128130
let resolver = annot::StackedResolver::default()
129-
.resolver(analyze::annot::ResultResolver::new(&sig.output()))
131+
.resolver(analyze::annot::ResultResolver::new(output_ty.to_sort()))
130132
.resolver((&param_resolver).map(rty::RefinedTypeVar::Free));
131133
self.extract_ensure_annot(resolver, def_id)
132134
};

0 commit comments

Comments
 (0)