Skip to content

Commit 7bc353e

Browse files
committed
Redefine AIR span to hold file-related info. Still need to update the
many callsites.
1 parent 0226f83 commit 7bc353e

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

verify/air/src/ast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ pub struct Span {
77
pub description: Option<String>,
88
pub raw_span: RawSpan,
99
pub as_string: String, // if we can't print (description, raw_span), print as_string instead
10+
pub filename: String,
11+
pub start_row: u32,
12+
pub start_col: u32,
13+
pub end_row: u32,
14+
pub end_col: u32,
1015
}
1116
pub type SpanOption = Rc<Option<Span>>;
1217

verify/air/src/print_parse.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ pub(crate) fn node_to_expr(node: &Node) -> Result<Expr, String> {
512512
{
513513
let raw_span = Rc::new(());
514514
let as_string = label[1..label.len() - 1].to_string();
515-
let span = Rc::new(Some(Span { description: None, raw_span, as_string }));
515+
// TODO: Update AIR syntax to support file info
516+
let span = Rc::new(Some(Span { description: None, raw_span, as_string, filename:"".to_string(), start_row:0, start_col: 0, end_row: 0, end_col: 0 }));
516517
let expr = node_to_expr(e)?;
517518
return Ok(Rc::new(ExprX::LabeledAssertion(span, expr)));
518519
}
@@ -714,7 +715,8 @@ pub(crate) fn node_to_stmt(node: &Node) -> Result<Stmt, String> {
714715
{
715716
let raw_span = Rc::new(());
716717
let as_string = label[1..label.len() - 1].to_string();
717-
let span = Span { description: None, raw_span, as_string };
718+
// TODO: Update AIR syntax to support file info
719+
let span = Span { description: None, raw_span, as_string, filename:"".to_string(), start_row:0, start_col: 0, end_row: 0, end_col: 0 };
718720
let expr = node_to_expr(&e)?;
719721
Ok(Rc::new(StmtX::Assert(Rc::new(Some(span)), expr)))
720722
}

verify/rust_verify/src/util.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
use rustc_span::Span;
1+
use rustc_span::{FileName, Span};
2+
use rustc_span::source_map::SourceMap;
23
use std::rc::Rc;
4+
use crate::unsupported;
35
use vir::ast::{VirErr, VirErrX};
46
use vir::def::Spanned;
57

6-
pub(crate) fn spanned_new<X>(span: Span, x: X) -> Rc<Spanned<X>> {
8+
static mut SOURCE_MAP: Option<SourceMap> = None;
9+
10+
pub(crate) fn spanned_new<X>(map: &SourceMap, span: Span, x: X) -> Rc<Spanned<X>> {
711
let raw_span = Rc::new(span);
812
let as_string = format!("{:?}", span);
9-
Spanned::new(air::ast::Span { description: None, raw_span, as_string }, x)
13+
let filename: String = match map.span_to_filename(span) {
14+
FileName::Real(rfn) => rfn
15+
.local_path()
16+
.to_str()
17+
.expect("internal error: path is not a valid string")
18+
.to_string(),
19+
_ => unsupported!("non real filenames in verifier errors", span),
20+
};
21+
let (start, end) = map.is_valid_span(span).expect("internal error: invalid Span");
22+
Spanned::new(air::ast::Span { description: None, raw_span, as_string, filename, start_row:start.line, start_col:start.col.to_u32(), end_row:end.line, end_col:end.col.to_u32() }, x)
1023
}
1124

1225
pub(crate) fn err_span_str<A>(span: Span, msg: &str) -> Result<A, VirErr> {

0 commit comments

Comments
 (0)