Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 20, 2025
1 parent 4800a60 commit 9b7a84d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
8 changes: 1 addition & 7 deletions vlib/v/markused/markused.v
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
if table.used_features.range_index || pref_.is_shared {
core_fns << string_idx_str + '.substr_with_check'
core_fns << string_idx_str + '.substr_ni'
core_fns << string_idx_str + '.substr'
core_fns << array_idx_str + '.slice_ni'
core_fns << array_idx_str + '.get_with_check' // used for `x := a[i] or {}`
core_fns << array_idx_str + '.clone_static_to_depth'
Expand Down Expand Up @@ -524,13 +525,6 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
}
}

if table.used_features.range_index {
walker.fn_by_name(string_idx_str + '.substr')
}
if walker.as_cast_type_names.len > 0 {
walker.fn_by_name('new_array_from_c_array')
}

table.used_features.used_fns = walker.used_fns.move()
table.used_features.used_consts = walker.used_consts.move()
table.used_features.used_globals = walker.used_globals.move()
Expand Down
37 changes: 0 additions & 37 deletions vlib/v/markused/walker.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ mut:
all_fns map[string]ast.FnDecl
all_consts map[string]ast.ConstField
all_globals map[string]ast.GlobalField
//
as_cast_type_names map[string]string
}

pub fn Walker.new(params Walker) &Walker {
Expand Down Expand Up @@ -513,7 +511,6 @@ fn (mut w Walker) expr(node_ ast.Expr) {
///
ast.AsCast {
w.expr(node.expr)
w.as_cast(node)
}
ast.AtExpr {}
ast.BoolLiteral {}
Expand Down Expand Up @@ -733,37 +730,3 @@ pub fn (mut w Walker) or_block(node ast.OrExpr) {
w.stmts(node.stmts)
}
}

pub fn (mut w Walker) as_cast(node ast.AsCast) {
if node.typ == 0 {
return
}
if node.typ.has_flag(.generic) {
w.as_cast_type_names['some_generic_type'] = 'some_generic_name'
return
}
if node.expr_type == 0 {
return
}
if node.expr_type.has_flag(.generic) {
w.as_cast_type_names['some_generic_type'] = 'some_generic_name'
return
}
mut expr_type_sym := w.table.sym(node.expr_type)
if mut expr_type_sym.info is ast.SumType {
w.fill_as_cast_type_names(expr_type_sym.info.variants)
} else if mut expr_type_sym.info is ast.Interface && node.expr_type != node.typ {
w.fill_as_cast_type_names(expr_type_sym.info.types)
}
}

fn (mut w Walker) fill_as_cast_type_names(types []ast.Type) {
for variant in types {
idx := u32(variant).str()
if idx in w.as_cast_type_names {
continue
}
variant_sym := w.table.sym(variant)
w.as_cast_type_names[idx] = variant_sym.name
}
}

0 comments on commit 9b7a84d

Please sign in to comment.