all: rename `[ref_only]` -> `[heap]` (#8718)
parent
2a8d0ddaf5
commit
374739b804
|
@ -3866,8 +3866,9 @@ fn old_function() {
|
||||||
fn inlined_function() {
|
fn inlined_function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following struct can only be used as a reference (`&Window`) and allocated on the heap.
|
// The following struct must be allocated on the heap. Therefore, it can only be used as a
|
||||||
[ref_only]
|
// reference (`&Window`) or inside another reference (`&OuterStruct{ Window{...} }`).
|
||||||
|
[heap]
|
||||||
struct Window {
|
struct Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ enum CloseTagType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tag holds the information of an HTML tag.
|
// Tag holds the information of an HTML tag.
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub enum ProcessState {
|
||||||
aborted
|
aborted
|
||||||
}
|
}
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct Process {
|
pub struct Process {
|
||||||
pub:
|
pub:
|
||||||
filename string // the process's command file path
|
filename string // the process's command file path
|
||||||
|
|
|
@ -28,12 +28,12 @@ fn C.sem_timedwait(voidptr, voidptr) int
|
||||||
fn C.sem_destroy(voidptr) int
|
fn C.sem_destroy(voidptr) int
|
||||||
|
|
||||||
// [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
|
// [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct Mutex {
|
pub struct Mutex {
|
||||||
mutex C.pthread_mutex_t
|
mutex C.pthread_mutex_t
|
||||||
}
|
}
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct RwMutex {
|
pub struct RwMutex {
|
||||||
mutex C.pthread_rwlock_t
|
mutex C.pthread_rwlock_t
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ struct RwMutexAttr {
|
||||||
attr C.pthread_rwlockattr_t
|
attr C.pthread_rwlockattr_t
|
||||||
}
|
}
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
struct Semaphore {
|
struct Semaphore {
|
||||||
sem C.sem_t
|
sem C.sem_t
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,12 +31,12 @@ fn C.pthread_cond_timedwait(voidptr, voidptr, voidptr) int
|
||||||
fn C.pthread_cond_destroy(voidptr) int
|
fn C.pthread_cond_destroy(voidptr) int
|
||||||
|
|
||||||
// [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
|
// [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct Mutex {
|
pub struct Mutex {
|
||||||
mutex C.pthread_mutex_t
|
mutex C.pthread_mutex_t
|
||||||
}
|
}
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct RwMutex {
|
pub struct RwMutex {
|
||||||
mutex C.pthread_rwlock_t
|
mutex C.pthread_rwlock_t
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ struct CondAttr {
|
||||||
|
|
||||||
/* MacOSX has no unnamed semaphores and no `timed_wait()` at all
|
/* MacOSX has no unnamed semaphores and no `timed_wait()` at all
|
||||||
so we emulate the behaviour with other devices */
|
so we emulate the behaviour with other devices */
|
||||||
[ref_only]
|
[heap]
|
||||||
struct Semaphore {
|
struct Semaphore {
|
||||||
mtx C.pthread_mutex_t
|
mtx C.pthread_mutex_t
|
||||||
cond C.pthread_cond_t
|
cond C.pthread_cond_t
|
||||||
|
|
|
@ -22,19 +22,19 @@ type SHANDLE = voidptr
|
||||||
//[init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
|
//[init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
|
||||||
|
|
||||||
// `SRWLOCK` is much more performant that `Mutex` on Windows, so use that in both cases since we don't want to share with other processes
|
// `SRWLOCK` is much more performant that `Mutex` on Windows, so use that in both cases since we don't want to share with other processes
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct Mutex {
|
pub struct Mutex {
|
||||||
mut:
|
mut:
|
||||||
mx C.SRWLOCK // mutex handle
|
mx C.SRWLOCK // mutex handle
|
||||||
}
|
}
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct RwMutex {
|
pub struct RwMutex {
|
||||||
mut:
|
mut:
|
||||||
mx C.SRWLOCK // mutex handle
|
mx C.SRWLOCK // mutex handle
|
||||||
}
|
}
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
struct Semaphore {
|
struct Semaphore {
|
||||||
mtx C.SRWLOCK
|
mtx C.SRWLOCK
|
||||||
cond C.CONDITION_VARIABLE
|
cond C.CONDITION_VARIABLE
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn C.atomic_fetch_add_u32(voidptr, u32) u32
|
||||||
// `wg.done()` when finished
|
// `wg.done()` when finished
|
||||||
//
|
//
|
||||||
// [init_with=new_waitgroup] // TODO: implement support for init_with struct attribute, and disallow WaitGroup{} from outside the sync.new_waitgroup() function.
|
// [init_with=new_waitgroup] // TODO: implement support for init_with struct attribute, and disallow WaitGroup{} from outside the sync.new_waitgroup() function.
|
||||||
[ref_only]
|
[heap]
|
||||||
struct WaitGroup {
|
struct WaitGroup {
|
||||||
mut:
|
mut:
|
||||||
task_count u32 // current task count - reading/writing should be atomic
|
task_count u32 // current task count - reading/writing should be atomic
|
||||||
|
|
|
@ -399,8 +399,8 @@ pub fn (mut c Checker) struct_decl(mut decl ast.StructDecl) {
|
||||||
c.error('`$embed_sym.name` is not a struct', embed.pos)
|
c.error('`$embed_sym.name` is not a struct', embed.pos)
|
||||||
} else {
|
} else {
|
||||||
info := embed_sym.info as table.Struct
|
info := embed_sym.info as table.Struct
|
||||||
if info.is_ref_only && !embed.typ.is_ptr() {
|
if info.is_heap && !embed.typ.is_ptr() {
|
||||||
struct_sym.info.is_ref_only = true
|
struct_sym.info.is_heap = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,8 +443,8 @@ pub fn (mut c Checker) struct_decl(mut decl ast.StructDecl) {
|
||||||
}
|
}
|
||||||
if sym.kind == .struct_ {
|
if sym.kind == .struct_ {
|
||||||
info := sym.info as table.Struct
|
info := sym.info as table.Struct
|
||||||
if info.is_ref_only && !field.typ.is_ptr() {
|
if info.is_heap && !field.typ.is_ptr() {
|
||||||
struct_sym.info.is_ref_only = true
|
struct_sym.info.is_heap = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sym.kind == .map {
|
if sym.kind == .map {
|
||||||
|
@ -543,7 +543,7 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
|
||||||
c.error('struct `$type_sym.name` is declared with a `[noinit]` attribute, so ' +
|
c.error('struct `$type_sym.name` is declared with a `[noinit]` attribute, so ' +
|
||||||
'it cannot be initialized with `$type_sym.name{}`', struct_init.pos)
|
'it cannot be initialized with `$type_sym.name{}`', struct_init.pos)
|
||||||
}
|
}
|
||||||
if info.is_ref_only && !c.inside_ref_lit && !c.inside_unsafe && !struct_init.typ.is_ptr() {
|
if info.is_heap && !c.inside_ref_lit && !c.inside_unsafe && !struct_init.typ.is_ptr() {
|
||||||
c.error('`$type_sym.name` type can only be used as a reference `&$type_sym.name` or inside a `struct` reference',
|
c.error('`$type_sym.name` type can only be used as a reference `&$type_sym.name` or inside a `struct` reference',
|
||||||
struct_init.pos)
|
struct_init.pos)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
vlib/v/checker/tests/ref_only_struct.vv:18:7: error: `Abc` type can only be used as a reference `&Abc` or inside a `struct` reference
|
vlib/v/checker/tests/heap_struct.vv:18:7: error: `Abc` type can only be used as a reference `&Abc` or inside a `struct` reference
|
||||||
16 |
|
16 |
|
||||||
17 | fn main() {
|
17 | fn main() {
|
||||||
18 | a := Abc{ n: 3 }
|
18 | a := Abc{ n: 3 }
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
19 | b := St{
|
19 | b := St{
|
||||||
20 | Abc{ n: 7 }
|
20 | Abc{ n: 7 }
|
||||||
vlib/v/checker/tests/ref_only_struct.vv:19:7: error: `St` type can only be used as a reference `&St` or inside a `struct` reference
|
vlib/v/checker/tests/heap_struct.vv:19:7: error: `St` type can only be used as a reference `&St` or inside a `struct` reference
|
||||||
17 | fn main() {
|
17 | fn main() {
|
||||||
18 | a := Abc{ n: 3 }
|
18 | a := Abc{ n: 3 }
|
||||||
19 | b := St{
|
19 | b := St{
|
||||||
| ~~~
|
| ~~~
|
||||||
20 | Abc{ n: 7 }
|
20 | Abc{ n: 7 }
|
||||||
21 | }
|
21 | }
|
||||||
vlib/v/checker/tests/ref_only_struct.vv:20:3: error: `Abc` type can only be used as a reference `&Abc` or inside a `struct` reference
|
vlib/v/checker/tests/heap_struct.vv:20:3: error: `Abc` type can only be used as a reference `&Abc` or inside a `struct` reference
|
||||||
18 | a := Abc{ n: 3 }
|
18 | a := Abc{ n: 3 }
|
||||||
19 | b := St{
|
19 | b := St{
|
||||||
20 | Abc{ n: 7 }
|
20 | Abc{ n: 7 }
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
21 | }
|
21 | }
|
||||||
22 | x := Qwe{
|
22 | x := Qwe{
|
||||||
vlib/v/checker/tests/ref_only_struct.vv:22:7: error: `Qwe` type can only be used as a reference `&Qwe` or inside a `struct` reference
|
vlib/v/checker/tests/heap_struct.vv:22:7: error: `Qwe` type can only be used as a reference `&Qwe` or inside a `struct` reference
|
||||||
20 | Abc{ n: 7 }
|
20 | Abc{ n: 7 }
|
||||||
21 | }
|
21 | }
|
||||||
22 | x := Qwe{
|
22 | x := Qwe{
|
||||||
| ~~~~
|
| ~~~~
|
||||||
23 | f: 12.25
|
23 | f: 12.25
|
||||||
24 | a: Abc{ n: 23 }
|
24 | a: Abc{ n: 23 }
|
||||||
vlib/v/checker/tests/ref_only_struct.vv:24:6: error: `Abc` type can only be used as a reference `&Abc` or inside a `struct` reference
|
vlib/v/checker/tests/heap_struct.vv:24:6: error: `Abc` type can only be used as a reference `&Abc` or inside a `struct` reference
|
||||||
22 | x := Qwe{
|
22 | x := Qwe{
|
||||||
23 | f: 12.25
|
23 | f: 12.25
|
||||||
24 | a: Abc{ n: 23 }
|
24 | a: Abc{ n: 23 }
|
|
@ -1,4 +1,4 @@
|
||||||
[ref_only]
|
[heap]
|
||||||
struct Abc {
|
struct Abc {
|
||||||
mut:
|
mut:
|
||||||
n int
|
n int
|
|
@ -14,7 +14,7 @@ pub type ScrollFn = fn (e ScrollEvent, func voidptr)
|
||||||
|
|
||||||
pub type MouseMoveFn = fn (e MouseMoveEvent, func voidptr)
|
pub type MouseMoveFn = fn (e MouseMoveEvent, func voidptr)
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
pub mut:
|
pub mut:
|
||||||
ui &UI = voidptr(0)
|
ui &UI = voidptr(0)
|
||||||
|
|
|
@ -8,7 +8,7 @@ struct Bar {
|
||||||
y int
|
y int
|
||||||
}
|
}
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
struct Baz {
|
struct Baz {
|
||||||
x string
|
x string
|
||||||
y int
|
y int
|
||||||
|
|
|
@ -877,11 +877,14 @@ fn (mut p Parser) parse_attr() table.Attr {
|
||||||
} else {
|
} else {
|
||||||
name = p.check_name()
|
name = p.check_name()
|
||||||
if name == 'unsafe_fn' {
|
if name == 'unsafe_fn' {
|
||||||
p.error_with_pos('please use `[unsafe]` instead', p.tok.position())
|
p.error_with_pos('[unsafe_fn] is obsolete, use `[unsafe]` instead', apos.extend(p.tok.position()))
|
||||||
return table.Attr{}
|
return table.Attr{}
|
||||||
} else if name == 'trusted_fn' {
|
} else if name == 'trusted_fn' {
|
||||||
p.error_with_pos('please use `[trusted]` instead', p.tok.position())
|
p.error_with_pos('[trusted_fn] is obsolete, use `[trusted]` instead', apos.extend(p.tok.position()))
|
||||||
return table.Attr{}
|
return table.Attr{}
|
||||||
|
} else if name == 'ref_only' {
|
||||||
|
p.warn_with_pos('[ref_only] is deprecated, use [heap] instead', apos.extend(p.tok.position()))
|
||||||
|
name = 'heap'
|
||||||
}
|
}
|
||||||
if p.tok.kind == .colon {
|
if p.tok.kind == .colon {
|
||||||
p.next()
|
p.next()
|
||||||
|
|
|
@ -295,7 +295,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||||
fields: fields
|
fields: fields
|
||||||
is_typedef: attrs.contains('typedef')
|
is_typedef: attrs.contains('typedef')
|
||||||
is_union: is_union
|
is_union: is_union
|
||||||
is_ref_only: attrs.contains('ref_only')
|
is_heap: attrs.contains('heap')
|
||||||
generic_types: generic_types
|
generic_types: generic_types
|
||||||
attrs: attrs
|
attrs: attrs
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ const (
|
||||||
'cflags', 'path']
|
'cflags', 'path']
|
||||||
)
|
)
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct Preferences {
|
pub struct Preferences {
|
||||||
pub mut:
|
pub mut:
|
||||||
os OS // the OS to compile for
|
os OS // the OS to compile for
|
||||||
|
|
|
@ -643,7 +643,7 @@ pub mut:
|
||||||
fields []Field
|
fields []Field
|
||||||
is_typedef bool // C. [typedef]
|
is_typedef bool // C. [typedef]
|
||||||
is_union bool
|
is_union bool
|
||||||
is_ref_only bool
|
is_heap bool
|
||||||
generic_types []Type
|
generic_types []Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[ref_only]
|
[heap]
|
||||||
struct Abc {
|
struct Abc {
|
||||||
mut:
|
mut:
|
||||||
n int
|
n int
|
||||||
|
|
|
@ -5,7 +5,7 @@ module util
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct Timers {
|
pub struct Timers {
|
||||||
pub mut:
|
pub mut:
|
||||||
swatches map[string]time.StopWatch
|
swatches map[string]time.StopWatch
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub:
|
||||||
vmod_folder string
|
vmod_folder string
|
||||||
}
|
}
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct ModFileCacher {
|
pub struct ModFileCacher {
|
||||||
mut:
|
mut:
|
||||||
cache map[string]ModFileAndFolder
|
cache map[string]ModFileAndFolder
|
||||||
|
|
|
@ -20,7 +20,7 @@ import strings
|
||||||
// > Each field is represented by the field name, followed by a colon, followed by the text
|
// > Each field is represented by the field name, followed by a colon, followed by the text
|
||||||
// > data for that field's value.
|
// > data for that field's value.
|
||||||
|
|
||||||
[ref_only]
|
[heap]
|
||||||
pub struct SSEConnection {
|
pub struct SSEConnection {
|
||||||
pub mut:
|
pub mut:
|
||||||
headers map[string]string
|
headers map[string]string
|
||||||
|
|
Loading…
Reference in New Issue