From 41f99c1abf556dfcbaf2296ea916ec8c260f9698 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 22 Jul 2023 19:13:58 +0300 Subject: [PATCH] tools: add cmd/tools/show_ancient_deprecations.v, to cleanup ancient functionality, deprecated over an year ago (#18946) --- cmd/tools/show_ancient_deprecations.v | 72 ++++++++++++++++++ examples/sokol/sounds/wav_player.v | 2 +- vlib/context/cancel.v | 13 ---- vlib/gg/draw.c.v | 101 -------------------------- vlib/math/abs.v | 9 --- vlib/math/fractions/approximations.v | 4 +- vlib/net/http/http.v | 27 ------- vlib/net/http/response.v | 5 +- vlib/net/http/response_test.v | 3 +- 9 files changed, 77 insertions(+), 159 deletions(-) create mode 100644 cmd/tools/show_ancient_deprecations.v delete mode 100644 vlib/math/abs.v diff --git a/cmd/tools/show_ancient_deprecations.v b/cmd/tools/show_ancient_deprecations.v new file mode 100644 index 0000000000..d68256cbcb --- /dev/null +++ b/cmd/tools/show_ancient_deprecations.v @@ -0,0 +1,72 @@ +import os +import time + +struct Context { +mut: + cut_time time.Time + deprecations int +} + +fn (mut ctx Context) analyze_line(line string, position_file string, position_line int) { + blame_for_time := os.execute('git blame -L${position_line} --porcelain -- ${position_file}') + if blame_for_time.exit_code != 0 { + return + } + ts := blame_for_time.output.all_after('committer-time').all_before('\n').trim_space().int() + t := time.unix(ts) + if ctx.cut_time < t { + println('>>> SKIPPING since t: ${t} > ${ctx.cut_time}, line: ${line}') + return + } + ctx.deprecations++ + blame_for_context := os.execute('git blame -L${position_line},+5 -- ${position_file}') + context := blame_for_context.output.trim_space().split_into_lines() + println('${position_file}:${position_line}: deprecation: ${ctx.deprecations}, timestamp: ${ts} - ${t}') + for cline in context { + println(' ${cline}') + } +} + +fn main() { + if os.args.len < 2 { + eprintln('Usage: v run cmd/tools/show_ancient_deprecations.v [DAYS]') + exit(1) + } + cut_months := os.args[1].int() + cut_time := time.now().add(-cut_months * 24 * time.hour) + mut ctx := Context{ + cut_time: cut_time + } + println('> Deprecations that happened before ${cut_time}') + all_v_files := os.walk_ext('.', '.v') + for v_file in all_v_files { + if v_file == './vlib/v/fmt/tests/attrs_keep.vv' { + println('>>> SKIPPING deprecations attrs formatting test file ${v_file}') + continue + } + if v_file.starts_with('./vlib/v/checker/tests') && v_file.contains('deprec') { + println('>>> SKIPPING deprecations test file ${v_file}') + continue + } + file_content := os.read_file(v_file)! + if !file_content.contains('[deprecated') { + continue + } + lines := file_content.split_into_lines() + for line_num := lines.len - 1; line_num > 0; line_num-- { + line := lines[line_num] + mut is_deprecation_line := false + if line.contains('[deprecated:') { + is_deprecation_line = true + } + if line.contains('[deprecated]') { + is_deprecation_line = true + } + if !is_deprecation_line { + continue + } + ctx.analyze_line(line, v_file, line_num + 1) + } + } + println('> Summary: there were ${ctx.deprecations} deprecations found, done before ${cut_time}.') +} diff --git a/examples/sokol/sounds/wav_player.v b/examples/sokol/sounds/wav_player.v index a0a6eee00e..f8b35c16d3 100644 --- a/examples/sokol/sounds/wav_player.v +++ b/examples/sokol/sounds/wav_player.v @@ -134,7 +134,7 @@ fn read_wav_file_samples(fpath string) ![]f32 { return error('WAV should have valid length') } offset += sizeof(RIFFHeader) - mut rf := &RIFFFormat(0) + mut rf := &RIFFFormat(unsafe { nil }) for { if offset >= bytes.len { break diff --git a/vlib/context/cancel.v b/vlib/context/cancel.v index 9c23a2d053..c05b70b8cc 100644 --- a/vlib/context/cancel.v +++ b/vlib/context/cancel.v @@ -17,19 +17,6 @@ mut: done() chan int } -[deprecated] -pub fn cancel(mut ctx Context) { - match mut ctx { - CancelContext { - ctx.cancel(true, canceled) - } - TimerContext { - ctx.cancel(true, canceled) - } - else {} - } -} - // A CancelContext can be canceled. When canceled, it also cancels any children // that implement Canceler. pub struct CancelContext { diff --git a/vlib/gg/draw.c.v b/vlib/gg/draw.c.v index 90d9dc4c10..c14034c94e 100644 --- a/vlib/gg/draw.c.v +++ b/vlib/gg/draw.c.v @@ -958,104 +958,3 @@ pub fn (ctx &Context) draw_cubic_bezier_in_steps(points []f32, steps u32, c gx.C sgl.end() } - -//---- deprecated - -// Sets a pixel -[deprecated: 'use draw_pixel() instead'] -pub fn (ctx &Context) set_pixel(x f32, y f32, c gx.Color) { - ctx.draw_pixel(x, y, c) -} - -[deprecated: 'use draw_pixels() instead'] -pub fn (ctx &Context) set_pixels(points []f32, c gx.Color) { - ctx.draw_pixels(points, c) -} - -[deprecated: 'use draw_poly_empty() instead'] -pub fn (ctx &Context) draw_empty_poly(points []f32, c gx.Color) { - ctx.draw_poly_empty(points, c) -} - -// TODO: Fix alpha -[deprecated: 'use draw_rect_filled() instead'] -pub fn (ctx &Context) draw_rect(x f32, y f32, w f32, h f32, c gx.Color) { - ctx.draw_rect_filled(x, y, w, h, c) -} - -// Draws the outline of a rectangle -[deprecated: 'use draw_rect_empty() instead'] -pub fn (ctx &Context) draw_empty_rect(x f32, y f32, w f32, h f32, c gx.Color) { - ctx.draw_rect_empty(x, y, w, h, c) -} - -[deprecated: 'use draw_rounded_rect_empty()'] -pub fn (ctx &Context) draw_empty_rounded_rect(x f32, y f32, w f32, h f32, radius f32, c gx.Color) { - ctx.draw_rounded_rect_empty(x, y, w, h, radius, c) -} - -[deprecated: 'use draw_rounded_rect_filled()'] -pub fn (ctx &Context) draw_rounded_rect(x f32, y f32, w f32, h f32, radius f32, c gx.Color) { - ctx.draw_rounded_rect_filled(x, y, w, h, radius, c) -} - -// Draws the outline of a triangle -[deprecated: 'use draw_triangle_empty() instead'] -pub fn (ctx &Context) draw_empty_triangle(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, c gx.Color) { - ctx.draw_triangle_empty(x, y, x2, y2, x3, y3, c) -} - -// Draws a filled triangle -[deprecated: 'use draw_triangle_filled() instead'] -pub fn (ctx &Context) draw_triangle(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, c gx.Color) { - ctx.draw_triangle_filled(x, y, x2, y2, x3, y3, c) -} - -// Draws the outline of a square -[deprecated: 'use draw_square_empty() instead'] -pub fn (ctx &Context) draw_empty_square(x f32, y f32, s f32, c gx.Color) { - ctx.draw_square_empty(x, y, s, c) -} - -// Draws a filled square -[deprecated: 'use draw_square_filled() instead'] -pub fn (ctx &Context) draw_square(x f32, y f32, s f32, c gx.Color) { - ctx.draw_square_filled(x, y, s, c) -} - -[deprecated: 'use draw_circle_filled() instead'] -pub fn (ctx &Context) draw_circle(x f32, y f32, radius f32, c gx.Color) { - ctx.draw_circle_filled(x, y, radius, c) -} - -[deprecated: 'use draw_slice_empty() instead'] -pub fn (ctx &Context) draw_empty_slice(x f32, y f32, radius f32, start_angle f32, end_angle f32, segments int, c gx.Color) { - ctx.draw_slice_empty(x, y, radius, start_angle, end_angle, segments, c) -} - -[deprecated: 'use draw_slice_filled() instead'] -pub fn (ctx &Context) draw_slice(x f32, y f32, radius f32, start_angle f32, end_angle f32, segments int, c gx.Color) { - ctx.draw_slice_filled(x, y, radius, start_angle, end_angle, segments, c) -} - -[deprecated: 'use draw_arc_empty() instead'] -pub fn (ctx &Context) draw_empty_arc(x f32, y f32, inner_radius f32, thickness f32, start_angle f32, end_angle f32, segments int, c gx.Color) { - ctx.draw_arc_empty(x, y, inner_radius, thickness, start_angle, end_angle, segments, - c) -} - -[deprecated: 'use draw_arc_filled() instead'] -pub fn (ctx &Context) draw_arc(x f32, y f32, inner_radius f32, thickness f32, start_angle f32, end_angle f32, segments int, c gx.Color) { - ctx.draw_arc_filled(x, y, inner_radius, thickness, start_angle, end_angle, segments, - c) -} - -[deprecated: 'use draw_ellipse_empty() instead'] -pub fn (ctx &Context) draw_empty_ellipse(x f32, y f32, rw f32, rh f32, c gx.Color) { - ctx.draw_ellipse_empty(x, y, rw, rh, c) -} - -[deprecated: 'use draw_ellipse_filled() instead'] -pub fn (ctx &Context) draw_ellipse(x f32, y f32, rw f32, rh f32, c gx.Color) { - ctx.draw_ellipse_filled(x, y, rw, rh, c) -} diff --git a/vlib/math/abs.v b/vlib/math/abs.v deleted file mode 100644 index b6ad2efcf0..0000000000 --- a/vlib/math/abs.v +++ /dev/null @@ -1,9 +0,0 @@ -module math - -[deprecated: 'use math.abs() instead'] -pub fn fabs(x f64) f64 { - if x > 0.0 { - return x - } - return -x -} diff --git a/vlib/math/fractions/approximations.v b/vlib/math/fractions/approximations.v index 56082ef829..9d9faa6d63 100644 --- a/vlib/math/fractions/approximations.v +++ b/vlib/math/fractions/approximations.v @@ -84,7 +84,7 @@ pub fn approximate_with_eps(val f64, eps f64) Fraction { if eps < 0.0 { panic('Epsilon value cannot be negative.') } - if math.fabs(val) > math.max_i64 { + if math.abs(val) > math.max_i64 { panic('Value out of range.') } // The integer part is separated first. Then we process the fractional @@ -110,7 +110,7 @@ pub fn approximate_with_eps(val f64, eps f64) Fraction { // eval_cf is called often so it needs to be performant partial = eval_cf(whole, d) // Check if we're done - if math.fabs(val - partial.f64()) < eps { + if math.abs(val - partial.f64()) < eps { return partial } frac -= f64(den) diff --git a/vlib/net/http/http.v b/vlib/net/http/http.v index 77bfe16a5c..0d470e4ab7 100644 --- a/vlib/net/http/http.v +++ b/vlib/net/http/http.v @@ -179,13 +179,6 @@ pub fn url_encode_form_data(data map[string]string) string { return pieces.join('&') } -[deprecated: 'use fetch()'] -fn fetch_with_method(method Method, _config FetchConfig) !Response { - mut config := _config - config.method = method - return fetch(config) -} - fn build_url_from_fetch(config FetchConfig) !string { mut url := urllib.parse(config.url)! if config.params.len == 0 { @@ -202,23 +195,3 @@ fn build_url_from_fetch(config FetchConfig) !string { url.raw_query = query return url.str() } - -[deprecated: 'unescape_url is deprecated, use urllib.query_unescape() instead'] -pub fn unescape_url(s string) string { - panic('http.unescape_url() was replaced with urllib.query_unescape()') -} - -[deprecated: 'escape_url is deprecated, use urllib.query_escape() instead'] -pub fn escape_url(s string) string { - panic('http.escape_url() was replaced with urllib.query_escape()') -} - -[deprecated: 'unescape is deprecated, use urllib.query_escape() instead'] -pub fn unescape(s string) string { - panic('http.unescape() was replaced with http.unescape_url()') -} - -[deprecated: 'escape is deprecated, use urllib.query_unescape() instead'] -pub fn escape(s string) string { - panic('http.escape() was replaced with http.escape_url()') -} diff --git a/vlib/net/http/response.v b/vlib/net/http/response.v index 10720efd1a..5466d66d77 100644 --- a/vlib/net/http/response.v +++ b/vlib/net/http/response.v @@ -10,7 +10,6 @@ import strconv pub struct Response { pub mut: body string - text string [deprecated: 'use Response.body instead'; deprecated_after: '2022-10-03'] header Header status_code int status_msg string @@ -50,7 +49,6 @@ pub fn parse_response(resp string) !Response { status_msg: status_msg header: header body: body - text: body // TODO: remove as depreciated } } @@ -118,14 +116,13 @@ pub struct ResponseConfig { status Status = .ok header Header body string - text string [deprecated: 'use ResponseConfig.body instead'; deprecated_after: '2022-10-03'] } // new_response creates a Response object from the configuration. This // function will add a Content-Length header if body is not empty. pub fn new_response(conf ResponseConfig) Response { mut resp := Response{ - body: conf.body + conf.text + body: conf.body header: conf.header } if resp.body.len > 0 && !resp.header.contains(.content_length) { diff --git a/vlib/net/http/response_test.v b/vlib/net/http/response_test.v index d6d22e65e1..7ca386e0ec 100644 --- a/vlib/net/http/response_test.v +++ b/vlib/net/http/response_test.v @@ -3,7 +3,7 @@ module http fn test_response_bytestr_1() { resp := new_response( status: .ok - text: 'Foo' // TODO: replace with `body` once deprecaped + body: 'Foo' ) assert resp.bytestr() == 'HTTP/1.1 200 OK\r\n' + 'Content-Length: 3\r\n' + '\r\n' + 'Foo' } @@ -43,5 +43,4 @@ fn test_parse_response() { assert x.header.contains(.content_length) assert x.header.get(.content_length)! == '3' assert x.body == 'Foo' - assert x.text == 'Foo' }