Skip to content

Commit 24f18fb

Browse files
author
Remi Delmas
committed
Update toolchain to 2025-02-26
Changes to attribute parsing and representation rust-lang/rust#135726 Map methods moved to `TyCtx` rust-lang/rust#137162 rust-lang/rust#137397 Remove `BackendRepr::Unihabited` rust-lang/rust#136985
1 parent 366ce20 commit 24f18fb

File tree

9 files changed

+79
-57
lines changed

9 files changed

+79
-57
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ impl GotocCtx<'_> {
6363
// Return item tagged with `#[kanitool::recursion_tracker]`
6464
let mut recursion_trackers = items.iter().filter_map(|item| {
6565
let MonoItem::Static(static_item) = item else { return None };
66-
if !static_item
67-
.attrs_by_path(&["kanitool".into(), "recursion_tracker".into()])
68-
.is_empty()
66+
if !static_item.tool_attrs(&["kanitool".into(), "recursion_tracker".into()]).is_empty()
6967
{
7068
let span = static_item.span();
7169
let loc = self.codegen_span_stable(span);

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,10 @@ impl GotocCtx<'_> {
10021002
// https://github.com/rust-lang/rust/blob/fee75fbe11b1fad5d93c723234178b2a329a3c03/compiler/rustc_codegen_ssa/src/mir/place.rs#L247
10031003
// See also the cranelift backend:
10041004
// https://github.com/rust-lang/rust/blob/05d22212e89588e7c443cc6b9bc0e4e02fdfbc8d/compiler/rustc_codegen_cranelift/src/discriminant.rs#L116
1005-
let offset = match &layout.fields {
1006-
FieldsShape::Arbitrary { offsets, .. } => offsets[0usize.into()],
1005+
let offset: rustc_abi::Size = match &layout.fields {
1006+
FieldsShape::Arbitrary { offsets, .. } => {
1007+
offsets[rustc_abi::FieldIdx::from_usize(0)]
1008+
}
10071009
_ => unreachable!("niche encoding must have arbitrary fields"),
10081010
};
10091011

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::codegen_cprover_gotoc::codegen::function::rustc_smir::region_from_cov
77
use crate::codegen_cprover_gotoc::{GotocCtx, VtableCtx};
88
use crate::unwrap_or_return_codegen_unimplemented_stmt;
99
use cbmc::goto_program::{Expr, Location, Stmt, Type};
10+
use rustc_abi::Size;
1011
use rustc_abi::{FieldsShape, Primitive, TagEncoding, Variants};
1112
use rustc_middle::ty::layout::LayoutOf;
1213
use rustc_middle::ty::{List, TypingEnv};
@@ -350,8 +351,10 @@ impl GotocCtx<'_> {
350351
}
351352
TagEncoding::Niche { untagged_variant, niche_variants, niche_start } => {
352353
if *untagged_variant != variant_index_internal {
353-
let offset = match &layout.fields {
354-
FieldsShape::Arbitrary { offsets, .. } => offsets[0usize.into()],
354+
let offset: Size = match &layout.fields {
355+
FieldsShape::Arbitrary { offsets, .. } => {
356+
offsets[rustc_abi::FieldIdx::from_usize(0)]
357+
}
355358
_ => unreachable!("niche encoding must have arbitrary fields"),
356359
};
357360
let discr_ty = self.codegen_enum_discr_typ(dest_ty_internal);

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ impl<'tcx> GotocCtx<'tcx> {
718718
let mut final_fields = Vec::with_capacity(flds.len());
719719
let mut offset = initial_offset;
720720
for idx in layout.fields.index_by_increasing_offset() {
721-
let fld_offset = offsets[idx.into()];
721+
let fld_offset = offsets[rustc_abi::FieldIdx::from(idx)];
722722
let (fld_name, fld_ty) = &flds[idx];
723723
if let Some(padding) =
724724
self.codegen_struct_padding(offset, fld_offset, final_fields.len())
@@ -1557,9 +1557,9 @@ impl<'tcx> GotocCtx<'tcx> {
15571557
let components = fields_shape
15581558
.index_by_increasing_offset()
15591559
.map(|idx| {
1560-
let idx = idx.into();
1561-
let name = fields[idx].name.to_string().intern();
1562-
let field_ty = fields[idx].ty(ctx.tcx, adt_args);
1560+
let fidx = FieldIdx::from(idx);
1561+
let name = fields[fidx].name.to_string().intern();
1562+
let field_ty = fields[fidx].ty(ctx.tcx, adt_args);
15631563
let typ = if !ctx.is_zst(field_ty) {
15641564
last_type.clone()
15651565
} else {

kani-compiler/src/kani_middle/attributes.rs

+61-41
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use kani_metadata::{CbmcSolver, HarnessAttributes, HarnessKind, Stub};
88
use quote::ToTokens;
99
use rustc_ast::{LitKind, MetaItem, MetaItemKind, attr};
1010
use rustc_errors::ErrorGuaranteed;
11-
use rustc_hir::{AttrArgs, AttrKind, Attribute, def::DefKind, def_id::DefId};
11+
use rustc_hir::{AttrArgs, Attribute, def::DefKind, def_id::DefId};
1212
use rustc_middle::ty::{Instance, TyCtxt, TyKind};
1313
use rustc_session::Session;
1414
use rustc_smir::rustc_internal;
@@ -214,7 +214,7 @@ impl<'tcx> KaniAttributes<'tcx> {
214214
.resolve_from_mod(name.as_str())
215215
.map_err(|e| {
216216
let mut err = self.tcx.dcx().struct_span_err(
217-
attr.span,
217+
attr.span(),
218218
format!(
219219
"Failed to resolve replacement function {}: {e}",
220220
name.as_str()
@@ -229,7 +229,7 @@ impl<'tcx> KaniAttributes<'tcx> {
229229
err.emit();
230230
})
231231
.ok()?;
232-
Some((name, def, attr.span))
232+
Some((name, def, attr.span()))
233233
})
234234
.collect()
235235
}
@@ -247,10 +247,10 @@ impl<'tcx> KaniAttributes<'tcx> {
247247
self.expect_maybe_one(KaniAttributeKind::ProofForContract).and_then(|target| {
248248
let name = expect_key_string_value(self.tcx.sess, target).ok()?;
249249
self.resolve_from_mod(name.as_str())
250-
.map(|ok| (name, ok, target.span))
250+
.map(|ok| (name, ok, target.span()))
251251
.map_err(|resolve_err| {
252252
let mut err = self.tcx.dcx().struct_span_err(
253-
target.span,
253+
target.span(),
254254
format!(
255255
"Failed to resolve checking function {} because {resolve_err}",
256256
name.as_str()
@@ -336,7 +336,7 @@ impl<'tcx> KaniAttributes<'tcx> {
336336
// Check that all attributes are correctly used and well formed.
337337
let is_harness = self.is_proof_harness();
338338
for (&kind, attrs) in self.map.iter() {
339-
let local_error = |msg| self.tcx.dcx().span_err(attrs[0].span, msg);
339+
let local_error = |msg| self.tcx.dcx().span_err(attrs[0].span(), msg);
340340

341341
if !is_harness && kind.is_harness_only() {
342342
local_error(format!(
@@ -451,7 +451,7 @@ impl<'tcx> KaniAttributes<'tcx> {
451451
kind.as_ref()
452452
);
453453
if let Some(attr) = self.map.get(&kind).unwrap().first() {
454-
self.tcx.dcx().span_err(attr.span, msg);
454+
self.tcx.dcx().span_err(attr.span(), msg);
455455
} else {
456456
self.tcx.dcx().err(msg);
457457
}
@@ -646,7 +646,7 @@ impl<'tcx> KaniAttributes<'tcx> {
646646

647647
/// Check that if this item is tagged with a proof_attribute, it is a valid harness.
648648
fn check_proof_attribute(&self, kind: KaniAttributeKind, proof_attribute: &Attribute) {
649-
let span = proof_attribute.span;
649+
let span = proof_attribute.span();
650650
let tcx = self.tcx;
651651
if let KaniAttributeKind::Proof = kind {
652652
expect_no_args(tcx, kind, proof_attribute);
@@ -719,7 +719,7 @@ fn expect_key_string_value(
719719
sess: &Session,
720720
attr: &Attribute,
721721
) -> Result<rustc_span::Symbol, ErrorGuaranteed> {
722-
let span = attr.span;
722+
let span = attr.span();
723723
let AttrArgs::Eq { expr, .. } = &attr.get_normal_item().args else {
724724
return Err(sess
725725
.dcx()
@@ -743,7 +743,7 @@ fn expect_single<'a>(
743743
.expect(&format!("expected at least one attribute {} in {attributes:?}", kind.as_ref()));
744744
if attributes.len() > 1 {
745745
tcx.dcx().span_err(
746-
attr.span,
746+
attr.span(),
747747
format!("only one '#[kani::{}]' attribute is allowed per harness", kind.as_ref()),
748748
);
749749
}
@@ -774,7 +774,7 @@ impl UnstableAttrParseError<'_> {
774774
fn report(&self, tcx: TyCtxt) -> ErrorGuaranteed {
775775
tcx.dcx()
776776
.struct_span_err(
777-
self.attr.span,
777+
self.attr.span(),
778778
format!("failed to parse `#[kani::unstable_feature]`: {}", self.reason),
779779
)
780780
.with_note(format!(
@@ -817,7 +817,7 @@ impl<'a> TryFrom<&'a Attribute> for UnstableAttribute {
817817
fn expect_no_args(tcx: TyCtxt, kind: KaniAttributeKind, attr: &Attribute) {
818818
if !attr.is_word() {
819819
tcx.dcx()
820-
.struct_span_err(attr.span, format!("unexpected argument for `{}`", kind.as_ref()))
820+
.struct_span_err(attr.span(), format!("unexpected argument for `{}`", kind.as_ref()))
821821
.with_help("remove the extra argument")
822822
.emit();
823823
}
@@ -830,7 +830,7 @@ fn parse_unwind(tcx: TyCtxt, attr: &Attribute) -> Option<u32> {
830830
None => {
831831
// There are no integers or too many arguments given to the attribute
832832
tcx.dcx().span_err(
833-
attr.span,
833+
attr.span(),
834834
"invalid argument for `unwind` attribute, expected an integer",
835835
);
836836
None
@@ -839,7 +839,7 @@ fn parse_unwind(tcx: TyCtxt, attr: &Attribute) -> Option<u32> {
839839
if let Ok(val) = unwind_integer_value.try_into() {
840840
Some(val)
841841
} else {
842-
tcx.dcx().span_err(attr.span, "value above maximum permitted value - u32::MAX");
842+
tcx.dcx().span_err(attr.span(), "value above maximum permitted value - u32::MAX");
843843
None
844844
}
845845
}
@@ -854,13 +854,13 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
854854
Ok(FnResolution::Fn(_)) => { /* no-op */ }
855855
Ok(FnResolution::FnImpl { .. }) => {
856856
tcx.dcx().span_err(
857-
attr.span,
857+
attr.span(),
858858
"Kani currently does not support stubbing trait implementations.",
859859
);
860860
}
861861
Err(err) => {
862862
tcx.dcx().span_err(
863-
attr.span,
863+
attr.span(),
864864
format!("failed to resolve `{}`: {err}", pretty_type_path(path)),
865865
);
866866
}
@@ -871,7 +871,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
871871
.filter_map(|attr| {
872872
let paths = parse_paths(tcx, attr).unwrap_or_else(|_| {
873873
tcx.dcx().span_err(
874-
attr.span,
874+
attr.span(),
875875
format!(
876876
"attribute `kani::{}` takes two path arguments; found argument that is not a path",
877877
KaniAttributeKind::Stub.as_ref())
@@ -893,7 +893,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
893893
}
894894
_ => {
895895
tcx.dcx().span_err(
896-
attr.span,
896+
attr.span(),
897897
format!(
898898
"attribute `kani::stub` takes two path arguments; found {}",
899899
paths.len()
@@ -912,15 +912,15 @@ fn parse_solver(tcx: TyCtxt, attr: &Attribute) -> Option<CbmcSolver> {
912912
const ATTRIBUTE: &str = "#[kani::solver]";
913913
let invalid_arg_err = |attr: &Attribute| {
914914
tcx.dcx().span_err(
915-
attr.span,
915+
attr.span(),
916916
format!("invalid argument for `{ATTRIBUTE}` attribute, expected one of the supported solvers (e.g. `kissat`) or a SAT solver binary (e.g. `bin=\"<SAT_SOLVER_BINARY>\"`)"),
917917
)
918918
};
919919

920920
let attr_args = attr.meta_item_list().unwrap();
921921
if attr_args.len() != 1 {
922922
tcx.dcx().span_err(
923-
attr.span,
923+
attr.span(),
924924
format!(
925925
"the `{ATTRIBUTE}` attribute expects a single argument. Got {} arguments.",
926926
attr_args.len()
@@ -943,7 +943,7 @@ fn parse_solver(tcx: TyCtxt, attr: &Attribute) -> Option<CbmcSolver> {
943943
match solver {
944944
Ok(solver) => Some(solver),
945945
Err(_) => {
946-
tcx.dcx().span_err(attr.span, format!("unknown solver `{ident_str}`"));
946+
tcx.dcx().span_err(attr.span(), format!("unknown solver `{ident_str}`"));
947947
None
948948
}
949949
}
@@ -1016,27 +1016,47 @@ fn parse_str_value(attr: &Attribute) -> Option<String> {
10161016

10171017
/// If the attribute is named `kanitool::name`, this extracts `name`
10181018
fn attr_kind(tcx: TyCtxt, attr: &Attribute) -> Option<KaniAttributeKind> {
1019-
match &attr.kind {
1020-
AttrKind::Normal(normal) => {
1021-
let segments = &normal.path.segments;
1022-
if (!segments.is_empty()) && segments[0].as_str() == "kanitool" {
1023-
let ident_str = segments[1..]
1024-
.iter()
1025-
.map(|segment| segment.as_str())
1026-
.intersperse("::")
1027-
.collect::<String>();
1028-
KaniAttributeKind::try_from(ident_str.as_str())
1029-
.inspect_err(|&err| {
1030-
debug!(?err, "attr_kind_failed");
1031-
tcx.dcx().span_err(attr.span, format!("unknown attribute `{ident_str}`"));
1032-
})
1033-
.ok()
1034-
} else {
1035-
None
1036-
}
1019+
if let Attribute::Unparsed(normal) = attr {
1020+
let segments = &normal.path.segments;
1021+
if (!segments.is_empty()) && segments[0].as_str() == "kanitool" {
1022+
let ident_str = segments[1..]
1023+
.iter()
1024+
.map(|segment| segment.as_str())
1025+
.intersperse("::")
1026+
.collect::<String>();
1027+
KaniAttributeKind::try_from(ident_str.as_str())
1028+
.inspect_err(|&err| {
1029+
debug!(?err, "attr_kind_failed");
1030+
tcx.dcx().span_err(attr.span(), format!("unknown attribute `{ident_str}`"));
1031+
})
1032+
.ok()
1033+
} else {
1034+
None
10371035
}
1038-
_ => None,
1036+
} else {
1037+
None
10391038
}
1039+
// match &attr.kind {
1040+
// AttrKind::Normal(normal) => {
1041+
// let segments = &normal.path.segments;
1042+
// if (!segments.is_empty()) && segments[0].as_str() == "kanitool" {
1043+
// let ident_str = segments[1..]
1044+
// .iter()
1045+
// .map(|segment| segment.as_str())
1046+
// .intersperse("::")
1047+
// .collect::<String>();
1048+
// KaniAttributeKind::try_from(ident_str.as_str())
1049+
// .inspect_err(|&err| {
1050+
// debug!(?err, "attr_kind_failed");
1051+
// tcx.dcx().span_err(attr.span(), format!("unknown attribute `{ident_str}`"));
1052+
// })
1053+
// .ok()
1054+
// } else {
1055+
// None
1056+
// }
1057+
// }
1058+
// _ => None,
1059+
// }
10401060
}
10411061

10421062
/// Parse an attribute using `syn`.
@@ -1099,7 +1119,7 @@ fn pretty_type_path(path: &TypePath) -> String {
10991119
/// Retrieve the value of the `fn_marker` attribute for the given definition if it has one.
11001120
pub(crate) fn fn_marker<T: CrateDef>(def: T) -> Option<String> {
11011121
let fn_marker: [SymbolStable; 2] = ["kanitool".into(), "fn_marker".into()];
1102-
let marker = def.attrs_by_path(&fn_marker).pop()?;
1122+
let marker = def.tool_attrs(&fn_marker).pop()?;
11031123
let attribute = syn_attr_stable(&marker);
11041124
let meta_name = attribute.meta.require_name_value().unwrap_or_else(|_| {
11051125
panic!("Expected name value attribute for `kanitool::fn_marker`, but found: `{:?}`", marker)

kani-compiler/src/kani_middle/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn simd_len_and_type<'tcx>(tcx: TyCtxt<'tcx>, simd_ty: Ty<'tcx>) -> (Const<'tcx>
9393
ty::Adt(def, args) => {
9494
assert!(def.repr().simd(), "`simd_size_and_type` called on non-SIMD type");
9595
let variant = def.non_enum_variant();
96-
let f0_ty = variant.fields[0u32.into()].ty(tcx, args);
96+
let f0_ty = variant.fields[rustc_abi::FieldIdx::from_usize(0)].ty(tcx, args);
9797

9898
match f0_ty.kind() {
9999
ty::Array(elem_ty, len) => (*len, *elem_ty),

kani-compiler/src/kani_middle/resolve.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ fn resolve_prefix<'tcx>(
307307
(None, Some(segment)) if segment.ident == CRATE => {
308308
// Find the module at the root of the crate.
309309
let current_module_hir_id = tcx.local_def_id_to_hir_id(current_module);
310-
let crate_root = match tcx.hir().parent_iter(current_module_hir_id).last() {
310+
let crate_root = match tcx.hir_parent_iter(current_module_hir_id).last() {
311311
None => current_module,
312312
Some((hir_id, _)) => hir_id.owner.def_id,
313313
};
@@ -366,7 +366,7 @@ where
366366
I: Iterator<Item = &'a PathSegment>,
367367
{
368368
let current_module_hir_id = tcx.local_def_id_to_hir_id(current_module);
369-
let mut parents = tcx.hir().parent_iter(current_module_hir_id);
369+
let mut parents = tcx.hir_parent_iter(current_module_hir_id);
370370
let mut base_module = current_module;
371371
while segments.next_if(|segment| segment.ident == SUPER).is_some() {
372372
if let Some((parent, _)) = parents.next() {

kani-compiler/src/kani_middle/transform/check_values.rs

-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ impl ValidValueReq {
213213
}
214214
ValueAbi::Scalar(_)
215215
| ValueAbi::ScalarPair(_, _)
216-
| ValueAbi::Uninhabited
217216
| ValueAbi::Vector { .. }
218217
| ValueAbi::Aggregate { .. } => None,
219218
}

rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
[toolchain]
5-
channel = "nightly-2025-02-21"
5+
channel = "nightly-2025-02-26"
66
components = ["llvm-tools", "rustc-dev", "rust-src", "rustfmt"]

0 commit comments

Comments
 (0)