Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: add cmd/tools/show_ancient_deprecations.v, to cleanup ancient functionality, deprecated over an year ago #18946

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 72 additions & 0 deletions cmd/tools/show_ancient_deprecations.v
Original file line number Diff line number Diff line change
@@ -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}.')
}
2 changes: 1 addition & 1 deletion examples/sokol/sounds/wav_player.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions vlib/builtin/js/string.js.v
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,6 @@ pub fn (s string) trim_string_right(str string) string {
return s.clone()
}

// trim_prefix strips `str` from the start of the string.
// Example: assert 'WorldHello V'.trim_prefix('World') == 'Hello V'
[deprecated: 'use s.trim_string_left(x) instead']
[deprecated_after: '2022-01-19']
pub fn (s string) trim_prefix(str string) string {
return s.trim_string_left(str)
}

// trim_suffix strips `str` from the end of the string.
// Example: assert 'Hello VWorld'.trim_suffix('World') == 'Hello V'
[deprecated: 'use s.trim_string_right(x) instead']
[deprecated_after: '2022-01-19']
pub fn (s string) trim_suffix(str string) string {
return s.trim_string_right(str)
}

// compare_strings returns `-1` if `a < b`, `1` if `a > b` else `0`.
pub fn compare_strings(a &string, b &string) int {
if a < b {
Expand Down
16 changes: 0 additions & 16 deletions vlib/builtin/string.v
Original file line number Diff line number Diff line change
Expand Up @@ -1677,22 +1677,6 @@ pub fn (s string) trim_string_right(str string) string {
return s.clone()
}

// trim_prefix strips `str` from the start of the string.
// Example: assert 'WorldHello V'.trim_prefix('World') == 'Hello V'
[deprecated: 'use s.trim_string_left(x) instead']
[deprecated_after: '2022-01-19']
pub fn (s string) trim_prefix(str string) string {
return s.trim_string_left(str)
}

// trim_suffix strips `str` from the end of the string.
// Example: assert 'Hello VWorld'.trim_suffix('World') == 'Hello V'
[deprecated: 'use s.trim_string_right(x) instead']
[deprecated_after: '2022-01-19']
pub fn (s string) trim_suffix(str string) string {
return s.trim_string_right(str)
}

// compare_strings returns `-1` if `a < b`, `1` if `a > b` else `0`.
pub fn compare_strings(a &string, b &string) int {
if a < b {
Expand Down
13 changes: 0 additions & 13 deletions vlib/builtin/utf8.v
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,6 @@ pub fn utf32_decode_to_buffer(code u32, buf &u8) int {
return 0
}

// utf8_str_len returns the number of runes contained in the string.
[deprecated: 'use `string.len_utf8()` instead']
[deprecated_after: '2022-05-28']
pub fn utf8_str_len(s string) int {
mut l := 0
mut i := 0
for i < s.len {
l++
i += ((0xe5000000 >> ((unsafe { s.str[i] } >> 3) & 0x1e)) & 3) + 1
}
return l
}

// Convert utf8 to utf32
// the original implementation did not check for
// valid utf8 in the string, and could result in
Expand Down
13 changes: 0 additions & 13 deletions vlib/context/cancel.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
101 changes: 0 additions & 101 deletions vlib/gg/draw.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
9 changes: 0 additions & 9 deletions vlib/math/abs.v

This file was deleted.

4 changes: 2 additions & 2 deletions vlib/math/fractions/approximations.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
27 changes: 0 additions & 27 deletions vlib/net/http/http.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()')
}
5 changes: 1 addition & 4 deletions vlib/net/http/response.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions vlib/net/http/response_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -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'
}