diff options
| author | 2026-10-15 15:19:17 +0330 | |
|---|---|---|
| committer | 2026-10-15 15:19:17 +0330 | |
| commit | d36190a5f3b8fa33fe3381771cd1efb9a1335e50 (patch) | |
| tree | d6b29e4720aa0a4b5bd54c7deee9a58fd622d25c | |
| parent | lsp test: block-end borrow message and related info (diff) | |
prescan: guess an owned return only from a local declared from new/heap, not a global assigned one (fixes lsp self-check); xref baseline for the new writers
| -rw-r--r-- | src/compiler/decl.zc | 8 | ||||
| -rw-r--r-- | tests/conformance/6-ownership/infer_owned_return_global_not_owned.zc | 7 | ||||
| -rw-r--r-- | tests/xref.baseline | 29 |
3 files changed, 28 insertions, 16 deletions
diff --git a/src/compiler/decl.zc b/src/compiler/decl.zc index e2c3613..bbde5ba 100644 --- a/src/compiler/decl.zc +++ b/src/compiler/decl.zc @@ -94,8 +94,12 @@ int prescan_maker() { // the guess only makes the function compile as if declared .u; its body is then // checked against that, so a wrong guess is an error, never a silent leak. int prescan_owned(int self) { - int depth = 0, n, k, found = 0, nown = 0; let owned[16]; + int depth = 0, n, k, found = 0, nown = 0, decl = 0; let owned[16]; while (tk != T_EOF) { + // a declaration's name follows a type name, a *, let or a comma; a plain + // assignment (to a global, say) follows ; { or } + int was = decl; + decl = tk == T_ID || (tk == T_OP && (rt.eq_w(tv, "*") || rt.eq_w(tv, ","))); if (is_op(s_lb)) depth++; else if (is_op(s_rb)) { depth--; if (!depth) { next(); return found; } } else if (tk == T_ID && rt.eq_w(tv, "return")) { @@ -107,7 +111,7 @@ int prescan_owned(int self) { } continue; } - else if (tk == T_ID) { + else if (tk == T_ID && was) { n = tv; peek(); if (pk_tk == T_OP && pk_tv == s_eq) { next(); next(); diff --git a/tests/conformance/6-ownership/infer_owned_return_global_not_owned.zc b/tests/conformance/6-ownership/infer_owned_return_global_not_owned.zc new file mode 100644 index 0000000..5d7f793 --- /dev/null +++ b/tests/conformance/6-ownership/infer_owned_return_global_not_owned.zc @@ -0,0 +1,7 @@ +// expect: 3/ +// spec 6.8 +include rt; +int* cache; +int* refill() { cache = rt.new(int); *cache = 3; return cache; } +fn main() { refill(); rt.put_n(*cache); rt.put_c(10); } +// zc0: skip diff --git a/tests/xref.baseline b/tests/xref.baseline index 26b6931..8b7c725 100644 --- a/tests/xref.baseline +++ b/tests/xref.baseline @@ -310,8 +310,8 @@ lnsz_initial local_captured clocap_at newloc reserve_locals local_cell capture_cell newloc reserve_locals local_dropset drop_attach expr localdecl newloc reassign_free reserve_locals -local_end_info assigncheck end_owner newloc reserve_locals -local_ended assigncheck end_owner newloc reserve_locals +local_end_info assigncheck block_end_owners end_owner newloc reserve_locals +local_ended assigncheck block_end_owners end_owner newloc reserve_locals local_origin assigncheck newloc reserve_locals local_origin_mask assigncheck newloc reserve_locals local_shadow newloc reserve_locals shadow_take shadow_use @@ -340,7 +340,7 @@ lrsoff_initial lsets chk_unit lslot newloc reserve_locals lsp ctx_pop loop_end loop_push zc_init -lstate alias_end assigncheck backedge block_close closure end_owner fndef handup join newloc recast reserve_locals retcheck snap_cmp snap_restore touch +lstate alias_end assigncheck backedge block_close block_end_owners closure end_owner fndef handup join newloc recast reserve_locals retcheck snap_cmp snap_restore touch lt_at lt_note lt_base lt_begin lt_end lt_buf lt_begin lt_room lt_stmt @@ -368,10 +368,10 @@ ltxt lt_note ltxtcap lt_note ltype array_literal_tokens closure embed_bind fndef kw_switch localdecl newloc reserve_locals lused assigncheck luse newloc reserve_locals -lv array_dynamic_literal array_literal_tokens bin blockexpr call chk_reset closure ctx_pop drop_attach enhcall expr field fn_begin heap_box incdec kwcall methcall newtyped postfix_tail primary rval ternary unary +lv array_dynamic_literal array_literal_tokens bin blockexpr call chk_reset closure ctx_pop drop_attach enhcall expr field fn_begin heap_box incdec kwcall methcall newtyped postfix_tail primary printcall rval ternary unary lvescaped closure newloc reserve_locals unary lvi chk_reset ctx_pop field postfix_tail primary -lvk array_dynamic_literal array_literal_tokens bin blockexpr call chk_reset closure ctx_pop drop_attach enhcall expr field fn_begin heap_box incdec kwcall methcall newtyped postfix_tail primary ternary unary +lvk array_dynamic_literal array_literal_tokens bin blockexpr call chk_reset closure ctx_pop drop_attach enhcall expr field fn_begin heap_box incdec kwcall methcall newtyped postfix_tail primary printcall ternary unary lvkind closure expr incdec newloc reserve_locals unary vf_effect vf_store lvvalue newloc reserve_locals vf_store mdbg chk_reset kw_memdebug @@ -497,6 +497,7 @@ qp readsrc src_push srcend qst readsrc src_push srcend readonly_types tconst types_init receiver_methods add_method zc_init +ret_borrowed fndef retcheck rsbase chk_unit rscap chk_unit rs_put rsn chk_unit rs_put @@ -705,27 +706,27 @@ uname add_unop reserve_unary uncap reserve_unary useq add_unop reserve_unary vislo build_image_grow chk_unit start syntax_resident -xaf af_forget args array_cap array_dynamic_literal array_len array_literal_tokens array_pop bin call chk_reset drop_attach drop_member expr field heap_box incdec kw_share_value kwcall methcall newtyped postfix_tail primary reassign_free ternary unary -xbor array_cap array_dynamic_literal array_len array_literal_tokens array_pop assigncheck bin blockexpr call chk_reset closure discard drop_attach drop_member enhcall field fn_begin heap_box kw_share_value kwcall methcall postfix_tail primary reassign_free ternary typearg unary +xaf af_forget args array_cap array_dynamic_literal array_len array_literal_tokens array_pop bin call chk_reset drop_attach drop_member expr field heap_box incdec kw_share_value kwcall methcall newtyped postfix_tail primary printcall reassign_free ternary unary +xbor array_cap array_dynamic_literal array_len array_literal_tokens array_pop assigncheck bin blockexpr call chk_reset closure discard drop_attach drop_member enhcall field fn_begin heap_box kw_share_value kwcall methcall postfix_tail primary printcall reassign_free ternary typearg unary xc_file xc_init xc_fn closure fndef xc_hook xc_init xc_on xc_init xc_src unit_stdin xcls array_cap array_len array_pop array_push array_resize chk_reset ctx_pop kw_asm kwcall quote_tokens -xconst array_dynamic_literal array_literal_tokens bin call chk_reset closure drop_attach heap_box kw_share_value methcall postfix_tail primary unary +xconst array_dynamic_literal array_literal_tokens bin call chk_reset closure drop_attach heap_box kw_share_value methcall postfix_tail primary printcall unary xcval array_literal_tokens primary unary -xfloat array_dynamic_literal array_len array_literal_tokens array_pop array_push array_resize bin blockexpr call closure drop_attach expr fcoerce femit ftest heap_box incdec kw_cfunc kw_for methcall postfix_tail primary reassign_free ternary unary +xfloat array_dynamic_literal array_len array_literal_tokens array_pop array_push array_resize bin blockexpr call closure drop_attach expr fcoerce femit ftest heap_box incdec kw_cfunc kw_for methcall postfix_tail primary printcall reassign_free ternary unary xgive argcheck args chk_reset xlend assigncheck expr unary -xlenloc array_len bin call closure enhcall methcall postfix_tail primary unary +xlenloc array_len bin call closure enhcall methcall postfix_tail primary printcall unary xprojection ctx_pop field postfix_tail primary xshadow assigncheck call shadow_take -xstamp array_dynamic_literal array_len bin call closure enhcall methcall newtyped postfix_tail primary unary -xstr array_dynamic_literal array_len array_literal_tokens bin blockexpr call closure drop_attach heap_box incdec methcall postfix_tail primary reassign_free unary -xty args array_cap array_dynamic_literal array_len array_literal_tokens array_pop array_push array_resize bin blockexpr call closure ctx_pop drop_attach drop_member enhcall expr fcoerce field ftest heap_box kw_cfunc kw_share_value kw_sizeof kw_typeof kwcall methcall newtyped postfix_tail primary reassign_free ternary unary +xstamp array_dynamic_literal array_len bin call closure enhcall methcall newtyped postfix_tail primary printcall unary +xstr array_dynamic_literal array_len array_literal_tokens bin blockexpr call closure drop_attach heap_box incdec methcall postfix_tail primary printcall reassign_free unary +xty args array_cap array_dynamic_literal array_len array_literal_tokens array_pop array_push array_resize bin blockexpr call closure ctx_pop drop_attach drop_member enhcall expr fcoerce field ftest heap_box kw_cfunc kw_share_value kw_sizeof kw_typeof kwcall methcall newtyped postfix_tail primary printcall reassign_free ternary unary xub bin xubat bin xvk array_dynamic_literal array_literal_tokens bin blockexpr chk_reset ctx_pop expr field fn_begin incdec kw_share_value kwcall postfix_tail primary ternary unary vf_coerce vf_effect vf_forget xvv blockexpr primary unary vf_coerce -xzero array_dynamic_literal array_literal_tokens bin blockexpr call closure drop_attach enhcall expr field heap_box incdec kwcall methcall newtyped postfix_tail primary ternary unary +xzero array_dynamic_literal array_literal_tokens bin blockexpr call closure drop_attach enhcall expr field heap_box incdec kwcall methcall newtyped postfix_tail primary printcall ternary unary |
