mirror of
https://github.com/vlang/v.git
synced 2025-09-18 11:56:57 -04:00
checker: reduce allocations part 2 (#22434)
This commit is contained in:
parent
184a86343e
commit
d3c3c391ca
@ -81,7 +81,7 @@ fn (mut c Checker) ident_autocomplete(node ast.Ident) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_method_summary(method ast.Fn) string {
|
fn build_method_summary(method &ast.Fn) string {
|
||||||
mut s := method.name + '('
|
mut s := method.name + '('
|
||||||
for i, param in method.params {
|
for i, param in method.params {
|
||||||
s += param.name
|
s += param.name
|
||||||
|
@ -928,7 +928,7 @@ fn (g Checker) get_generic_array_fixed_element_type(array ast.ArrayFixed) ast.Ty
|
|||||||
return typ
|
return typ
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr) {
|
fn (mut c Checker) infer_fn_generic_types(func &ast.Fn, mut node ast.CallExpr) {
|
||||||
mut inferred_types := []ast.Type{}
|
mut inferred_types := []ast.Type{}
|
||||||
mut arg_inferred := []int{}
|
mut arg_inferred := []int{}
|
||||||
for gi, gt_name in func.generic_names {
|
for gi, gt_name in func.generic_names {
|
||||||
|
@ -3713,7 +3713,7 @@ struct ACFieldMethod {
|
|||||||
typ string
|
typ string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) resolve_var_fn(func ast.Fn, mut node ast.Ident, name string) ast.Type {
|
fn (mut c Checker) resolve_var_fn(func &ast.Fn, mut node ast.Ident, name string) ast.Type {
|
||||||
mut fn_type := ast.new_type(c.table.find_or_register_fn_type(func, false, true))
|
mut fn_type := ast.new_type(c.table.find_or_register_fn_type(func, false, true))
|
||||||
if func.generic_names.len > 0 {
|
if func.generic_names.len > 0 {
|
||||||
concrete_types := node.concrete_types.map(c.unwrap_generic(it))
|
concrete_types := node.concrete_types.map(c.unwrap_generic(it))
|
||||||
|
@ -597,7 +597,7 @@ fn (mut c Checker) eval_comptime_const_expr(expr ast.Expr, nlevel int) ?ast.Comp
|
|||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) verify_vweb_params_for_method(node ast.Fn) (bool, int, int) {
|
fn (mut c Checker) verify_vweb_params_for_method(node &ast.Fn) (bool, int, int) {
|
||||||
margs := node.params.len - 1 // first arg is the receiver/this
|
margs := node.params.len - 1 // first arg is the receiver/this
|
||||||
// if node.attrs.len == 0 || (node.attrs.len == 1 && node.attrs[0].name == 'post') {
|
// if node.attrs.len == 0 || (node.attrs.len == 1 && node.attrs[0].name == 'post') {
|
||||||
if node.attrs.len == 0 {
|
if node.attrs.len == 0 {
|
||||||
|
@ -693,7 +693,7 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
|
|||||||
return typ
|
return typ
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) builtin_args(mut node ast.CallExpr, fn_name string, func ast.Fn) {
|
fn (mut c Checker) builtin_args(mut node ast.CallExpr, fn_name string, func &ast.Fn) {
|
||||||
c.inside_interface_deref = true
|
c.inside_interface_deref = true
|
||||||
c.expected_type = ast.string_type
|
c.expected_type = ast.string_type
|
||||||
if !(node.language != .js && node.args[0].expr is ast.CallExpr) {
|
if !(node.language != .js && node.args[0].expr is ast.CallExpr) {
|
||||||
@ -1690,25 +1690,33 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// register_trace_call registers the wrapper funcs for calling funcs for callstack feature
|
// register_trace_call registers the wrapper funcs for calling funcs for callstack feature
|
||||||
fn (mut c Checker) register_trace_call(node ast.CallExpr, func ast.Fn) {
|
fn (mut c Checker) register_trace_call(node &ast.CallExpr, func &ast.Fn) {
|
||||||
is_traceable := (c.pref.is_callstack || c.pref.is_trace) && c.table.cur_fn != unsafe { nil }
|
if !(c.pref.is_callstack || c.pref.is_trace) || c.table.cur_fn == unsafe { nil }
|
||||||
&& node.language == .v && c.file.imports.any(it.mod == 'v.debug')
|
|| node.language != .v {
|
||||||
&& node.name !in ['v.debug.callstack', 'v.debug.add_after_call', 'v.debug.add_before_call', 'v.debug.remove_after_call', 'v.debug.remove_before_call']
|
return
|
||||||
if is_traceable {
|
}
|
||||||
hash_fn, fn_name := c.table.get_trace_fn_name(c.table.cur_fn, node)
|
if node.name in ['v.debug.callstack', 'v.debug.add_after_call', 'v.debug.add_before_call',
|
||||||
calling_fn := if func.is_method {
|
'v.debug.remove_after_call', 'v.debug.remove_before_call'] {
|
||||||
'${c.table.type_to_str(c.unwrap_generic(node.left_type))}_${fn_name}'
|
return
|
||||||
} else {
|
}
|
||||||
fn_name
|
if !c.file.imports.any(it.mod == 'v.debug') {
|
||||||
}
|
return
|
||||||
c.table.cur_fn.trace_fns[hash_fn] = ast.FnTrace{
|
}
|
||||||
name: calling_fn
|
hash_fn, fn_name := c.table.get_trace_fn_name(c.table.cur_fn, node)
|
||||||
file: c.file.path
|
calling_fn := if func.is_method {
|
||||||
line: node.pos.line_nr + 1
|
'${c.table.type_to_str(c.unwrap_generic(node.left_type))}_${fn_name}'
|
||||||
return_type: node.return_type
|
} else {
|
||||||
func: &func
|
fn_name
|
||||||
is_fn_var: node.is_fn_var
|
}
|
||||||
|
c.table.cur_fn.trace_fns[hash_fn] = ast.FnTrace{
|
||||||
|
name: calling_fn
|
||||||
|
file: c.file.path
|
||||||
|
line: node.pos.line_nr + 1
|
||||||
|
return_type: node.return_type
|
||||||
|
func: &ast.Fn{
|
||||||
|
...func
|
||||||
}
|
}
|
||||||
|
is_fn_var: node.is_fn_var
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1741,7 +1749,7 @@ fn (mut c Checker) is_generic_expr(node ast.Expr) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) resolve_comptime_args(func ast.Fn, node_ ast.CallExpr, concrete_types []ast.Type) map[int]ast.Type {
|
fn (mut c Checker) resolve_comptime_args(func &ast.Fn, node_ ast.CallExpr, concrete_types []ast.Type) map[int]ast.Type {
|
||||||
mut comptime_args := map[int]ast.Type{}
|
mut comptime_args := map[int]ast.Type{}
|
||||||
has_dynamic_vars := (c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len > 0)
|
has_dynamic_vars := (c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len > 0)
|
||||||
|| c.comptime.comptime_for_field_var != ''
|
|| c.comptime.comptime_for_field_var != ''
|
||||||
@ -1890,7 +1898,7 @@ fn (mut c Checker) resolve_comptime_args(func ast.Fn, node_ ast.CallExpr, concre
|
|||||||
return comptime_args
|
return comptime_args
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) resolve_fn_generic_args(func ast.Fn, mut node ast.CallExpr) []ast.Type {
|
fn (mut c Checker) resolve_fn_generic_args(func &ast.Fn, mut node ast.CallExpr) []ast.Type {
|
||||||
mut concrete_types := node.concrete_types.map(c.unwrap_generic(it))
|
mut concrete_types := node.concrete_types.map(c.unwrap_generic(it))
|
||||||
|
|
||||||
// dynamic values from comptime and generic parameters
|
// dynamic values from comptime and generic parameters
|
||||||
|
Loading…
x
Reference in New Issue
Block a user