Skip to content

Commit 31151e3

Browse files
committed
v self works
1 parent 414cdb8 commit 31151e3

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

vlib/v/builder/builder.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ pub fn (b &Builder) find_module_path(mod string, fpath string) !string {
548548
if b.pref.is_verbose {
549549
println(' >> trying to find ${mod} in ${try_path} ..')
550550
}
551-
if found_path := find_module_path_from_search_root(p1, mod) {
551+
if found_path := find_module_path_from_search_root(current_dir, mod) {
552552
return found_path
553553
}
554554
parent_dir := os.dir(current_dir)

vlib/v/checker/if.v

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,6 @@ fn (mut c Checker) smartcast_none_guard_fallthrough(cond ast.Expr, mut scope ast
766766
return
767767
}
768768
}
769-
} else if first_cond.left in [ast.Ident, ast.SelectorExpr] && first_cond.op == .not_is {
770-
c.smartcast(mut first_cond.left, first_cond.left_type, first_cond.right_type, mut
771-
scope, false, false)
772769
}
773770
if c.comptime.get_ct_type_var(cond_expr.left) == .smartcast {
774771
cond_expr.left_type = c.type_resolver.get_type(cond_expr.left)

vlib/v/gen/c/cgen.v

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ mut:
203203
anon_fns shared []string // remove duplicate anon generated functions
204204
sumtype_definitions map[u32]bool // `_TypeA_to_sumtype_TypeB()` fns that have been generated
205205
trace_fn_definitions []string
206-
json_types []ast.Type // to avoid json gen duplicates
206+
json_types []ast.Type // to avoid json gen duplicates
207+
json_types_pos map[ast.Type]token.Pos
208+
json_gen_pos token.Pos
207209
pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name
208210
hotcode_fn_names []string
209211
hotcode_fpaths []string
@@ -485,6 +487,11 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
485487
global_g.array_last_index_types << g.array_last_index_types
486488
global_g.pcs << g.pcs
487489
global_g.json_types << g.json_types
490+
for k, v in g.json_types_pos {
491+
if k !in global_g.json_types_pos || global_g.json_types_pos[k] == token.Pos{} {
492+
global_g.json_types_pos[k] = v
493+
}
494+
}
488495
global_g.hotcode_fn_names << g.hotcode_fn_names
489496
global_g.hotcode_fpaths << g.hotcode_fpaths
490497
global_g.test_function_names << g.test_function_names
@@ -1118,6 +1125,10 @@ pub fn (mut g Gen) init() {
11181125
// muttable.used_features.used_fns['exit'] = true
11191126
}
11201127

1128+
fn (g &Gen) should_use_object_local_linkage(mod string) bool {
1129+
return g.pref.is_o && g.module_built != '' && mod != g.module_built
1130+
}
1131+
11211132
pub fn (mut g Gen) finish() {
11221133
if g.pref.is_prof && g.pref.build_mode != .build_module {
11231134
g.gen_vprint_profile_stats()
@@ -9160,6 +9171,52 @@ fn (mut g Gen) check_noscan(elem_typ ast.Type) string {
91609171
return ''
91619172
}
91629173

9174+
// vgc_ptrmap computes a precise pointer bitmap for simple VGC heap allocations.
9175+
fn (mut g Gen) vgc_ptrmap(typ ast.Type) (string, string) {
9176+
if g.pref.gc_mode != .vgc {
9177+
return '', ''
9178+
}
9179+
if !g.contains_ptr(typ) {
9180+
return '', ''
9181+
}
9182+
unwrapped := g.unwrap_generic(typ)
9183+
sym := g.table.final_sym(unwrapped)
9184+
if sym.kind != .struct {
9185+
return '', ''
9186+
}
9187+
info := sym.info as ast.Struct
9188+
styp := g.styp(unwrapped)
9189+
mut parts := []string{}
9190+
mut nptrs := 0
9191+
for embed in info.embeds {
9192+
if g.contains_ptr(embed) {
9193+
return '', ''
9194+
}
9195+
}
9196+
for field in info.fields {
9197+
if field.typ.is_any_kind_of_pointer() || field.typ.is_ptr() {
9198+
fname := c_name(field.name)
9199+
parts << '(1ULL << (offsetof(${styp}, ${fname}) / sizeof(void*)))'
9200+
nptrs++
9201+
} else {
9202+
fsym := g.table.final_sym(field.typ)
9203+
if fsym.kind in [.array, .map, .string] {
9204+
fname := c_name(field.name)
9205+
parts << '(1ULL << (offsetof(${styp}, ${fname}) / sizeof(void*)))'
9206+
nptrs++
9207+
} else if fsym.kind in [.interface, .sum_type] {
9208+
return '', ''
9209+
} else if g.contains_ptr(field.typ) {
9210+
return '', ''
9211+
}
9212+
}
9213+
}
9214+
if parts.len == 0 {
9215+
return '', ''
9216+
}
9217+
return '(uint64_t)(${parts.join(' | ')})', '${nptrs}'
9218+
}
9219+
91639220
// vint2int rename `_vint_t` to `int`
91649221
fn vint2int(name string) string {
91659222
$if new_int ? && x64 {

0 commit comments

Comments
 (0)