bare func declaration identities (comptime)
This commit is contained in:
@@ -957,6 +957,33 @@ is_optional_pointer :: proc(value: Type, store: ^Store) -> bool {
|
||||
return ok && item.kind == .Optional && is_pointer(item.child, store)
|
||||
}
|
||||
|
||||
is_comptime_only :: proc(value: Type, store: ^Store, depth := 0) -> bool {
|
||||
if depth > 256 {
|
||||
return false
|
||||
}
|
||||
item, ok := node(store, value)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if item.kind == .Function {
|
||||
return true
|
||||
}
|
||||
if item.kind == .Pointer || item.kind == .Slice || item.kind == .Range || item.kind == .Fallible {
|
||||
return false
|
||||
}
|
||||
if item.kind == .Array || item.kind == .Optional || item.kind == .Distinct || item.kind == .Enum || item.kind == .Alias {
|
||||
return is_comptime_only(item.child, store, depth+1)
|
||||
}
|
||||
if item.kind == .Struct || item.kind == .Union {
|
||||
for field in fields_for(store, value) {
|
||||
if is_comptime_only(field.type, store, depth+1) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
is_runtime_value :: proc(value: Type, store: ^Store, depth := 0) -> bool {
|
||||
if depth > 256 {
|
||||
return false
|
||||
@@ -981,7 +1008,8 @@ is_runtime_value :: proc(value: Type, store: ^Store, depth := 0) -> bool {
|
||||
}
|
||||
if value_kind == .Struct || value_kind == .Union {
|
||||
item, ok := node(store, value)
|
||||
return ok && item.declared && !item.opaque && (!item.c_layout || item.field_count > 0)
|
||||
return ok && item.declared && !item.opaque && (!item.c_layout || item.field_count > 0) &&
|
||||
!is_comptime_only(value, store)
|
||||
}
|
||||
if value_kind == .Fallible {
|
||||
item, ok := node(store, value)
|
||||
@@ -1265,6 +1293,20 @@ function_pointer :: proc(value: Type, store: ^Store) -> (pointer_item, function_
|
||||
return pointer_node, function_node, pointer_node.child, true
|
||||
}
|
||||
|
||||
callable_function :: proc(value: Type, store: ^Store) -> (pointer_item, function_item: Node, function_type: Type, ok: bool) {
|
||||
item, item_ok := node(store, value)
|
||||
if item_ok && item.kind == .Function {
|
||||
return {}, item, value, true
|
||||
}
|
||||
return function_pointer(value, store)
|
||||
}
|
||||
|
||||
can_coerce_function_pointer :: proc(actual, expected: Type, store: ^Store) -> bool {
|
||||
actual_item, actual_ok := node(store, actual)
|
||||
_, _, expected_function, expected_ok := function_pointer(expected, store)
|
||||
return actual_ok && actual_item.kind == .Function && expected_ok && equal(actual, expected_function)
|
||||
}
|
||||
|
||||
replace_pointer_child :: proc(store: ^Store, value, child: Type) -> (Type, bool) {
|
||||
item, ok := node(store, value)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user