Skip to content

Commit 76a916e

Browse files
committed
[hermes] Get tests passing again
gherrit-pr-id: G3db3762006cf6333a7112b668f747072f8bb477b
1 parent 5660a8c commit 76a916e

File tree

40 files changed

+149
-37
lines changed

40 files changed

+149
-37
lines changed

tools/hermes/src/parse.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,17 +325,14 @@ where
325325

326326
// If this is a trait impl, we use UFCS syntax (`<Type as Trait>`). If
327327
// this is an inherent impl, we use the `Type: Type` syntax.
328+
let self_ty = &node.self_ty;
328329
let segment = if let Some((_, path, _)) = &node.trait_ {
329-
let self_ty = &node.self_ty;
330-
let tokens = quote! { <#self_ty as #path> };
331-
tokens.to_string().replace(" ", "") // Remove spaces for cleaner paths
330+
quote! { <#self_ty as #path> }
332331
} else {
333-
let self_ty = &node.self_ty;
334-
let tokens = quote! { #self_ty };
335-
tokens.to_string().replace(" ", "")
332+
quote! { #self_ty }
336333
};
337334

338-
self.current_path.push(segment);
335+
self.current_path.push(segment.to_string());
339336
syn::visit::visit_item_impl(self, node);
340337
self.current_path.pop();
341338
}

tools/hermes/src/transform.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
use proc_macro2::Span;
1+
use std::ops::Range;
2+
23
use syn::spanned::Spanned;
34

45
use crate::parse::{ParsedItem, ParsedLeanItem};
56

6-
/// Appends the spans of text that should be blanked out in the shadow crate.
7+
/// Appends the byte ranges that should be blanked out in the shadow crate.
78
///
89
/// For `unsafe` functions with Hermes annotations, this targets:
910
/// 1. The `unsafe` keyword (to make the function signature "safe" for Aeneas).
10-
/// 2. The entire function block (to remove the unverified implementation).
11-
pub fn append_edits(item: &ParsedLeanItem, edits: &mut Vec<Span>) {
11+
/// 2. The *contents* of the function block (preserving the braces `{}`).
12+
pub fn append_edits(item: &ParsedLeanItem, edits: &mut Vec<Range<usize>>) {
1213
if let ParsedItem::Fn(func) = &item.item {
1314
if let Some(unsafety) = &func.sig.unsafety {
1415
// 1. Mark the `unsafe` keyword for blanking.
1516
// Result: `unsafe fn` -> ` fn`
16-
edits.push(unsafety.span());
17+
edits.push(unsafety.span().byte_range());
1718

1819
// TODO:
1920
// - Only blank bodies for functions which are modeled.
2021
// - Figure out what to replace these bodies with.
21-
edits.push(func.block.span());
22+
23+
// 2. Mark the *inside* of the block for blanking.
24+
// We use start+1 and end-1 to preserve the curly braces.
25+
let block_range = func.block.span().byte_range();
26+
if block_range.len() >= 2 {
27+
edits.push(block_range.start + 1..block_range.end - 1);
28+
}
2229
}
2330
}
2431
}
@@ -34,9 +41,9 @@ pub fn append_edits(item: &ParsedLeanItem, edits: &mut Vec<Span>) {
3441
/// # Panics
3542
///
3643
/// Panics if any span in `edits` is not in-bounds of `buffer`.
37-
pub fn apply_edits(buffer: &mut [u8], edits: &[Span]) {
38-
for span in edits {
39-
for byte in &mut buffer[span.byte_range()] {
44+
pub fn apply_edits(buffer: &mut [u8], edits: &[Range<usize>]) {
45+
for range in edits {
46+
for byte in &mut buffer[range.clone()] {
4047
if !matches!(*byte, b'\n' | b'\r') {
4148
*byte = b' ';
4249
}
@@ -59,7 +66,8 @@ mod tests {
5966
_ => panic!("Expected function"),
6067
};
6168

62-
let edits = vec![func.sig.unsafety.unwrap().span(), func.block.span()];
69+
let edits =
70+
vec![func.sig.unsafety.unwrap().span().byte_range(), func.block.span().byte_range()];
6371

6472
apply_edits(&mut buffer, &edits);
6573

@@ -91,9 +99,9 @@ mod tests {
9199
/// ```lean
92100
/// theorem foo : True := by trivial
93101
/// ```
94-
fn foo()
102+
fn foo() {
95103
96-
104+
}
97105
";
98106
assert_eq!(std::str::from_utf8(&buffer).unwrap(), expected);
99107
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[[command]]
2-
# Expected: crate::<*constFooasT1>::m1, crate::<[Foo;5]asT3>::m3, crate::<[Foo]asT2>::m2
3-
args = ["--start-from", "crate::<*constFooasT1>::m1,crate::<[Foo;5]asT3>::m3,crate::<[Foo]asT2>::m2"]
2+
args = ["--start-from", "crate::< * const Foo as T1 >::m1,crate::< [Foo ; 5] as T3 >::m3,crate::< [Foo] as T2 >::m2"]
43
should_not_exist = false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
failure
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
fn windows() {}
2+
3+
/// ```lean
4+
/// ```
5+
fn _hermes_dummy() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
fn windows() {}
2+
3+
/// ```lean
4+
/// ```
5+
fn _hermes_dummy() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#[path = "sys/unix.rs"]
22
mod sys;
33

4+
5+
/// ```lean
6+
/// ```
7+
fn _hermes_dummy() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
pub mod nested;
22

3+
4+
/// ```lean
5+
/// ```
6+
fn _hermes_dummy() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
mod bar;
22

3+
4+
/// ```lean
5+
/// ```
6+
fn _hermes_dummy() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
fn clean() {}
22

3+
4+
/// ```lean
5+
/// ```
6+
fn _hermes_dummy() {}

0 commit comments

Comments
 (0)