Skip to content

Commit 8391931

Browse files
committed
[hermes] Add some tests for Charon invocation
gherrit-pr-id: G60bb1cd41a5fade3144a05f2bdafb2a670059e03
1 parent 3434d56 commit 8391931

File tree

1,520 files changed

+785145
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,520 files changed

+785145
-61
lines changed

tools/Cargo.lock

Lines changed: 133 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/hermes/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ assert_cmd = "2.1.2"
3131
tempfile = "3.24.0"
3232
predicates = "3.1.3"
3333
datatest-stable = "0.3.3"
34+
serde = { version = "1.0", features = ["derive"] }
35+
toml = "0.8"
36+
which = "6.0"
3437

3538
[[test]]
3639
name = "integration"

tools/hermes/src/charon.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ pub fn run_charon(args: &Args, roots: &Roots, packages: &[HermesArtifact]) -> Re
3030
// Fail fast on errors
3131
cmd.arg("--abort-on-error");
3232

33-
// Start translation from specific entry points
34-
cmd.arg("--start-from").arg(artifact.start_from.join(","));
33+
// Start translation from specific entry points. Sort to ensure
34+
// deterministic ordering for testing (not important in production).
35+
let mut start_from = artifact.start_from.clone();
36+
start_from.sort();
37+
cmd.arg("--start-from").arg(start_from.join(","));
3538

3639
// Separator for the underlying cargo command
3740
cmd.arg("--");

tools/hermes/src/parse.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use log::{debug, trace};
88
use miette::{NamedSource, SourceSpan};
99
use proc_macro2::Span;
1010
use syn::{
11-
spanned::Spanned as _, visit::Visit, Attribute, Error, Expr, ItemEnum, ItemFn, ItemImpl,
12-
ItemMod, ItemStruct, ItemTrait, ItemUnion, Lit, Meta,
11+
spanned::Spanned as _, visit::Visit, Attribute, Error, Expr, ImplItemFn, ItemEnum, ItemFn,
12+
ItemImpl, ItemMod, ItemStruct, ItemTrait, ItemUnion, Lit, Meta,
1313
};
1414

1515
use crate::errors::HermesError;
@@ -42,6 +42,7 @@ pub enum ParsedItem {
4242
Union(ItemUnion),
4343
Trait(ItemTrait),
4444
Impl(ItemImpl),
45+
ImplItemFn(ImplItemFn),
4546
}
4647

4748
impl ParsedItem {
@@ -52,6 +53,7 @@ impl ParsedItem {
5253
Self::Enum(item) => Some(item.ident.to_string()),
5354
Self::Union(item) => Some(item.ident.to_string()),
5455
Self::Trait(item) => Some(item.ident.to_string()),
56+
Self::ImplItemFn(item) => Some(item.sig.ident.to_string()),
5557
Self::Impl(_) => None,
5658
}
5759
}
@@ -65,6 +67,7 @@ impl ParsedItem {
6567
Self::Union(item) => &item.attrs,
6668
Self::Trait(item) => &item.attrs,
6769
Self::Impl(item) => &item.attrs,
70+
Self::ImplItemFn(item) => &item.attrs,
6871
}
6972
}
7073
}
@@ -226,6 +229,14 @@ where
226229
}
227230
}
228231

232+
fn get_type_ident(ty: &syn::Type) -> Option<String> {
233+
match ty {
234+
syn::Type::Path(type_path) => Some(type_path.path.segments.last()?.ident.to_string()),
235+
syn::Type::Reference(type_ref) => get_type_ident(&type_ref.elem),
236+
_ => None,
237+
}
238+
}
239+
229240
impl<'ast, I, M> Visit<'ast> for HermesVisitor<I, M>
230241
where
231242
I: FnMut(&str, Result<ParsedLeanItem, HermesError>),
@@ -275,15 +286,35 @@ where
275286
}
276287

277288
fn visit_item_trait(&mut self, node: &'ast ItemTrait) {
278-
trace!("Visiting Trait {}", node.ident);
289+
let name = node.ident.to_string();
290+
trace!("Visiting Trait {}", name);
279291
self.check_and_add(ParsedItem::Trait(node.clone()), node.span());
292+
293+
self.current_path.push(name);
280294
syn::visit::visit_item_trait(self, node);
295+
self.current_path.pop();
281296
}
282297

283298
fn visit_item_impl(&mut self, node: &'ast ItemImpl) {
284299
trace!("Visiting Impl");
285300
self.check_and_add(ParsedItem::Impl(node.clone()), node.span());
301+
302+
let type_name = get_type_ident(&node.self_ty);
303+
if let Some(ref name) = type_name {
304+
self.current_path.push(name.clone());
305+
}
306+
286307
syn::visit::visit_item_impl(self, node);
308+
309+
if type_name.is_some() {
310+
self.current_path.pop();
311+
}
312+
}
313+
314+
fn visit_impl_item_fn(&mut self, node: &'ast ImplItemFn) {
315+
trace!("Visiting ImplItemFn {}", node.sig.ident);
316+
self.check_and_add(ParsedItem::ImplItemFn(node.clone()), node.span());
317+
syn::visit::visit_impl_item_fn(self, node);
287318
}
288319
}
289320

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
verify --workspace
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "pkg_a"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# Force the library artifact to be named "common_utils"
7+
[lib]
8+
name = "common_utils"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// ```lean
2+
/// ```
3+
fn utils_a() {}

0 commit comments

Comments
 (0)