-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacl2s.rs
More file actions
181 lines (161 loc) · 5.97 KB
/
Copy pathacl2s.rs
File metadata and controls
181 lines (161 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
//! ACL2s — sibling dialect to ACL2 with richer type annotations and
//! "session" extensions (Northeastern). Same Common-Lisp foundation
//! and same proof theory, but different binary, different default
//! libraries, and different user base. Kept as its own `ProverKind`
//! because the corpus grows separately and the default tactic
//! distributions diverge enough that an ML policy trained on ACL2
//! proofs alone won't be optimal for ACL2s and vice versa.
#![allow(dead_code)]
use anyhow::{anyhow, Context as AnyhowContext, Result};
use async_trait::async_trait;
use std::path::PathBuf;
use std::process::Stdio;
use tokio::process::Command;
use super::{ProverBackend, ProverConfig, ProverKind};
use crate::core::{Context as ProofContext, Goal, ProofState, Tactic, TacticResult, Term};
pub struct Acl2sBackend {
config: ProverConfig,
}
impl Acl2sBackend {
pub fn new(config: ProverConfig) -> Self {
Acl2sBackend { config }
}
fn binary(&self) -> PathBuf {
if self.config.executable.as_os_str().is_empty() {
PathBuf::from("acl2s")
} else {
self.config.executable.clone()
}
}
}
#[async_trait]
impl ProverBackend for Acl2sBackend {
fn kind(&self) -> ProverKind {
ProverKind::ACL2s
}
async fn version(&self) -> Result<String> {
let output = Command::new(self.binary()).arg("--version").output().await;
match output {
Ok(out) if out.status.success() => {
Ok(String::from_utf8_lossy(&out.stdout).trim().to_string())
},
Ok(_) => Ok("acl2s@unavailable".to_string()),
Err(_) => Ok("acl2s@not-installed".to_string()),
}
}
async fn parse_file(&self, path: PathBuf) -> Result<ProofState> {
let content = super::bounded_read_proof_file(&path)
.await
.with_context(|| format!("ACL2s: reading {}", path.display()))?;
self.parse_string(&content).await
}
async fn parse_string(&self, content: &str) -> Result<ProofState> {
let mut state = ProofState {
goals: vec![Goal {
id: "acl2s-file".to_string(),
target: Term::Const(content.to_string()),
hypotheses: vec![],
}],
context: ProofContext::default(),
proof_script: vec![],
metadata: Default::default(),
};
state.metadata.insert(
"acl2s_source".to_string(),
serde_json::Value::String(content.to_string()),
);
Ok(state)
}
async fn apply_tactic(&self, state: &ProofState, tactic: &Tactic) -> Result<TacticResult> {
let mut new_state = state.clone();
new_state.proof_script.push(tactic.clone());
Ok(TacticResult::Success(new_state))
}
async fn verify_proof(&self, state: &ProofState) -> Result<bool> {
let source: String = state
.metadata
.get("acl2s_source")
.and_then(|v| v.as_str())
.map(ToOwned::to_owned)
.unwrap_or_default();
let tmp_dir = tempfile::Builder::new()
.prefix("echidna-acl2s-")
.tempdir()
.context("ACL2s: tempdir")?;
let input = tmp_dir.path().join("check.lisp");
tokio::fs::write(&input, source.as_bytes())
.await
.context("ACL2s: writing input")?;
let mut cmd = Command::new(self.binary());
cmd.arg("-f")
.arg(&input)
.stdout(Stdio::piped())
.stderr(Stdio::piped());
for arg in &self.config.args {
cmd.arg(arg);
}
match cmd.output().await {
Ok(out) if out.status.success() => Ok(true),
Ok(_) => Ok(false),
Err(e) => Err(anyhow!("ACL2s: binary not runnable: {}", e)),
}
}
async fn export(&self, state: &ProofState) -> Result<String> {
Ok(state
.metadata
.get("acl2s_source")
.and_then(|v| v.as_str())
.map(ToOwned::to_owned)
.unwrap_or_default())
}
async fn suggest_tactics(&self, state: &ProofState, limit: usize) -> Result<Vec<Tactic>> {
// ACL2s (ACL2 Sedan) is a pedagogical IDE for ACL2. Its proof strategy
// hints are ACL2 :hints keyword arguments and defthm patterns.
let tactics = vec![
Tactic::Custom {
prover: "acl2s".to_string(),
command: "hint".to_string(),
args: vec![":hints ((\"Goal\" :induct t))".to_string()],
},
Tactic::Custom {
prover: "acl2s".to_string(),
command: "hint".to_string(),
args: vec![":hints ((\"Goal\" :in-theory (enable ...)))".to_string()],
},
Tactic::Custom {
prover: "acl2s".to_string(),
command: "hint".to_string(),
args: vec![":hints ((\"Goal\" :use (:instance lemma ...)))".to_string()],
},
Tactic::Custom {
prover: "acl2s".to_string(),
command: "prove".to_string(),
args: vec![],
},
Tactic::Simplify,
];
Ok(crate::provers::gnn_augment_tactics(&self.config, state, "acl2s", tactics, limit).await)
}
async fn search_theorems(&self, _pattern: &str) -> Result<Vec<String>> {
// ACL2s theorem search requires a running ACL2 session with the
// appropriate libraries loaded; return empty as fallback.
Ok(vec![])
}
fn config(&self) -> &ProverConfig {
&self.config
}
fn set_config(&mut self, config: ProverConfig) {
self.config = config;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn kind_is_acl2s() {
let backend = Acl2sBackend::new(ProverConfig::default());
assert_eq!(backend.kind(), ProverKind::ACL2s);
}
}