Skip to content

Commit 34e175a

Browse files
authored
checker: minor cleanup of the fns classification (#12977)
1 parent a2eb90e commit 34e175a

File tree

3 files changed

+379
-378
lines changed

3 files changed

+379
-378
lines changed

vlib/v/checker/checker.v

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,85 +1600,6 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
16001600
return to_lock, pos
16011601
}
16021602

1603-
pub fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
1604-
// First check everything that applies to both fns and methods
1605-
// TODO merge logic from method_call and fn_call
1606-
/*
1607-
for i, call_arg in node.args {
1608-
if call_arg.is_mut {
1609-
c.fail_if_immutable(call_arg.expr)
1610-
if !arg.is_mut {
1611-
tok := call_arg.share.str()
1612-
c.error('`$node.name` parameter `$arg.name` is not `$tok`, `$tok` is not needed`',
1613-
call_arg.expr.position())
1614-
} else if arg.typ.share() != call_arg.share {
1615-
c.error('wrong shared type', call_arg.expr.position())
1616-
}
1617-
} else {
1618-
if arg.is_mut && (!call_arg.is_mut || arg.typ.share() != call_arg.share) {
1619-
tok := call_arg.share.str()
1620-
c.error('`$node.name` parameter `$arg.name` is `$tok`, you need to provide `$tok` e.g. `$tok arg${i+1}`',
1621-
call_arg.expr.position())
1622-
}
1623-
}
1624-
}
1625-
*/
1626-
// Now call `method_call` or `fn_call` for specific checks.
1627-
old_inside_fn_arg := c.inside_fn_arg
1628-
c.inside_fn_arg = true
1629-
mut continue_check := true
1630-
typ := if node.is_method {
1631-
c.method_call(mut node)
1632-
} else {
1633-
c.fn_call(mut node, mut continue_check)
1634-
}
1635-
if !continue_check {
1636-
return ast.void_type
1637-
}
1638-
c.inside_fn_arg = old_inside_fn_arg
1639-
// autofree: mark args that have to be freed (after saving them in tmp exprs)
1640-
free_tmp_arg_vars := c.pref.autofree && !c.is_builtin_mod && node.args.len > 0
1641-
&& !node.args[0].typ.has_flag(.optional)
1642-
if free_tmp_arg_vars && !c.inside_const {
1643-
for i, arg in node.args {
1644-
if arg.typ != ast.string_type {
1645-
continue
1646-
}
1647-
if arg.expr in [ast.Ident, ast.StringLiteral, ast.SelectorExpr] {
1648-
// Simple expressions like variables, string literals, selector expressions
1649-
// (`x.field`) can't result in allocations and don't need to be assigned to
1650-
// temporary vars.
1651-
// Only expressions like `str + 'b'` need to be freed.
1652-
continue
1653-
}
1654-
node.args[i].is_tmp_autofree = true
1655-
}
1656-
// TODO copy pasta from above
1657-
if node.receiver_type == ast.string_type
1658-
&& node.left !in [ast.Ident, ast.StringLiteral, ast.SelectorExpr] {
1659-
node.free_receiver = true
1660-
}
1661-
}
1662-
c.expected_or_type = node.return_type.clear_flag(.optional)
1663-
c.stmts_ending_with_expression(node.or_block.stmts)
1664-
c.expected_or_type = ast.void_type
1665-
if node.or_block.kind == .propagate && !c.table.cur_fn.return_type.has_flag(.optional)
1666-
&& !c.inside_const {
1667-
if !c.table.cur_fn.is_main {
1668-
c.error('to propagate the optional call, `$c.table.cur_fn.name` must return an optional',
1669-
node.or_block.pos)
1670-
}
1671-
}
1672-
return typ
1673-
}
1674-
1675-
fn semicolonize(main string, details string) string {
1676-
if details == '' {
1677-
return main
1678-
}
1679-
return '$main; $details'
1680-
}
1681-
16821603
fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos token.Position) bool {
16831604
$if debug_interface_type_implements ? {
16841605
eprintln('> type_implements typ: $typ.debug() (`${c.table.type_to_str(typ)}`) | inter_typ: $interface_type.debug() (`${c.table.type_to_str(interface_type)}`)')
@@ -2597,19 +2518,6 @@ fn (mut c Checker) for_c_stmt(node ast.ForCStmt) {
25972518
c.in_for_count--
25982519
}
25992520

2600-
fn (mut c Checker) comptime_for(node ast.ComptimeFor) {
2601-
typ := c.unwrap_generic(node.typ)
2602-
sym := c.table.sym(typ)
2603-
if sym.kind == .placeholder || typ.has_flag(.generic) {
2604-
c.error('unknown type `$sym.name`', node.typ_pos)
2605-
}
2606-
if node.kind == .fields {
2607-
c.comptime_fields_type[node.val_var] = node.typ
2608-
c.comptime_fields_default_type = node.typ
2609-
}
2610-
c.stmts(node.stmts)
2611-
}
2612-
26132521
fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
26142522
c.in_for_count++
26152523
prev_loop_label := c.loop_label
@@ -4822,36 +4730,6 @@ fn (mut c Checker) fetch_field_name(field ast.StructField) string {
48224730
return name
48234731
}
48244732

4825-
fn (mut c Checker) post_process_generic_fns() {
4826-
// Loop thru each generic function concrete type.
4827-
// Check each specific fn instantiation.
4828-
for i in 0 .. c.file.generic_fns.len {
4829-
mut node := c.file.generic_fns[i]
4830-
c.mod = node.mod
4831-
gtypes := c.table.fn_generic_types[node.name]
4832-
$if trace_post_process_generic_fns ? {
4833-
eprintln('> post_process_generic_fns $node.mod | $node.name | $gtypes')
4834-
}
4835-
for concrete_types in gtypes {
4836-
c.table.cur_concrete_types = concrete_types
4837-
c.fn_decl(mut node)
4838-
if node.name == 'vweb.run' {
4839-
for ct in concrete_types {
4840-
if ct !in c.vweb_gen_types {
4841-
c.vweb_gen_types << ct
4842-
}
4843-
}
4844-
}
4845-
}
4846-
c.table.cur_concrete_types = []
4847-
$if trace_post_process_generic_fns ? {
4848-
if node.generic_names.len > 0 {
4849-
eprintln(' > fn_decl node.name: $node.name | generic_names: $node.generic_names | ninstances: $node.ninstances')
4850-
}
4851-
}
4852-
}
4853-
}
4854-
48554733
fn (mut c Checker) trace(fbase string, message string) {
48564734
if c.file.path_base == fbase {
48574735
println('> c.trace | ${fbase:-10s} | $message')

0 commit comments

Comments
 (0)