Skip to content

Commit 4961888

Browse files
committed
make_compile
1 parent 33c2fe3 commit 4961888

11 files changed

Lines changed: 44 additions & 116 deletions

File tree

vlib/v/ast/table.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ pub fn (t &Table) does_type_implement_interface(typ Type, inter_typ Type) bool {
21642164
}
21652165
return false
21662166
}
2167-
if !is_interface_upcast && typ != voidptr_type && typ != nil_type && typ != none_type
2167+
if sym.kind != .interface && typ != voidptr_type && typ != nil_type && typ != none_type
21682168
&& !inter_sym.info.types.contains(typ) {
21692169
inter_sym.info.types << typ
21702170
}

vlib/v/builder/cc.v

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,58 +1302,6 @@ fn (mut b Builder) cc_linux_cross() {
13021302
verror(cc_res.output)
13031303
return
13041304
}
1305-
// Compile extra .c source files (from `#flag @VMODROOT/file.c` etc.)
1306-
// separately for the cross target, and collect the resulting .o files.
1307-
mut extra_obj_files := []string{cap: extra_c_sources.len}
1308-
for csource in extra_c_sources {
1309-
extra_obj := csource + '.o'
1310-
mut extra_cc_args := []string{cap: 10}
1311-
extra_cc_args << '-w'
1312-
extra_cc_args << '-fPIC'
1313-
extra_cc_args << '-target x86_64-linux-gnu'
1314-
extra_cc_args << defines
1315-
extra_cc_args << conly_flags
1316-
extra_cc_args << '-I ${os.quoted_path('${sysroot}/include')} '
1317-
extra_cc_args << '-o ${os.quoted_path(extra_obj)}'
1318-
extra_cc_args << '-c ${os.quoted_path(csource)}'
1319-
extra_cmd := '${b.quote_compiler_name(cc_name)} ' + extra_cc_args.join(' ')
1320-
if b.pref.show_cc {
1321-
println(extra_cmd)
1322-
}
1323-
extra_res := os.execute(extra_cmd)
1324-
if extra_res.exit_code != 0 {
1325-
println('Cross compilation for Linux failed (compiling ${csource}).')
1326-
verror(extra_res.output)
1327-
return
1328-
}
1329-
extra_obj_files << os.quoted_path(extra_obj)
1330-
}
1331-
// For libraries that only exist as static .a in the sysroot (e.g. libpq.a),
1332-
// create shared library stubs so the linker produces a dynamically linked binary
1333-
// instead of pulling in incomplete static archives with missing internal deps.
1334-
lib_search_paths := [
1335-
os.join_path(sysroot, 'usr', 'lib', 'x86_64-linux-gnu'),
1336-
os.join_path(sysroot, 'lib', 'x86_64-linux-gnu'),
1337-
]
1338-
stubs_dir := os.join_path(os.vtmp_dir(), 'cross_linux_stubs')
1339-
os.mkdir_all(stubs_dir) or {}
1340-
for lib in libs {
1341-
libname := lib.replace('-l', '')
1342-
if libname in ['c', 'pthread', 'm', 'dl'] {
1343-
continue // standard libs, always available
1344-
}
1345-
has_so := lib_search_paths.any(os.exists(os.join_path(it, 'lib${libname}.so')))
1346-
has_a := !has_so && lib_search_paths.any(os.exists(os.join_path(it, 'lib${libname}.a')))
1347-
if has_a {
1348-
a_path := lib_search_paths.map(os.join_path(it, 'lib${libname}.a')).filter(os.exists(it))[0] or {
1349-
continue
1350-
}
1351-
stub_so := os.join_path(stubs_dir, 'lib${libname}.so')
1352-
if !os.exists(stub_so) {
1353-
b.create_shared_lib_stub(cc_name, a_path, stub_so, sysroot)
1354-
}
1355-
}
1356-
}
13571305
// Compile compiler runtime builtins (provides __udivti3 etc. for 128-bit integer
13581306
// operations used by thirdparty code like mbedtls bignum.c, since the linuxroot
13591307
// sysroot doesn't include libgcc or compiler-rt).

