Skip to content

Commit

Permalink
Slice.length
Browse files Browse the repository at this point in the history
  • Loading branch information
SCHNEIDER Laurent committed Nov 29, 2024
1 parent 60d4c77 commit d90784e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions creusot/src/backend/program.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use self::ty::{concret_intty, concret_uintty, slice_create_qname};
use self::ty::{concret_intty, concret_uintty, slice_create_qname, slice_length_qname};

use crate::{
backend::{
Expand Down Expand Up @@ -337,7 +337,7 @@ impl<'tcx> RValue<'tcx> {
// right operand must be converted to integer
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => {
let r_ty = r.ty(lower.ctx.tcx, lower.locals);

// rust allows shifting by a value of any integer type
// so we need to import the prelude for the right operand
let prelude: PreludeModule = match r_ty.kind() {
Expand Down Expand Up @@ -492,7 +492,7 @@ impl<'tcx> RValue<'tcx> {
}
RValue::Len(pl) => {
let len_call =
Exp::qvar(QName::from_string("Slice.length")).app_to(pl.to_why(lower, istmts));
Exp::qvar(slice_length_qname()).app_to(pl.to_why(lower, istmts));
len_call
}
RValue::Array(fields) => {
Expand Down
9 changes: 9 additions & 0 deletions creusot/src/backend/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,13 @@ pub(crate) fn slice_set_qname() -> QName {
return QName::from_string("Slice32.set");
#[cfg(target_pointer_width = "16")]
return QName::from_string("Slice16.set");
}

pub(crate) fn slice_length_qname() -> QName {
#[cfg(target_pointer_width = "64")]
return QName::from_string("Slice64.length");
#[cfg(target_pointer_width = "32")]
return QName::from_string("Slice32.length");
#[cfg(target_pointer_width = "16")]
return QName::from_string("Slice16.length");
}

0 comments on commit d90784e

Please sign in to comment.