From ed7da0d9e31e8dd6847e2e603f0d1943330cf4d0 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 13 Mar 2026 14:07:29 +0200 Subject: add initial reference invalidation + Makes vec example actually memory safe, which is cool + Specify owner > sub relationships with ">" in closure parameter lists, uses the same group idea as closure calls + Relies on users implementing functions in a consistent manner, since you can kind of do whatever with pointers. Presumably there would be a stdlib of vec/map/set etc. which applications could then use and by proxy be memory safe. Although some more checks wouldn't hurt, I suppose? + Not sure I like having reference invalidation be 'just a move', seems to work alright but the semantics of it are a bit muddy. --- src/move.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/move.c') diff --git a/src/move.c b/src/move.c index 5137719..a76ffd5 100644 --- a/src/move.c +++ b/src/move.c @@ -372,6 +372,19 @@ static int mvcheck_id(struct state *state, struct ast *node) if (def->k != AST_VAR_DEF) return 0; + struct ast_pair *prev = find_move(state, def); + + /* a reference invalidation is represented as a 'moved' + * reference, which is not expressible within the + * language but is constructed as part of + * opt_group_left/opt_group_right forcing a move to + * happen. Hack? */ + if (def->t->k == TYPE_REF && prev) { + /** @todo a more fitting error message? */ + move_error(node, prev->use); + return -1; + } + if (is_trivially_copyable(def->t)) return 0; @@ -381,7 +394,6 @@ static int mvcheck_id(struct state *state, struct ast *node) return -1; } - struct ast_pair *prev = find_move(state, def); if (prev) { /* error messages for opt groups could be improved */ move_error(node, prev->use); -- cgit v1.2.3