Skip to content

Commit 23c4f03

Browse files
committed
Improve union ergonomics.
1 parent 798adaa commit 23c4f03

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

opt/pulse

src/pass/emit.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -714,15 +714,17 @@ impl<'a> Emitter<'a> {
714714
)),
715715
ExprKind::RValue(x_doc) => ExprKind::RValue(annotated(
716716
v,
717-
self.nm
718-
.emit(Name::UnionFieldConstructor(
719-
union_name.val.clone(),
720-
a.val.clone(),
721-
))
722-
.append("?._0")
723-
.append(Doc::line())
724-
.append(x_doc)
725-
.group(),
717+
parens(
718+
self.nm
719+
.emit(Name::UnionFieldConstructor(
720+
union_name.val.clone(),
721+
a.val.clone(),
722+
))
723+
.append("?._0")
724+
.append(Doc::line())
725+
.append(x_doc)
726+
.group(),
727+
),
726728
)),
727729
}
728730
}
@@ -1556,7 +1558,13 @@ impl<'a> Emitter<'a> {
15561558

15571559
let k = &TypeRefKind::Typedef(name.clone());
15581560
let t = self.nm.emit(Name::TypeRef(k.into()));
1559-
let ty_decl = mk_let(t.clone(), &[], Doc::text("Type"), self.emit_type(env, body));
1561+
// The unfold here is important to trigger the loop detection in the Pulse prover
1562+
let ty_decl = Doc::text("unfold").append(Doc::line()).append(mk_let(
1563+
t.clone(),
1564+
&[],
1565+
Doc::text("Type"),
1566+
self.emit_type(env, body),
1567+
));
15601568
let env = &mut env.clone();
15611569
let this = env
15621570
.push_this(TypeT::TypeRef(k.clone()).with_loc(name.loc.clone()))

test/union_test2.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,30 @@ void test1(u_context_t ctx)
2323
_requires(_is_uds(ctx))
2424
{
2525
uint8_t *uds_buf = ctx.uds;
26-
_ghost_stmt(union__u_context_t__aux_raw_fold_uds $&(ctx) _);
2726
}
2827

2928
void test2(u_context_t *ctx)
3029
_requires(_is_uds(*ctx))
3130
{
3231
uint8_t *uds_buf = ctx->uds;
33-
_ghost_stmt(union__u_context_t__aux_raw_fold_uds $(ctx) _);
3432
}
3533

3634
void test3a(context_t ctx)
3735
_requires(_is_uds(ctx.payload))
3836
{
3937
u_context_t *payload = &ctx.payload;
4038
uint8_t *uds_buf = payload->uds;
41-
_ghost_stmt(union__u_context_t__aux_raw_fold_uds _ _);
4239
}
4340

4441

4542
void test3(context_t ctx)
4643
_requires(_is_uds(ctx.payload))
4744
{
4845
uint8_t *uds_buf = ctx.payload.uds;
49-
_ghost_stmt(union__u_context_t__aux_raw_fold_uds _ _);
5046
}
5147

5248
void test4(context_t *ctx)
5349
_requires(_is_uds(ctx->payload))
5450
{
5551
uint8_t *uds_buf = ctx->payload.uds;
56-
_ghost_stmt(union__u_context_t__aux_raw_fold_uds _ _);
5752
}

0 commit comments

Comments
 (0)