Skip to content

Commit 0d8675d

Browse files
authored
Remove support for the unstable argument --function (rust-lang#3278)
This is a legacy argument that we have very limited support to. We kept it around for bookrunner tests, which has been removed already. Resolves rust-lang#2129
1 parent 12ff35f commit 0d8675d

File tree

28 files changed

+93
-292
lines changed

28 files changed

+93
-292
lines changed

kani-compiler/src/codegen_cprover_gotoc/codegen/contract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'tcx> GotocCtx<'tcx> {
9595
vec![]
9696
});
9797
self.attach_modifies_contract(instance_of_check, assigns_contract);
98-
let wrapper_name = self.symbol_name_stable(instance_of_check);
98+
let wrapper_name = instance_of_check.mangled_name();
9999

100100
AssignsContract {
101101
recursion_tracker: full_recursion_tracker_name,

kani-compiler/src/codegen_cprover_gotoc/codegen/foreign_function.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'tcx> GotocCtx<'tcx> {
4949
/// handled later.
5050
pub fn codegen_foreign_fn(&mut self, instance: Instance) -> &Symbol {
5151
debug!(?instance, "codegen_foreign_function");
52-
let fn_name = self.symbol_name_stable(instance).intern();
52+
let fn_name = instance.mangled_name().intern();
5353
let loc = self.codegen_span_stable(instance.def.span());
5454
if self.symbol_table.contains(fn_name) {
5555
// Symbol has been added (either a built-in CBMC function or a Rust allocation function).
@@ -134,7 +134,7 @@ impl<'tcx> GotocCtx<'tcx> {
134134

135135
/// Generate type for the given foreign instance.
136136
fn codegen_ffi_type(&mut self, instance: Instance) -> Type {
137-
let fn_name = self.symbol_name_stable(instance);
137+
let fn_name = instance.mangled_name();
138138
let fn_abi = instance.fn_abi().unwrap();
139139
let loc = self.codegen_span_stable(instance.def.span());
140140
let params = fn_abi
@@ -166,7 +166,7 @@ impl<'tcx> GotocCtx<'tcx> {
166166
/// This will behave like `codegen_unimplemented_stmt` but print a message that includes
167167
/// the name of the function not supported and the calling convention.
168168
fn codegen_ffi_unsupported(&mut self, instance: Instance, loc: Location) -> Stmt {
169-
let fn_name = &self.symbol_name_stable(instance);
169+
let fn_name = &instance.mangled_name();
170170
debug!(?fn_name, ?loc, "codegen_ffi_unsupported");
171171

172172
// Save this occurrence so we can emit a warning in the compilation report.

kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'tcx> GotocCtx<'tcx> {
5252
}
5353

5454
pub fn codegen_function(&mut self, instance: Instance) {
55-
let name = self.symbol_name_stable(instance);
55+
let name = instance.mangled_name();
5656
let old_sym = self.symbol_table.lookup(&name).unwrap();
5757

5858
let _trace_span = debug_span!("CodegenFunction", name = instance.name()).entered();
@@ -204,7 +204,7 @@ impl<'tcx> GotocCtx<'tcx> {
204204
let body = self.transformer.body(self.tcx, instance);
205205
self.set_current_fn(instance, &body);
206206
debug!(krate=?instance.def.krate(), is_std=self.current_fn().is_std(), "declare_function");
207-
self.ensure(self.symbol_name_stable(instance), |ctx, fname| {
207+
self.ensure(instance.mangled_name(), |ctx, fname| {
208208
Symbol::function(
209209
fname,
210210
ctx.fn_typ(instance, &body),

kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl<'tcx> GotocCtx<'tcx> {
628628
} else {
629629
// All non-foreign functions should've been declared beforehand.
630630
trace!(func=?instance, "codegen_func_symbol");
631-
let func = self.symbol_name_stable(instance);
631+
let func = instance.mangled_name();
632632
self.symbol_table
633633
.lookup(&func)
634634
.unwrap_or_else(|| panic!("Function `{func}` should've been declared before usage"))

kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ impl<'tcx> GotocCtx<'tcx> {
12991299
debug!(?vtable_field_name, ?vtable_type, "codegen_vtable_method_field");
13001300

13011301
// Lookup in the symbol table using the full symbol table name/key
1302-
let fn_name = self.symbol_name_stable(instance);
1302+
let fn_name = instance.mangled_name();
13031303

13041304
if let Some(fn_symbol) = self.symbol_table.lookup(&fn_name) {
13051305
if self.vtable_ctx.emit_vtable_restrictions {

kani-compiler/src/codegen_cprover_gotoc/codegen/ty_stable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'tcx> GotocCtx<'tcx> {
4444
}
4545

4646
pub fn codegen_fndef_type_stable(&mut self, instance: Instance) -> Type {
47-
let func = self.symbol_name_stable(instance);
47+
let func = instance.mangled_name();
4848
self.ensure_struct(
4949
format!("{func}::FnDefStruct"),
5050
format!("{}::FnDefStruct", instance.name()),

kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl GotocCodegenBackend {
133133
format!(
134134
"codegen_function: {}\n{}",
135135
instance.name(),
136-
gcx.symbol_name_stable(instance)
136+
instance.mangled_name()
137137
),
138138
instance.def,
139139
);

kani-compiler/src/codegen_cprover_gotoc/context/current_fn.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ impl<'tcx> CurrentFnCtx<'tcx> {
3939
pub fn new(instance: Instance, gcx: &GotocCtx<'tcx>, body: &Body) -> Self {
4040
let instance_internal = rustc_internal::internal(gcx.tcx, instance);
4141
let readable_name = instance.name();
42-
let name =
43-
if &readable_name == "main" { readable_name.clone() } else { instance.mangled_name() };
42+
let name = instance.mangled_name();
4443
let locals = body.locals().to_vec();
4544
let local_names = body
4645
.var_debug_info

kani-compiler/src/codegen_cprover_gotoc/utils/names.rs

-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use cbmc::InternedString;
88
use rustc_hir::def_id::LOCAL_CRATE;
99
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
1010
use rustc_middle::ty::TyCtxt;
11-
use stable_mir::mir::mono::Instance;
1211
use stable_mir::mir::Local;
1312

1413
impl<'tcx> GotocCtx<'tcx> {
@@ -50,15 +49,6 @@ impl<'tcx> GotocCtx<'tcx> {
5049
format!("{var_name}_init")
5150
}
5251

53-
/// Return the mangled name to be used in the symbol table.
54-
///
55-
/// We special case main function in order to support `--function main`.
56-
// TODO: Get rid of this: https://github.com/model-checking/kani/issues/2129
57-
pub fn symbol_name_stable(&self, instance: Instance) -> String {
58-
let pretty = instance.name();
59-
if pretty == "main" { pretty } else { instance.mangled_name() }
60-
}
61-
6252
/// The name for a tuple field
6353
pub fn tuple_fld_name(n: usize) -> String {
6454
format!("{n}")

kani-compiler/src/kani_middle/metadata.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,12 @@ use stable_mir::CrateDef;
1313

1414
use super::{attributes::KaniAttributes, SourceLocation};
1515

16-
pub fn canonical_mangled_name(instance: Instance) -> String {
17-
let pretty_name = instance.name();
18-
// Main function a special case in order to support `--function main`
19-
// TODO: Get rid of this: https://github.com/model-checking/kani/issues/2129
20-
if pretty_name == "main" { pretty_name } else { instance.mangled_name() }
21-
}
22-
2316
/// Create the harness metadata for a proof harness for a given function.
2417
pub fn gen_proof_metadata(tcx: TyCtxt, instance: Instance, base_name: &Path) -> HarnessMetadata {
2518
let def = instance.def;
2619
let kani_attributes = KaniAttributes::for_instance(tcx, instance);
2720
let pretty_name = instance.name();
28-
let mangled_name = canonical_mangled_name(instance);
21+
let mangled_name = instance.mangled_name();
2922

3023
// We get the body span to include the entire function definition.
3124
// This is required for concrete playback to properly position the generated test.

kani-driver/src/args/mod.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ pub struct VerificationArgs {
150150

151151
/// Generate C file equivalent to inputted program.
152152
/// This feature is unstable and it requires `--enable-unstable` to be used
153-
#[arg(long, hide_short_help = true, requires("enable_unstable"),
154-
conflicts_with_all(&["function"]))]
153+
#[arg(long, hide_short_help = true, requires("enable_unstable"))]
155154
pub gen_c: bool,
156155

157156
/// Directory for all generated artifacts.
@@ -169,19 +168,10 @@ pub struct VerificationArgs {
169168
#[command(flatten)]
170169
pub checks: CheckArgs,
171170

172-
/// Entry point for verification (symbol name).
173-
/// This is an unstable feature. Consider using --harness instead
174-
#[arg(long, hide = true, requires("enable_unstable"))]
175-
pub function: Option<String>,
176171
/// If specified, only run harnesses that match this filter. This option can be provided
177172
/// multiple times, which will run all tests matching any of the filters.
178173
/// If used with --exact, the harness filter will only match the exact fully qualified name of a harness.
179-
#[arg(
180-
long = "harness",
181-
conflicts_with = "function",
182-
num_args(1),
183-
value_name = "HARNESS_FILTER"
184-
)]
174+
#[arg(long = "harness", num_args(1), value_name = "HARNESS_FILTER")]
185175
pub harnesses: Vec<String>,
186176

187177
/// When specified, the harness filter will only match the exact fully qualified name of a harness
@@ -569,7 +559,7 @@ impl ValidateArgs for VerificationArgs {
569559
if self.cbmc_args.contains(&OsString::from("--function")) {
570560
return Err(Error::raw(
571561
ErrorKind::ArgumentConflict,
572-
"Invalid flag: --function should be provided to Kani directly, not via --cbmc-args.",
562+
"Invalid flag: --function is not supported in Kani.",
573563
));
574564
}
575565
if self.common_args.quiet && self.concrete_playback == Some(ConcretePlaybackMode::Print) {

kani-driver/src/assess/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ fn assess_project(mut session: KaniSession) -> Result<AssessMetadata> {
5656
let project = project::cargo_project(&session, true)?;
5757
let cargo_metadata = project.cargo_metadata.as_ref().expect("built with cargo");
5858

59-
let packages_metadata = if project.merged_artifacts {
60-
// With the legacy linker we can't expect to find the metadata structure we'd expect
61-
// so we just use it as-is. This does mean the "package count" will be wrong, but
62-
// we will at least continue to see everything.
63-
project.metadata.clone()
64-
} else {
65-
reconstruct_metadata_structure(&session, cargo_metadata, &project.metadata)?
66-
};
59+
let packages_metadata =
60+
reconstruct_metadata_structure(&session, cargo_metadata, &project.metadata)?;
6761

6862
// We don't really have a list of crates that went into building our various targets,
6963
// so we can't easily count them.

kani-driver/src/call_cbmc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub fn resolve_unwind_value(
402402
#[cfg(test)]
403403
mod tests {
404404
use crate::args;
405-
use crate::metadata::mock_proof_harness;
405+
use crate::metadata::tests::mock_proof_harness;
406406
use clap::Parser;
407407

408408
use super::*;

kani-driver/src/call_single_file.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,10 @@ impl KaniSession {
7070
rustc_args.push(t);
7171
}
7272
} else {
73-
// If we specifically request "--function main" then don't override crate type
74-
if Some("main".to_string()) != self.args.function {
75-
// We only run against proof harnesses normally, and this change
76-
// 1. Means we do not require a `fn main` to exist
77-
// 2. Don't forget it also changes visibility rules.
78-
rustc_args.push("--crate-type".into());
79-
rustc_args.push("lib".into());
80-
}
73+
// We only run against proof harnesses, so always compile as a library.
74+
// This ensures compilation passes if the crate does not have a `main` function.
75+
rustc_args.push("--crate-type".into());
76+
rustc_args.push("lib".into());
8177
}
8278

8379
// Note that the order of arguments is important. Kani specific flags should precede

kani-driver/src/harness_runner.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::args::OutputFormat;
1010
use crate::call_cbmc::{VerificationResult, VerificationStatus};
1111
use crate::project::Project;
1212
use crate::session::KaniSession;
13-
use crate::util::error;
1413

1514
/// A HarnessRunner is responsible for checking all proof harnesses. The data in this structure represents
1615
/// "background information" that the controlling driver (e.g. cargo-kani or kani) computed.
@@ -173,26 +172,22 @@ impl KaniSession {
173172
"Complete - {succeeding} successfully verified harnesses, {failing} failures, {total} total."
174173
);
175174
} else {
176-
match (self.args.harnesses.as_slice(), &self.args.function) {
177-
([], None) =>
175+
match self.args.harnesses.as_slice() {
176+
[] =>
178177
// TODO: This could use a better message, possibly with links to Kani documentation.
179178
// New users may encounter this and could use a pointer to how to write proof harnesses.
180179
{
181180
println!(
182181
"No proof harnesses (functions with #[kani::proof]) were found to verify."
183182
)
184183
}
185-
([harness], None) => {
184+
[harness] => {
186185
bail!("no harnesses matched the harness filter: `{harness}`")
187186
}
188-
(harnesses, None) => bail!(
187+
harnesses => bail!(
189188
"no harnesses matched the harness filters: `{}`",
190189
harnesses.join("`, `")
191190
),
192-
([], Some(func)) => error(&format!("No function named {func} was found")),
193-
_ => unreachable!(
194-
"invalid configuration. Cannot specify harness and function at the same time"
195-
),
196191
};
197192
}
198193
}

kani-driver/src/metadata.rs

+25-29
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
use anyhow::{bail, Result};
5-
use std::path::{Path, PathBuf};
5+
use std::path::Path;
66
use tracing::{debug, trace};
77

88
use kani_metadata::{
9-
HarnessAttributes, HarnessMetadata, InternedString, KaniMetadata, TraitDefinedMethod,
10-
VtableCtxResults,
9+
HarnessMetadata, InternedString, KaniMetadata, TraitDefinedMethod, VtableCtxResults,
1110
};
1211
use std::collections::{BTreeSet, HashMap};
1312
use std::fs::File;
@@ -115,12 +114,7 @@ impl KaniSession {
115114
&self,
116115
all_harnesses: &[&'a HarnessMetadata],
117116
) -> Result<Vec<&'a HarnessMetadata>> {
118-
let harnesses = if self.args.harnesses.is_empty() {
119-
BTreeSet::from_iter(self.args.function.iter())
120-
} else {
121-
BTreeSet::from_iter(self.args.harnesses.iter())
122-
};
123-
117+
let harnesses = BTreeSet::from_iter(self.args.harnesses.iter());
124118
let total_harnesses = harnesses.len();
125119
let all_targets = &harnesses;
126120

@@ -169,25 +163,6 @@ pub fn sort_harnesses_by_loc<'a>(harnesses: &[&'a HarnessMetadata]) -> Vec<&'a H
169163
harnesses_clone
170164
}
171165

172-
pub fn mock_proof_harness(
173-
name: &str,
174-
unwind_value: Option<u32>,
175-
krate: Option<&str>,
176-
model_file: Option<PathBuf>,
177-
) -> HarnessMetadata {
178-
HarnessMetadata {
179-
pretty_name: name.into(),
180-
mangled_name: name.into(),
181-
crate_name: krate.unwrap_or("<unknown>").into(),
182-
original_file: "<unknown>".into(),
183-
original_start_line: 0,
184-
original_end_line: 0,
185-
attributes: HarnessAttributes { unwind_value, proof: true, ..Default::default() },
186-
goto_file: model_file,
187-
contract: Default::default(),
188-
}
189-
}
190-
191166
/// Search for a proof harness with a particular name.
192167
/// At the present time, we use `no_mangle` so collisions shouldn't happen,
193168
/// but this function is written to be robust against that changing in the future.
@@ -223,8 +198,29 @@ fn find_proof_harnesses<'a>(
223198
}
224199

225200
#[cfg(test)]
226-
mod tests {
201+
pub mod tests {
227202
use super::*;
203+
use kani_metadata::HarnessAttributes;
204+
use std::path::PathBuf;
205+
206+
pub fn mock_proof_harness(
207+
name: &str,
208+
unwind_value: Option<u32>,
209+
krate: Option<&str>,
210+
model_file: Option<PathBuf>,
211+
) -> HarnessMetadata {
212+
HarnessMetadata {
213+
pretty_name: name.into(),
214+
mangled_name: name.into(),
215+
crate_name: krate.unwrap_or("<unknown>").into(),
216+
original_file: "<unknown>".into(),
217+
original_start_line: 0,
218+
original_end_line: 0,
219+
attributes: HarnessAttributes { unwind_value, proof: true, ..Default::default() },
220+
goto_file: model_file,
221+
contract: Default::default(),
222+
}
223+
}
228224

229225
#[test]
230226
fn check_find_proof_harness_without_exact() {

0 commit comments

Comments
 (0)