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

cgen: add autofree comptime check #21197

Merged
merged 2 commits into from
Apr 7, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vlib/v/ast/comptime_valid_idents.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub const valid_comptime_if_cpu_features = ['x64', 'x32', 'little_endian', 'big_
pub const valid_comptime_if_other = ['apk', 'js', 'debug', 'prod', 'test', 'glibc', 'prealloc',
'no_bounds_checking', 'freestanding', 'threads', 'js_node', 'js_browser', 'js_freestanding',
'interpreter', 'es5', 'profile', 'wasm32', 'wasm32_emscripten', 'wasm32_wasi', 'fast_math',
'native']
'native', 'autofree']
pub const valid_comptime_not_user_defined = all_valid_comptime_idents()
pub const valid_comptime_compression_types = ['none', 'zlib']

Expand Down
3 changes: 3 additions & 0 deletions vlib/v/checker/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,9 @@ fn (mut c Checker) comptime_if_branch(mut cond ast.Expr, pos token.Pos) Comptime
'no_bounds_checking' {
return if cname in c.pref.compile_defines_all { .eval } else { .skip }
}
'autofree' {
return if c.pref.autofree { .eval } else { .skip }
}
'freestanding' {
return if c.pref.is_bare && !c.pref.output_cross_c { .eval } else { .skip }
}
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/gen/c/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,9 @@ fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_option bool) !strin
'freestanding' {
return '_VFREESTANDING'
}
'autofree' {
return '_VAUTOFREE'
}
// architectures:
'amd64' {
return '__V_amd64'
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/gen/js/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ fn (mut g JsGen) comptime_if_to_ifdef(name string, is_comptime_option bool) !str
'freestanding' {
return '_VFREESTANDING'
}
'autofree' {
return '_VAUTOFREE'
}
// architectures:
'amd64' {
return '(\$process.arch == "x64")'
Expand Down