Skip to content

Commit

Permalink
breaking,vlib: update handling of imports whose symbols are not direc…
Browse files Browse the repository at this point in the history
…tly used in imported file, remove `pub const is_used = 1` workarounds (#21160)
  • Loading branch information
ttytm authored Apr 1, 2024
1 parent 97e1b24 commit c086bee
Show file tree
Hide file tree
Showing 33 changed files with 30 additions and 102 deletions.
3 changes: 0 additions & 3 deletions examples/sokol/drawing.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sokol
import sokol.sapp
import sokol.gfx
import sokol.sgl
Expand All @@ -7,8 +6,6 @@ struct AppState {
pass_action gfx.PassAction
}

const used_import = sokol.used_import

fn main() {
state := &AppState{
pass_action: gfx.create_clear_pass_action(0.1, 0.1, 0.1, 1.0)
Expand Down
3 changes: 0 additions & 3 deletions examples/sokol/particles/particles.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
module main

import time
import sokol
import sokol.sapp
import sokol.gfx
import sokol.sgl
import particle

const used_import = sokol.used_import

fn main() {
mut app := &App{
width: 800
Expand Down
2 changes: 0 additions & 2 deletions vlib/fontstash/fontstash.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ $if windows {
pub type Context = C.FONScontext

//#flag -lfreetype
// TODO: fontstash.used_import is used to keep v from warning about unused imports
pub const used_import = 1
pub const invalid = C.FONS_INVALID

// create_internal returns a fontstash Context allocated on the heap.
Expand Down
4 changes: 1 addition & 3 deletions vlib/gx/text.c.v
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module gx

import fontstash

const used_import = fontstash.used_import
import fontstash as _

pub enum HorizontalAlign {
left = C.FONS_ALIGN_LEFT
Expand Down
2 changes: 0 additions & 2 deletions vlib/json/cjson/cjson_wrapper.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ pub:
// TODO: `@string &char` from above does not work. It should be fixed, at least inside `struct C.`.
}

pub const used = 1

pub type Node = C.cJSON

fn C.cJSON_Version() &char
Expand Down
2 changes: 0 additions & 2 deletions vlib/json/json_primitives.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module json
#include "cJSON.h"
#define js_get(object, key) cJSON_GetObjectItemCaseSensitive((object), (key))

pub const used = 1

pub struct C.cJSON {
valueint int
valuedouble f64
Expand Down
2 changes: 0 additions & 2 deletions vlib/net/mbedtls/mbedtls.c.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module mbedtls

pub const is_used = 1

#flag -I @VEXEROOT/thirdparty/mbedtls/library
#flag -I @VEXEROOT/thirdparty/mbedtls/include
// #flag -D _FILE_OFFSET_BITS=64
Expand Down
3 changes: 1 addition & 2 deletions vlib/net/mbedtls/mbedtls_compiles_test.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import net.mbedtls
import net.mbedtls as _

fn test_mbedtls_compiles() {
assert mbedtls.is_used == 1
assert true
}
2 changes: 0 additions & 2 deletions vlib/net/openssl/openssl.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ fn init() {
}
}

pub const is_used = true

// ssl_error returns non error ssl code or error if unrecoverable and we should panic
fn ssl_error(ret int, ssl voidptr) !SSLError {
res := C.SSL_get_error(ssl, ret)
Expand Down
7 changes: 1 addition & 6 deletions vlib/net/openssl/openssl_compiles_test.c.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import net.openssl
import net.openssl as _

struct Abc {
x &C.SSL_CTX
Expand All @@ -10,8 +10,3 @@ fn test_printing_struct_with_reference_field_of_type_ssl_ctx() {
sa := a.str()
assert sa.contains('&C.SSL_CTX(0x7b)')
}

fn test_openssl_compiles() {
assert openssl.is_used
assert true
}
2 changes: 0 additions & 2 deletions vlib/sokol/c/declaration.c.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module c

pub const used_import = 1

#flag -I @VEXEROOT/thirdparty/sokol
#flag -I @VEXEROOT/thirdparty/sokol/util
#flag freebsd -I /usr/local/include
Expand Down
6 changes: 2 additions & 4 deletions vlib/sokol/f/f.v
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module f

import fontstash
import sokol.c

pub const used_import = fontstash.used_import + c.used_import
import fontstash as _
import sokol.c as _

#flag linux -I.

Expand Down
4 changes: 1 addition & 3 deletions vlib/sokol/gfx/gfx.c.v
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module gfx

import sokol.c
import sokol.c as _
import sokol.memory

pub const version = 1

pub const used_import = c.used_import

// setup initialises the SOKOL's gfx library, based on the information passed in `desc`
pub fn setup(desc &Desc) {
if desc.allocator.alloc_fn == unsafe { nil } && desc.allocator.free_fn == unsafe { nil } {
Expand Down
2 changes: 0 additions & 2 deletions vlib/sokol/sapp/sapp.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module sapp
import sokol.gfx
import sokol.memory

pub const used_import = gfx.used_import

// Android needs a global reference to `g_desc`
__global g_desc C.sapp_desc

Expand Down
5 changes: 1 addition & 4 deletions vlib/sokol/sfons/sfons.c.v
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
module sfons

import fontstash
import sokol.f
import sokol.f as _
import sokol.memory

// keep v from warning about unused imports
const used_import = f.used_import + fontstash.used_import + 1

// create a new Context/font atlas, for rendering glyphs, given its dimensions `width` and `height`
@[inline]
pub fn create(width int, height int, flags int) &fontstash.Context {
Expand Down
22 changes: 9 additions & 13 deletions vlib/sokol/sokol.v
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
module sokol

import sokol.c
import sokol.f
import sokol.c as _
import sokol.f as _

pub const used_import = c.used_import + f.used_import

/*
pub enum Key {
up=C.SAPP_KEYCODE_UP
left = C.SAPP_KEYCODE_LEFT
right =C.SAPP_KEYCODE_RIGHT
down = C.SAPP_KEYCODE_DOWN
/* pub enum Key {
up = C.SAPP_KEYCODE_UP
left = C.SAPP_KEYCODE_LEFT
right = C.SAPP_KEYCODE_RIGHT
down = C.SAPP_KEYCODE_DOWN
escape = C.SAPP_KEYCODE_ESCAPE
space = C.SAPP_KEYCODE_SPACE
}
*/
space = C.SAPP_KEYCODE_SPACE
} */
3 changes: 0 additions & 3 deletions vlib/sync/channels.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ module sync

import time
import rand
import sync.stdatomic

const aops_used = stdatomic.used

// how often to try to get data without blocking before to wait for semaphore
const spinloops = 750
Expand Down
2 changes: 0 additions & 2 deletions vlib/sync/stdatomic/1.declarations.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,3 @@ fn C.atomic_compare_exchange_strong_u64(voidptr, voidptr, u64) bool
fn C.atomic_exchange_u64(voidptr, u64) u64
fn C.atomic_fetch_add_u64(voidptr, u64) u64
fn C.atomic_fetch_sub_u64(voidptr, u64) u64

pub const used = 1
2 changes: 1 addition & 1 deletion vlib/v/checker/tests/import_mod_as_duplicate_err.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ vlib/v/checker/tests/import_mod_as_duplicate_err.vv:3:16: error: cannot import `
3 | import json as json2
| ~~~~~
4 |
5 | const used = true
5 | _ := json2.encode('foo')
vlib/v/checker/tests/import_mod_as_duplicate_err.vv:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
1 | module json2
| ^
Expand Down
4 changes: 1 addition & 3 deletions vlib/v/checker/tests/import_mod_as_duplicate_err.vv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ module json2

import json as json2

const used = true

println(json2.used)
_ := json2.encode('foo')
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module module_with_redeclaration

import sokol.memory

pub const used = 1

@[typedef]
pub struct C.saudio_allocator {
pub mut:
Expand Down
2 changes: 0 additions & 2 deletions vlib/v/embed_file/embed_file.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module embed_file

pub const is_used = 1

// EmbedFileData encapsulates functionality for the `$embed_file()` compile time call.
pub struct EmbedFileData {
apath string
Expand Down
4 changes: 1 addition & 3 deletions vlib/v/gen/c/testdata/gui_windows_program.vv
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// vtest vflags: -os windows
import sokol

const used_import = sokol.used_import
import sokol as _

fn main() {
println('hello world')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// vtest vflags: -os windows
import sokol

const used_import = sokol.used_import
import sokol as _

@[console]
fn main() {
Expand Down
2 changes: 0 additions & 2 deletions vlib/v/live/common.c.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module live

pub const is_used = 1

pub type FNLinkLiveSymbols = fn (linkcb voidptr)

pub type FNLiveReloadCB = fn (info &LiveReloadInfo)
Expand Down
2 changes: 0 additions & 2 deletions vlib/v/live/executable/reloader.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import time
import dl
import v.live

pub const is_used = 1

// The live reloader code is implemented here.
// Note: new_live_reload_info will be called by generated C code inside main()
@[markused]
Expand Down
4 changes: 1 addition & 3 deletions vlib/v/live/sharedlib/live_sharedlib.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module sharedlib

import v.live

pub const is_used = live.is_used + 1
import v.live as _
6 changes: 2 additions & 4 deletions vlib/v/preludes/embed_file/embed_file.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module embed_file

// This prelude is loaded in every v program that uses `$embed_file`,
// in both the main executable, and in the shared library.
import v.embed_file
module embed_file

const no_warning_embed_file_is_used = embed_file.is_used
import v.embed_file as _
6 changes: 2 additions & 4 deletions vlib/v/preludes/live.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module main

// This prelude is loaded in every v program compiled with -live,
// in both the main executable, and in the shared library.
import v.live
module main

const no_warning_live_is_used = live.is_used
import v.live as _
6 changes: 2 additions & 4 deletions vlib/v/preludes/live_main.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module main

// This prelude is loaded in every v program compiled with -live,
// but only for the main executable.
import v.live.executable
module main

const no_warning_live_executable_is_used = executable.is_used
import v.live.executable as _
6 changes: 2 additions & 4 deletions vlib/v/preludes/live_shared.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module main

// This prelude is loaded in every v program compiled with -live,
// but only for the shared library.
import v.live.sharedlib
module main

const no_warning_live_shared_is_used = sharedlib.is_used
import v.live.sharedlib as _
4 changes: 1 addition & 3 deletions vlib/v/preludes/trace_calls.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module main

import v.trace_calls

const trace_calls_used = trace_calls.is_used
import v.trace_calls as _
2 changes: 0 additions & 2 deletions vlib/v/trace_calls/tracing_calls.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module trace_calls
__global g_stack_base = &u8(0)
__global g_start_time = u64(0)

pub const is_used = 1

@[markused]
pub fn on_call(fname string) {
mut volatile pfbase := unsafe { &u8(0) }
Expand Down

0 comments on commit c086bee

Please sign in to comment.