Skip to content

Commit 4fd5cf6

Browse files
authored
Merge pull request #597 from Nadrieril/update-hax
Update hax
2 parents 1e6b9e5 + 5a24362 commit 4fd5cf6

File tree

7 files changed

+44
-31
lines changed

7 files changed

+44
-31
lines changed

charon/Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charon/src/bin/charon-driver/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![expect(incomplete_features)]
55
#![feature(box_patterns)]
66
#![feature(deref_patterns)]
7+
#![feature(if_let_guard)]
78
#![feature(iter_array_chunks)]
89
#![feature(iterator_try_collect)]
910
#![feature(let_chains)]

charon/src/bin/charon-driver/translate/translate_constants.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ use hax_frontend_exporter as hax;
66
impl<'tcx, 'ctx> BodyTransCtx<'tcx, 'ctx> {
77
fn translate_constant_literal_to_raw_constant_expr(
88
&mut self,
9+
span: Span,
910
v: &hax::ConstantLiteral,
1011
) -> Result<RawConstantExpr, Error> {
1112
let lit = match v {
1213
hax::ConstantLiteral::ByteStr(bs) => Literal::ByteStr(bs.clone()),
13-
hax::ConstantLiteral::Str(s) => Literal::Str(s.clone()),
14+
hax::ConstantLiteral::Str(..) => {
15+
// This should have been handled in the `&str` case. If we get here, there's a
16+
// `str` value not behind a reference.
17+
raise_error!(self, span, "found a `str` constants not behind a reference")
18+
}
1419
hax::ConstantLiteral::Char(c) => Literal::Char(*c),
1520
hax::ConstantLiteral::Bool(b) => Literal::Bool(*b),
1621
hax::ConstantLiteral::Int(i) => {
@@ -66,15 +71,14 @@ impl<'tcx, 'ctx> BodyTransCtx<'tcx, 'ctx> {
6671
v: &hax::ConstantExpr,
6772
) -> Result<ConstantExpr, Error> {
6873
use hax::ConstantExprKind;
69-
let ty = &v.ty;
74+
let ty = self.translate_ty(span, &v.ty)?;
7075
let value = match v.contents.as_ref() {
7176
ConstantExprKind::Literal(lit) => {
72-
self.translate_constant_literal_to_raw_constant_expr(lit)?
77+
self.translate_constant_literal_to_raw_constant_expr(span, lit)?
7378
}
7479
ConstantExprKind::Adt { info, fields } => {
7580
let fields: Vec<ConstantExpr> = fields
7681
.iter()
77-
// TODO: the user_ty is not always None
7882
.map(|f| self.translate_constant_expr_to_constant_expr(span, &f.value))
7983
.try_collect()?;
8084
use hax::VariantKind;
@@ -85,8 +89,25 @@ impl<'tcx, 'ctx> BodyTransCtx<'tcx, 'ctx> {
8589
};
8690
RawConstantExpr::Adt(vid, fields)
8791
}
88-
ConstantExprKind::Array { .. } => {
89-
raise_error!(self, span, "array constants are not supported yet")
92+
ConstantExprKind::Array { fields } => {
93+
let fields: Vec<ConstantExpr> = fields
94+
.iter()
95+
.map(|x| self.translate_constant_expr_to_constant_expr(span, x))
96+
.try_collect()?;
97+
if let TyKind::Adt(TypeId::Builtin(BuiltinTy::Array), args) = ty.kind()
98+
&& let TyKind::Literal(LiteralTy::Integer(IntegerTy::U8)) = args.types[0].kind()
99+
{
100+
RawConstantExpr::Literal(Literal::ByteStr(
101+
fields
102+
.iter()
103+
.map(|konst| konst.value.as_literal().unwrap())
104+
.map(|x| x.as_scalar().unwrap().as_u8().unwrap())
105+
.copied()
106+
.collect(),
107+
))
108+
} else {
109+
raise_error!(self, span, "array constants are not supported yet")
110+
}
90111
}
91112
ConstantExprKind::Tuple { fields } => {
92113
let fields: Vec<ConstantExpr> = fields
@@ -125,9 +146,15 @@ impl<'tcx, 'ctx> BodyTransCtx<'tcx, 'ctx> {
125146
generics,
126147
})
127148
}
128-
ConstantExprKind::Borrow(be) => {
129-
let be = self.translate_constant_expr_to_constant_expr(span, be)?;
130-
RawConstantExpr::Ref(Box::new(be))
149+
ConstantExprKind::Borrow(v)
150+
if let ConstantExprKind::Literal(hax::ConstantLiteral::Str(s)) =
151+
v.contents.as_ref() =>
152+
{
153+
RawConstantExpr::Literal(Literal::Str(s.clone()))
154+
}
155+
ConstantExprKind::Borrow(v) => {
156+
let val = self.translate_constant_expr_to_constant_expr(span, v)?;
157+
RawConstantExpr::Ref(Box::new(val))
131158
}
132159
ConstantExprKind::Cast { .. } => {
133160
raise_error!(
@@ -178,7 +205,6 @@ impl<'tcx, 'ctx> BodyTransCtx<'tcx, 'ctx> {
178205
}
179206
};
180207

181-
let ty = self.translate_ty(span, ty)?;
182208
Ok(ConstantExpr { value, ty })
183209
}
184210

charon/src/bin/charon-driver/translate/translate_functions_to_ullbc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<'tcx, 'ctx> BodyTransCtx<'tcx, 'ctx> {
432432
}
433433
hax::Operand::Constant(const_op) => {
434434
let constant =
435-
self.translate_constant_expr_to_constant_expr(span, &const_op.const_)?;
435+
self.translate_constant_expr_to_constant_expr(span, &const_op.evaluated)?;
436436
let ty = constant.ty.clone();
437437
Ok((Operand::Const(constant), ty))
438438
}

charon/tests/ui/simple/promoted-literal-addition.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn test_crate::two() -> &'static (u32)
88
let @3: u32; // anonymous local
99
let @4: &'_ (u32); // anonymous local
1010

11-
@3 := const (RawMemory([2, 0, 0, 0]))
11+
@3 := const (2 : u32)
1212
@4 := &@3
1313
@2 := move (@4)
1414
@1 := copy (@2)

charon/tests/ui/simple/ptr_to_promoted.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn test_crate::main()
1111
let @6: u8; // anonymous local
1212
let @7: &'_ (u8); // anonymous local
1313

14-
@6 := const (RawMemory([0]))
14+
@6 := const (0 : u8)
1515
@7 := &@6
1616
@5 := move (@7)
1717
@2 := copy (@5)

charon/tests/ui/unsupported/advanced-const-generics.out

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ error: Item `test_crate::foo` caused errors; ignoring.
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444
|
4545

46-
disabled backtrace
47-
warning[E9999]: Failed to compute associated type <T as std::marker::DiscriminantKind>::Discriminant
48-
--> /rustc/86d69c705a552236a622eee3fdea94bf13c5f102/library/core/src/intrinsics.rs:2556:5
49-
|
50-
= note: ⚠️ This is a bug in Hax's frontend.
51-
Please report this error to https://github.com/hacspec/hax/issues with some context (e.g. the current crate)!
52-
53-
disabled backtrace
54-
warning[E9999]: Failed to compute associated type <Self as std::marker::DiscriminantKind>::Discriminant
55-
--> /rustc/86d69c705a552236a622eee3fdea94bf13c5f102/library/core/src/marker.rs:823:5
56-
|
57-
= note: ⚠️ This is a bug in Hax's frontend.
58-
Please report this error to https://github.com/hacspec/hax/issues with some context (e.g. the current crate)!
59-
60-
error: aborting due to 1 previous error; 2 warnings emitted
46+
error: aborting due to 1 previous error
6147

6248
ERROR Code failed to compile

0 commit comments

Comments
 (0)