From 783cee98d9e9dafd854e1b2f006892ee5c6462d4 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 20 Feb 2021 21:54:47 +0800 Subject: [PATCH] table/parser: minor optimization of anon_fn names (#8851) --- vlib/v/parser/fn.v | 2 +- vlib/v/table/table.v | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index f2e40e317c..8db0f089fd 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -564,7 +564,7 @@ fn (mut p Parser) anon_fn() ast.AnonFn { is_variadic: is_variadic return_type: return_type } - name := 'anon_${p.tok.pos}_${p.table.fn_type_signature(func)}' + name := 'anon_fn_${p.table.fn_type_signature(func)}_$p.tok.pos' func.name = name idx := p.table.find_or_register_fn_type(p.mod, func, true, false) typ := table.new_type(idx) diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 71986e4b7d..78d8da7fd0 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -98,16 +98,16 @@ pub fn (t &Table) fn_type_signature(f &Fn) string { for i, arg in f.params { // TODO: for now ignore mut/pts in sig for now typ := arg.typ.set_nr_muls(0) - // if arg.is_mut { - // sig += 'mut_' - // } - // sig += '$arg.typ' - sig += '$typ' + arg_type_sym := t.get_type_symbol(typ) + sig += '$arg_type_sym.kind' if i < f.params.len - 1 { sig += '_' } } - sig += '_$f.return_type' + if f.return_type != 0 && f.return_type != void_type { + sym := t.get_type_symbol(f.return_type) + sig += '__$sym.kind' + } return sig }