Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into orm_mark_var_as_used
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 3, 2024
2 parents b590abc + 25ed636 commit 931ec77
Show file tree
Hide file tree
Showing 27 changed files with 444 additions and 173 deletions.
34 changes: 22 additions & 12 deletions cmd/tools/modules/vgit/vgit.v
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ pub fn clone_or_pull(remote_git_url string, local_worktree_path string) {
// Note: after clone_or_pull, the current repo branch is === HEAD === master
if os.is_dir(local_worktree_path) && os.is_dir(os.join_path_single(local_worktree_path, '.git')) {
// Already existing ... Just pulling in this case is faster usually.
scripting.run('git -C "${local_worktree_path}" checkout --quiet master')
scripting.run('git -C "${local_worktree_path}" pull --quiet ')
scripting.run('git -C "${local_worktree_path}" checkout --quiet master')
scripting.run('git -C "${local_worktree_path}" pull --quiet ')
} else {
// Clone a fresh local tree.
if remote_git_url.starts_with('http') {
// cloning an https remote with --filter=blob:none is usually much less bandwidth intensive, at the
// expense of doing small network ops later when using checkouts.
scripting.run('git clone --filter=blob:none --quiet "${remote_git_url}" "${local_worktree_path}" ')
scripting.run('git clone --filter=blob:none --quiet "${remote_git_url}" "${local_worktree_path}" ')
return
}
mut is_blobless_clone := false
Expand All @@ -112,7 +112,7 @@ pub fn clone_or_pull(remote_git_url string, local_worktree_path string) {
// at the expense of a little more space usage, which will make the new tree in local_worktree_path,
// exactly 1:1 the same, as the one in remote_git_url, just independent from it .
copy_cmd := if os.user_os() == 'windows' { 'robocopy /MIR' } else { 'rsync -a' }
scripting.run('${copy_cmd} "${remote_git_url}/" "${local_worktree_path}/"')
scripting.run('${copy_cmd} "${remote_git_url}/" "${local_worktree_path}/"')
return
}
scripting.run('git clone --quiet "${remote_git_url}" "${local_worktree_path}" ')
Expand All @@ -121,7 +121,8 @@ pub fn clone_or_pull(remote_git_url string, local_worktree_path string) {

pub struct VGitContext {
pub:
cc string = 'cc' // what compiler to use
cc string = 'cc' // what C compiler to use for bootstrapping
cc_options string // what additional C compiler options to use for bootstrapping
workdir string = '/tmp' // the base working folder
commit_v string = 'master' // the commit-ish that needs to be prepared
path_v string // where is the local working copy v repo
Expand Down Expand Up @@ -195,12 +196,16 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
mut c_flags := '-std=gnu11 -I ./thirdparty/stdatomic/nix -w'
mut c_ldflags := '-lm -lpthread'
mut vc_source_file_location := os.join_path_single(vgit_context.path_vc, 'v.c')
mut vc_v_bootstrap_flags := ''
mut vc_v_cpermissive_flags := '${vgit_context.cc_options} -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration -Wno-error=int-conversion'
// after 85b58b0 2021-09-28, -no-parallel is supported, and can be used to force the cgen stage to be single threaded, which increases the chances of successful bootstraps
mut vc_v_bootstrap_flags := ''
if vgit_context.commit_v__ts >= 1632778086 {
vc_v_bootstrap_flags += '-no-parallel'
vc_v_bootstrap_flags += ' -no-parallel'
}
scripting.verbose_trace(@FN, 'vc_v_bootstrap_flags: ${vc_v_bootstrap_flags} | vgit_context.commit_v__ts: ${vgit_context.commit_v__ts}')
vc_v_bootstrap_flags = vc_v_bootstrap_flags.trim_space()
scripting.verbose_trace(@FN, 'vc_v_bootstrap_flags: ${vc_v_bootstrap_flags}')
scripting.verbose_trace(@FN, 'vc_v_cpermissive_flags: ${vc_v_cpermissive_flags}')
scripting.verbose_trace(@FN, 'vgit_context.commit_v__ts: ${vgit_context.commit_v__ts}')

if 'windows' == os.user_os() {
c_flags = '-std=c99 -I ./thirdparty/stdatomic/win -w'
Expand All @@ -219,11 +224,11 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
if vgit_context.commit_v__ts >= 1699341818 && !vgit_context.cc.contains('msvc') {
c_flags += '-lws2_32'
}
command_for_building_v_from_c_source = '${vgit_context.cc} ${c_flags} -o cv.exe "${vc_source_file_location}" ${c_ldflags}'
command_for_selfbuilding = '.\\cv.exe ${vc_v_bootstrap_flags} -o ${vgit_context.vexename} {SOURCE}'
command_for_building_v_from_c_source = c(vgit_context.cc, '${vc_v_cpermissive_flags} ${c_flags} -o cv.exe "${vc_source_file_location}" ${c_ldflags}')
command_for_selfbuilding = c('.\\cv.exe', '${vc_v_bootstrap_flags} -o ${vgit_context.vexename} {SOURCE}')
} else {
command_for_building_v_from_c_source = '${vgit_context.cc} ${c_flags} -o cv "${vc_source_file_location}" ${c_ldflags}'
command_for_selfbuilding = './cv ${vc_v_bootstrap_flags} -o ${vgit_context.vexename} {SOURCE}'
command_for_building_v_from_c_source = c(vgit_context.cc, '${vc_v_cpermissive_flags} ${c_flags} -o cv "${vc_source_file_location}" ${c_ldflags}')
command_for_selfbuilding = c('./cv', '${vc_v_bootstrap_flags} -o ${vgit_context.vexename} {SOURCE}')
}

scripting.run(command_for_building_v_from_c_source)
Expand All @@ -233,6 +238,11 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
// which should be a valid working V executable.
}

fn c(cmd string, params string) string {
// compose a command, while reducing the potential whitespaces, due to all the interpolations of optional flags above
return '${cmd} ${params.trim_space()}'
}

pub struct VGitOptions {
pub mut:
workdir string = os.temp_dir() // the working folder (typically /tmp), where the tool will write
Expand Down
37 changes: 26 additions & 11 deletions cmd/tools/oldv.v
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ mut:
path_v string // the full path to the v folder inside workdir.
path_vc string // the full path to the vc folder inside workdir.
cmd_to_run string // the command that you want to run *in* the oldv repo
cleanup bool // should the tool run a cleanup first
use_cache bool // use local cached copies for --vrepo and --vcrepo in
fresh_tcc bool // do use `make fresh_tcc`
is_bisect bool // bisect mode; usage: `cmd/tools/oldv -b -c './v run bug.v'`
show_vccommit bool // show the V and VC commits, corresponding to the V commit-ish, that can be used to build V
cc string = 'cc' // the C compiler to use for bootstrapping.
cleanup bool // should the tool run a cleanup first
use_cache bool // use local cached copies for --vrepo and --vcrepo in
fresh_tcc bool // do use `make fresh_tcc`
is_bisect bool // bisect mode; usage: `cmd/tools/oldv -b -c './v run bug.v'`
show_vccommit bool // show the V and VC commits, corresponding to the V commit-ish, that can be used to build V
cc_options string // additional options to pass to the C compiler while bootstrapping.
}

fn (mut c Context) compile_oldv_if_needed() {
Expand All @@ -48,6 +49,7 @@ fn (mut c Context) compile_oldv_if_needed() {
v_repo_url: c.vgo.v_repo_url
vc_repo_url: c.vgo.vc_repo_url
cc: c.cc
cc_options: c.cc_options
commit_v: c.commit_v
path_v: c.path_v
path_vc: c.path_vc
Expand Down Expand Up @@ -103,7 +105,11 @@ fn sync_cache() {
}

fn main() {
scripting.used_tools_must_exist(['git'])
if os.user_os() == 'windows' {
scripting.used_tools_must_exist(['git', 'wc', 'make', 'robocopy'])
} else {
scripting.used_tools_must_exist(['git', 'wc', 'make', 'rsync', 'cc'])
}

// Resetting VEXE here allows for `v run cmd/tools/oldv.v'.
// the parent V would have set VEXE, which later will
Expand All @@ -126,19 +132,28 @@ fn main() {
context.vgo.v_repo_url = 'https://github.com/vlang/v'
context.vgo.vc_repo_url = 'https://github.com/vlang/vc'
}
should_sync := fp.bool('cache-sync', `s`, false, 'Update the local cache')
context.is_bisect = fp.bool('bisect', `b`, false, 'Bisect mode. Use the current commit in the repo where oldv is.')
if !should_sync && !context.is_bisect {
fp.limit_free_args(1, 1)!
context.cc = fp.string('cc', 0, 'cc', 'Use this C compiler for bootstrapping v.c (defaults to `cc`).')
context.cc_options = fp.string('ccoptions', 0, '', 'Use these C compiler options for bootstrapping v.c (defaults to ``).')
env_cc_options := os.getenv('OLDV_CCOPTIONS')
if env_cc_options != '' {
context.cc_options = env_cc_options
}
////
context.cleanup = fp.bool('clean', 0, false, 'Clean before running (slower).')
context.fresh_tcc = fp.bool('fresh_tcc', 0, true, 'Do `make fresh_tcc` when preparing a V compiler.')
context.cmd_to_run = fp.string('command', `c`, '', 'Command to run in the old V repo.\n')
context.show_vccommit = fp.bool('show_VC_commit', 0, false, 'Show the VC commit, that can be used to compile the given V commit, and exit.\n')
context.is_bisect = fp.bool('bisect', `b`, false, 'Bisect mode. Use the current commit in the repo where oldv is.')

should_sync := fp.bool('cache-sync', `s`, false, 'Update the local cache')
if !should_sync && !context.is_bisect {
fp.limit_free_args(1, 1)!
}

////
commits := vgit.add_common_tool_options(mut context.vgo, mut fp)
if should_sync {
sync_cache()
println('Cache synced, cache folder: ${cache_oldv_folder} .')
exit(0)
}
if context.use_cache {
Expand Down
13 changes: 11 additions & 2 deletions vlib/net/mbedtls/ssl_connection.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const ctr_drbg = C.mbedtls_ctr_drbg_context{}

const entropy = C.mbedtls_entropy_context{}

const mbedtls_client_read_timeout_ms = $d('mbedtls_client_read_timeout_ms', 550)
const mbedtls_server_read_timeout_ms = $d('mbedtls_server_read_timeout_ms', 41_000)

fn init() {
$if trace_ssl ? {
eprintln(@METHOD)
Expand Down Expand Up @@ -176,7 +179,10 @@ fn (mut l SSLListener) init() ! {
C.mbedtls_net_init(&l.server_fd)
C.mbedtls_ssl_init(&l.ssl)
C.mbedtls_ssl_config_init(&l.conf)
C.mbedtls_ssl_conf_read_timeout(&l.conf, 41_000)
$if trace_mbedtls_timeouts ? {
dump(mbedtls_server_read_timeout_ms)
}
C.mbedtls_ssl_conf_read_timeout(&l.conf, mbedtls_server_read_timeout_ms)
l.certs = &SSLCerts{}
C.mbedtls_x509_crt_init(&l.certs.client_cert)
C.mbedtls_pk_init(&l.certs.client_key)
Expand Down Expand Up @@ -371,7 +377,10 @@ fn (mut s SSLConn) init() ! {
if ret != 0 {
return error_with_code('Failed to set SSL configuration', ret)
}
C.mbedtls_ssl_conf_read_timeout(&s.conf, 550)
$if trace_mbedtls_timeouts ? {
dump(mbedtls_client_read_timeout_ms)
}
C.mbedtls_ssl_conf_read_timeout(&s.conf, mbedtls_client_read_timeout_ms)

unsafe {
C.mbedtls_ssl_conf_rng(&s.conf, C.mbedtls_ctr_drbg_random, &ctr_drbg)
Expand Down
3 changes: 2 additions & 1 deletion vlib/orm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ struct Foo {
- `[sql_type: 'SQL TYPE']` explicitly sets the type in SQL
- `[default: 'raw_sql']` inserts `raw_sql` verbatim in a "DEFAULT" clause when
creating a new table, allowing for SQL functions like `CURRENT_TIME`. For raw strings,
surround `raw_sql` with backticks (`).
surround `raw_sql` with backticks (\`).

- `[fkey: 'parent_id']` sets foreign key for an field which holds an array

## Usage
Expand Down
29 changes: 13 additions & 16 deletions vlib/os/os.v
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,24 @@ pub fn get_lines() []string {
// get_lines_joined returns a string of the values read from stdin.
// reading is stopped when an empty line is read.
pub fn get_lines_joined() string {
return get_lines().join('')
}

// get_raw_lines reads *all* input lines from stdin, as an array of strings.
// Note: unlike os.get_lines, empty lines (that contain only `\r\n` or `\n`),
// will be present in the output.
// Reading is stopped, only on EOF of stdin.
pub fn get_raw_lines() []string {
mut line := ''
mut inputstr := ''
mut lines := []string{}
for {
line = get_line()
line = get_raw_line()
if line.len <= 0 {
break
}
line = line.trim_space()
inputstr += line
lines << line
}
return inputstr
return lines
}

// get_raw_lines_joined reads *all* input lines from stdin.
Expand All @@ -390,17 +397,7 @@ pub fn get_lines_joined() string {
// the output.
// Reading is stopped, only on EOF of stdin.
pub fn get_raw_lines_joined() string {
mut line := ''
mut lines := []string{}
for {
line = get_raw_line()
if line.len <= 0 {
break
}
lines << line
}
res := lines.join('')
return res
return get_raw_lines().join('')
}

// user_os returns the current user's operating system name.
Expand Down
13 changes: 13 additions & 0 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -3637,6 +3637,19 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
}
}
node.return_type = ast.void_type
} else if method_name == 'delete_many' {
if node.args.len != 2 {
c.error('`.delete_many()` expected 2 arguments, but got ${node.args.len}',
node.pos)
} else {
for i, mut arg in node.args {
arg_typ := c.expr(mut arg.expr)
c.check_expected_call_arg(arg_typ, ast.int_type, node.language, arg) or {
c.error('${err.msg()} in argument ${i + 1} to `.delete_many()`', arg.pos)
}
}
}
node.return_type = ast.void_type
} else if method_name == 'reverse' {
c.table.used_features.arr_reverse = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vlib/v/checker/tests/generics_fn_return_generic_closure_err.vv:2:9: error: cannot use `fn (f64) []f64` as type `fn ([]f64) []f64` in return argument
1 | fn vectorize[T](op fn (T) T) fn ([]T) []T {
2 | return fn [op] [T](values T) []T {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 | mut result := []T{}
4 | return result
16 changes: 16 additions & 0 deletions vlib/v/checker/tests/generics_fn_return_generic_closure_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fn vectorize[T](op fn (T) T) fn ([]T) []T {
return fn [op] [T](values T) []T {
mut result := []T{}
return result
}
}

fn add_one(x f64) f64 {
return x + 1
}

fn main() {
vadd := vectorize[f64](add_one)
v := [1.0, 2, 3, 4]
println(vadd(v))
}
18 changes: 12 additions & 6 deletions vlib/v/gen/c/array.v
Original file line number Diff line number Diff line change
Expand Up @@ -1649,23 +1649,28 @@ fn (mut g Gen) fixed_array_init_with_cast(expr ast.ArrayInit, typ ast.Type) {
}
}

fn (mut g Gen) fixed_array_update_expr_field(expr_str string, field_type ast.Type, field_name string, is_auto_deref bool, elem_type ast.Type, size int) {
fn (mut g Gen) fixed_array_update_expr_field(expr_str string, field_type ast.Type, field_name string, is_auto_deref bool, elem_type ast.Type, size int, is_update_embed bool) {
elem_sym := g.table.sym(elem_type)
if !g.inside_array_fixed_struct {
g.write('{')
defer {
g.write('}')
}
}
embed_field := if is_update_embed {
g.get_embed_field_name(field_type, field_name)
} else {
''
}
for i in 0 .. size {
if elem_sym.info is ast.ArrayFixed {
init_str := if g.inside_array_fixed_struct {
'${expr_str}'
} else {
'${expr_str}->${c_name(field_name)}[${i}]'
'${expr_str}->${embed_field}${c_name(field_name)}[${i}]'
}
g.fixed_array_update_expr_field(init_str, field_type, field_name, is_auto_deref,
elem_sym.info.elem_type, elem_sym.info.size)
elem_sym.info.elem_type, elem_sym.info.size, is_update_embed)
} else {
g.write(expr_str)
if !expr_str.ends_with(']') {
Expand All @@ -1674,11 +1679,12 @@ fn (mut g Gen) fixed_array_update_expr_field(expr_str string, field_type ast.Typ
} else {
g.write('.')
}
if is_update_embed {
g.write(embed_field)
}
g.write(c_name(field_name))
}
if !expr_str.starts_with('(') && !expr_str.starts_with('{') {
g.write('[${i}]')
}
g.write('[${i}]')
}
if i != size - 1 {
g.write(', ')
Expand Down
Loading

0 comments on commit 931ec77

Please sign in to comment.