Skip to content

Commit 7bd38d6

Browse files
authored
Merge pull request #1577 from N1ark/simd
Translate `repr(simd)`
2 parents 437c3f9 + 8ba28c2 commit 7bd38d6

12 files changed

Lines changed: 46 additions & 14 deletions

File tree

‎charon-ml/src/CharonVersion.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(* This is an automatically generated file, generated from `charon/Cargo.toml`. *)
22
(* To re-generate this file, rune `make` in the root directory *)
3-
let supported_charon_version = "0.1.301"
3+
let supported_charon_version = "0.1.302"

‎charon-ml/src/generated/Generated_OfJson.ml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3892,6 +3892,7 @@ and repr_algorithm_of_json (ctx : of_json_ctx) (js : json) :
38923892
(match js with
38933893
| `String "Rust" -> Ok Rust
38943894
| `String "C" -> Ok C
3895+
| `String "Simd" -> Ok Simd
38953896
| _ -> Error "")
38963897

38973898
and repr_options_of_json (ctx : of_json_ctx) (js : json) :

‎charon-ml/src/generated/Generated_OfPostcard.ml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,6 +3263,7 @@ and repr_algorithm_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
32633263
match __tag with
32643264
| 0 -> Ok Rust
32653265
| 1 -> Ok C
3266+
| 2 -> Ok Simd
32663267
| _ -> Error ("unknown enum variant tag: " ^ string_of_int __tag))
32673268

32683269
and repr_options_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :

‎charon-ml/src/generated/Generated_Types.ml‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,13 +1502,15 @@ and repr_algorithm =
15021502
(** The default layout algorithm. Used without an explicit [ŗepr] or for
15031503
[repr(Rust)]. *)
15041504
| C (** The C layout algorithm as enforced by [repr(C)]. *)
1505+
| Simd
1506+
(** The SIMD vector layout algorithm as enforced by the unstable
1507+
[repr(simd)]. *)
15051508

15061509
(** The representation options as annotated by the user.
15071510
1508-
NOTE: This does not include less common/unstable representations such as
1509-
[#[repr(simd)]] or the compiler internal [#[repr(linear)]]. Similarly, enum
1510-
discriminant representations are encoded in [[Variant::discriminant]] and
1511-
[[Discriminator]] instead. *)
1511+
NOTE: This does not include the compiler internal [#[repr(linear)]].
1512+
Similarly, enum discriminant representations are encoded in
1513+
[[Variant::discriminant]] and [[Discriminator]] instead. *)
15121514
and repr_options = {
15131515
repr_algo : repr_algorithm;
15141516
align_modif : alignment_modifier option;

‎charon/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎charon/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tracing = { version = "0.1", features = ["max_level_trace"] }
2828

2929
[package]
3030
name = "charon"
31-
version = "0.1.301"
31+
version = "0.1.302"
3232
authors.workspace = true
3333
edition.workspace = true
3434
license.workspace = true

‎charon/src/ast/items/layout.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ impl std::ops::Deref for InhabitedPredicate {
455455

456456
/// The representation options as annotated by the user.
457457
///
458-
/// NOTE: This does not include less common/unstable representations such as `#[repr(simd)]`
459-
/// or the compiler internal `#[repr(linear)]`. Similarly, enum discriminant representations
460-
/// are encoded in [`Variant::discriminant`] and [`Discriminator`] instead.
458+
/// NOTE: This does not include the compiler internal `#[repr(linear)]`. Similarly, enum
459+
/// discriminant representations are encoded in [`Variant::discriminant`] and [`Discriminator`]
460+
/// instead.
461461
#[derive(Debug, Default, Clone, PartialEq, Eq)]
462462
#[derive(Serialize, Deserialize)]
463463
pub struct ReprOptions {
@@ -478,6 +478,8 @@ pub enum ReprAlgorithm {
478478
Rust,
479479
/// The C layout algorithm as enforced by `repr(C)`.
480480
C,
481+
/// The SIMD vector layout algorithm as enforced by the unstable `repr(simd)`.
482+
Simd,
481483
}
482484

483485
/// Describes modifiers to the alignment and packing of the corresponding type.
@@ -563,9 +565,9 @@ impl ReprOptions {
563565
/// Whether this representation options guarantee a fixed
564566
/// field ordering for the type.
565567
///
566-
/// Since we don't support `repr(simd)` or `repr(linear)` yet, this is
567-
/// the case if it's either `repr(C)` or an explicit discriminant type for
568-
/// an enum with fields (if it doesn't have fields, this obviously doesn't matter anyway).
568+
/// Since we don't support `repr(linear)` yet, this is the case if it's either `repr(C)` or an
569+
/// explicit discriminant type for an enum with fields (if it doesn't have fields, this
570+
/// obviously doesn't matter anyway).
569571
///
570572
/// Cf. <https://doc.rust-lang.org/reference/type-layout.html#r-layout.repr.c.struct>
571573
/// and <https://doc.rust-lang.org/reference/type-layout.html#r-layout.repr.primitive.adt>.

‎charon/src/bin/charon-driver/translate/translate_types.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,9 @@ impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx> {
13291329
}
13301330

13311331
pub fn translate_repr_options(&mut self, hax_repr_options: &hax::ReprOptions) -> ReprOptions {
1332-
let repr_algo = if hax_repr_options.flags.is_c {
1332+
let repr_algo = if hax_repr_options.flags.is_simd {
1333+
ReprAlgorithm::Simd
1334+
} else if hax_repr_options.flags.is_c {
13331335
ReprAlgorithm::C
13341336
} else {
13351337
ReprAlgorithm::Rust

‎charon/src/pretty/fmt_with_ctx.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,7 @@ impl Display for ReprOptions {
21082108
let algorithm = match self.repr_algo {
21092109
ReprAlgorithm::Rust => "Rust",
21102110
ReprAlgorithm::C => "C",
2111+
ReprAlgorithm::Simd => "simd",
21112112
};
21122113
write!(f, "repr({algorithm}")?;
21132114
if let Some(modifier) = &self.align_modif {

‎charon/src/transform/add_missing_info/compute_layout_guarantees.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ fn compute_guarantees(
161161
// `repr(int)`: each variant is its own struct `(tag, fields..)`, so
162162
// the first field is aligned to itself.
163163
ReprAlgorithm::Rust => OffsetGuarantee::ReprCField(FieldPredecessor::Tag),
164+
ReprAlgorithm::Simd => unreachable!("repr(simd) on an enum"),
164165
});
165166

166167
let align = type_align(tag_align.into_iter().chain(field_aligns).collect());

0 commit comments

Comments
 (0)