Skip to content

Commit 51f0ab7

Browse files
committed
C gen: don't tag closure objects
Similar to boxed products, closures are not analyzed in pattern matching based on a tag, so the tag word can be removed. When we implement the support for closures in variants we'll need to assign them tags based on their function types. Also remove an old comment in lowering saying that integers don't have tags. They do now (used in variants), they're just not tagged by default.
1 parent 8af8bd3 commit 51f0ab7

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

src/lowering.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ pub enum BuiltinConDecl {
368368
t: mono::Type,
369369
},
370370

371-
// Integers are value types (not boxed), so they don't have tags.
372371
I8,
373372
U8,
374373
I32,

src/to_c.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,10 @@ pub(crate) fn to_c(pgm: &LoweredPgm, main: &str) -> String {
7070

7171
// Generate the CLOSURE type before other types. CLOSURE is a special built-in that doesn't have
7272
// a TypeDecl entry, so it's not part of the dependency-sorted types.
73-
let closure_tag = CLOSURE_CON_IDX.0;
74-
wln!(p, "#define CLOSURE_TAG {closure_tag}");
7573
writedoc!(
7674
p,
7775
"
7876
typedef struct {{
79-
uint64_t tag;
8077
void (*fun)(void);
8178
// captures here ...
8279
}} CLOSURE;
@@ -328,7 +325,7 @@ pub(crate) fn to_c(pgm: &LoweredPgm, main: &str) -> String {
328325

329326
w!(
330327
p,
331-
"static CLOSURE _con_closure_{tag}_data = {{ .tag = CLOSURE_TAG, .fun = (void(*)(void))_con_closure_{tag}_fun }};",
328+
"static CLOSURE _con_closure_{tag}_data = {{ .fun = (void(*)(void))_con_closure_{tag}_fun }};",
332329
);
333330
p.nl();
334331

@@ -379,7 +376,7 @@ pub(crate) fn to_c(pgm: &LoweredPgm, main: &str) -> String {
379376

380377
w!(
381378
p,
382-
"static CLOSURE _fun_closure_{i}_data = {{ .tag = CLOSURE_TAG, .fun = (void(*)(void))_fun_closure_{i}_fun }};",
379+
"static CLOSURE _fun_closure_{i}_data = {{ .fun = (void(*)(void))_fun_closure_{i}_fun }};",
383380
);
384381
p.nl();
385382

@@ -484,7 +481,6 @@ fn gen_closure_struct(closure: &Closure, idx: usize, pgm: &LoweredPgm, p: &mut P
484481
w!(p, "typedef struct {{");
485482
p.indent();
486483
p.nl();
487-
wln!(p, "uint64_t tag;");
488484
wln!(p, "void (*fun)(void);");
489485
for (i, fv) in closure.fvs.iter().enumerate() {
490486
if i != 0 {
@@ -2098,15 +2094,13 @@ fn expr_to_c(expr: &Expr, loc: &Loc, locals: &[LocalInfo], cg: &mut Cg, p: &mut
20982094
p.nl();
20992095
if closure.fvs.is_empty() {
21002096
wln!(p, "CLOSURE* _clos = (CLOSURE*)malloc(sizeof(CLOSURE));");
2101-
wln!(p, "_clos->tag = CLOSURE_TAG;");
21022097
w!(p, "_clos->fun = (void(*)(void))_closure_{};", idx);
21032098
p.nl();
21042099
} else {
21052100
wln!(
21062101
p,
21072102
"_Closure_{idx}* _clos = (_Closure_{idx}*)malloc(sizeof(_Closure_{idx}));"
21082103
);
2109-
wln!(p, "_clos->tag = CLOSURE_TAG;");
21102104
w!(p, "_clos->fun = (void(*)(void))_closure_{};", idx);
21112105
p.nl();
21122106
for (i, fv) in closure.fvs.iter().enumerate() {

0 commit comments

Comments
 (0)