vlib/v/checker/check_types.v

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,14 +1315,15 @@ fn (mut c Checker) infer_fn_generic_types(func &ast.Fn, mut node ast.CallExpr) {
13151315
if arg.expr.is_auto_deref_var() && typ.is_ptr() {
13161316
if !arg.is_mut {
13171317
typ = typ.deref()
1318-
} else if arg.expr is ast.Ident && arg.expr.obj is ast.Var
1319-
&& arg.expr.obj.generic_typ == 0 {
1320-
// Non-generic auto-deref mut param: obj.typ includes the
1321-
// mut pointer (e.g. mut ctx Context → obj.typ=&Context),
1322-
// so strip it for generic inference.
1323-
// Generic auto-deref mut params (generic_typ != 0) already
1324-
// have the correct resolved type without extra mut pointer.
1325-
typ = typ.deref()
1318+
} else if arg.expr is ast.Ident && arg.expr.obj is ast.Var {
1319+
if arg.expr.obj.generic_typ == 0 {
1320+
// Non-generic auto-deref mut param: obj.typ includes the
1321+
// mut pointer (e.g. mut ctx Context → obj.typ=&Context),
1322+
// so strip it for generic inference.
1323+
// Generic auto-deref mut params (generic_typ != 0) already
1324+
// have the correct resolved type without extra mut pointer.
1325+
typ = typ.deref()
1326+
}
13261327
}
13271328
}
13281329
// resolve &T &&T ...

vlib/v/checker/checker.v

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,24 +3119,6 @@ fn (mut c Checker) enum_decl(mut node ast.EnumDecl) {
31193119
field.expr.pos)
31203120
}
31213121
}
3122-
ast.IfExpr {
3123-
c.if_expr(mut field.expr)
3124-
if comptime_value := c.eval_comptime_const_expr(field.expr, 0) {
3125-
comptime_lit := c.comptime_value_to_integer_literal(comptime_value,
3126-
field.expr.pos) or {
3127-
c.error('the default value for an enum has to be an integer',
3128-
field.expr.pos)
3129-
continue
3130-
}
3131-
c.check_enum_field_integer_literal(comptime_lit, signed,
3132-
node.is_multi_allowed, senum_type, field.expr.pos, mut useen,
3133-
enum_umin, enum_umax, mut iseen, enum_imin, enum_imax)
3134-
field.expr = comptime_lit
3135-
} else {
3136-
c.error('the default value for an enum has to be an integer',
3137-
field.expr.pos)
3138-
}
3139-
}
31403122
else {
31413123
if mut field.expr is ast.Ident {
31423124
if field.expr.language == .c {

vlib/v/checker/fn.v

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,11 +3320,6 @@ fn (mut c Checker) method_call(mut node ast.CallExpr, mut continue_check &bool)
33203320
if exp_arg_typ.has_flag(.generic) {
33213321
has_unresolved_generic_param = c.check_unresolved_generic_param(node, arg)
33223322
|| has_unresolved_generic_param
3323-
method_concrete_types := if method_generic_names_len == rec_concrete_types.len {
3324-
rec_concrete_types
3325-
} else {
3326-
concrete_types
3327-
}
33283323
if exp_utyp := c.table.convert_generic_param_type(param, method.generic_names,
33293324
method_concrete_types)
33303325
{

vlib/v/checker/if.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ fn (mut c Checker) smartcast_if_conds(mut node ast.Expr, mut scope ast.Scope, co
783783
if left_sym.kind in [.interface, .sum_type] || is_option_unwrap {
784784
mut left_expr := first_cond.left
785785
c.smartcast(mut left_expr, left_type, right_type, mut scope,
786-
false, is_option_unwrap)
786+
false, is_option_unwrap, false)
787787
}
788788
}
789789
c.smartcast_none_guard_unwrap(control_expr.branches[0].cond, mut scope)

vlib/v/gen/c/assign.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ fn (mut g Gen) gen_self_recursing_anon_fn_capture_patch(left ast.Expr, anon_fn a
6363
if ident.name !in anon_fn.inherited_vars.map(it.name) {
6464
return
6565
}
66-
concrete_types := g.get_anon_fn_concrete_types(anon_fn)
67-
ctx_struct := g.closure_ctx(anon_fn.decl, concrete_types)
66+
ctx_struct := g.closure_ctx(anon_fn.decl)
6867
left_expr := g.expr_string(left)
6968
g.writeln('((${ctx_struct}*)builtin__closure__closure_data(${left_expr}))->${c_name(ident.name)} = ${left_expr};')
7069
}

vlib/v/gen/c/cgen.v

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ mut:
200200
threaded_fns shared []string // for generating unique wrapper types and fns for `go xxx()`
201201
waiter_fns shared []string // functions that wait for `go xxx()` to finish
202202
needed_equality_fns []ast.Type
203-
generated_eq_fns []ast.Type
204-
array_sort_fn shared []string
203+
generated_eq_fns []ast.Type
204+
generated_array_interface_cast_fns shared map[string]bool
205+
array_sort_fn shared []string
205206
array_contains_types []ast.Type
206207
array_index_types []ast.Type
207208
array_last_index_types []ast.Type
@@ -934,8 +935,6 @@ fn cgen_process_one_file_cb(mut p pool.PoolProcessor, idx int, wid int) voidptr
934935
done_typedef_phase: global_g.done_typedef_phase
935936
array_typedefs: global_g.array_typedefs.clone()
936937
written_array_typedefs: global_g.written_array_typedefs
937-
static_modifier: global_g.static_modifier
938-
static_non_parallel: global_g.static_non_parallel
939938
has_reflection: 'v.reflection' in global_g.table.modules
940939
has_debugger: 'v.debug' in global_g.table.modules
941940
reflection_strings: global_g.reflection_strings
@@ -4918,7 +4917,7 @@ fn (mut g Gen) expr(node_ ast.Expr) {
49184917
g.write('(*')
49194918
g.expr(node.expr)
49204919
g.write(')')
4921-
} else if !handled_atomic_postfix && node.op == .question {
4920+
} else if node.op == .question {
49224921
mut expr_type := ast.void_type
49234922
if mut node.expr is ast.ComptimeSelector {
49244923
if node.expr.field_expr is ast.SelectorExpr
@@ -10807,6 +10806,29 @@ fn (mut g Gen) check_noscan(elem_typ ast.Type) string {
1080710806
return ''
1080810807
}
1080910808

10809+
fn (mut g Gen) write_heap_alloc(styp string, typ ast.Type) {
10810+
if g.pref.gc_mode == .vgc {
10811+
ptrmap, _ := g.vgc_ptrmap(typ)
10812+
if ptrmap.len > 0 {
10813+
g.write('HEAP_vgc(${styp}, (')
10814+
return
10815+
}
10816+
}
10817+
g.write('HEAP(${styp}, (')
10818+
}
10819+
10820+
// write_heap_alloc_close writes the closing part of a HEAP_vgc or HEAP call.
10821+
fn (mut g Gen) write_heap_alloc_close(typ ast.Type) {
10822+
if g.pref.gc_mode == .vgc {
10823+
ptrmap, nptrs := g.vgc_ptrmap(typ)
10824+
if ptrmap.len > 0 {
10825+
g.write('), ${ptrmap}, ${nptrs})')
10826+
return
10827+
}
10828+
}
10829+
g.write('))')
10830+
}
10831+
1081010832
// vgc_ptrmap computes a precise pointer bitmap for simple VGC heap allocations.
1081110833
fn (mut g Gen) vgc_ptrmap(typ ast.Type) (string, string) {
1081210834
if g.pref.gc_mode != .vgc {

vlib/v/gen/c/dumpexpr.v

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,10 @@ fn (mut g Gen) dump_expr(node ast.DumpExpr) {
241241
if expr_type.has_flag(.option_mut_param_t) {
242242
g.write('*')
243243
}
244-
if node.expr is ast.Ident && node.expr.obj is ast.Var && node.expr.obj.is_auto_deref
245-
&& !expr_type.is_ptr() {
246-
g.write('*')
244+
if node.expr is ast.Ident && node.expr.obj is ast.Var {
245+
if node.expr.obj.is_auto_deref && !expr_type.is_ptr() {
246+
g.write('*')
247+
}
247248
}
248249
for {
249250
if node.expr is ast.Ident {

vlib/v/gen/c/infix.v

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,6 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
264264
g.write(method_name)
265265
g.write('__eq')
266266
}
267-
mut is_builtin_or_alias_to_builtin := left.sym.is_builtin()
268-
if !has_alias_eq_op_overload && !is_builtin_or_alias_to_builtin
269-
&& left.sym.info is ast.Alias {
270-
alias_info := left.sym.info as ast.Alias
271-
parent_sym := g.table.sym(alias_info.parent_type)
272-
is_builtin_or_alias_to_builtin = parent_sym.is_builtin()
273-
}
274-
if is_builtin_or_alias_to_builtin {
275-
method_name = 'builtin__${method_name}'
276-
}
277-
mut eq_fn_name := '${method_name}__eq'
278-
eq_fn_name = g.specialized_method_name_from_receiver(eq_method, left.typ, eq_fn_name)
279-
g.write(eq_fn_name)
280267
g.write('(')
281268
g.write('*'.repeat(left.typ.nr_muls()))
282269
if eq_operator_expects_ptr {

0 commit comments

Comments
 (0)