preserve active comptime state in local type declarations
This commit is contained in:
@@ -943,10 +943,9 @@
|
|||||||
identically during comptime evaluation; zeroing is `memset!(destination, 0)`
|
identically during comptime evaluation; zeroing is `memset!(destination, 0)`
|
||||||
- `std/mem` aligned reallocation uses `memcopy!`
|
- `std/mem` aligned reallocation uses `memcopy!`
|
||||||
|
|
||||||
46. fix `EnumFieldStruct` in `std/meta`
|
46. fix `EnumFieldStruct` in `std/meta` (implemented)
|
||||||
- currently, the `|info|` `.enum` payload capture doesn't preserve the comptime-ness in the match statement
|
- comptime local declarations resolve type syntax in the active interpreter state, preserving match captures
|
||||||
this results in having to type other values in the scope like `[field!(typeinfo!(E), "enum").fields.len]mut []u8`
|
- `EnumFieldStruct` sizes its working arrays directly from the comptime `.enum |info|` capture
|
||||||
which is obviously absurd
|
|
||||||
|
|
||||||
## A word on unchecked casts
|
## A word on unchecked casts
|
||||||
|
|
||||||
|
|||||||
@@ -3873,7 +3873,7 @@ ct_exec_statements :: proc(
|
|||||||
ok = value_ok
|
ok = value_ok
|
||||||
if ok && value_flow.kind == .Yield {
|
if ok && value_flow.kind == .Yield {
|
||||||
value := value_flow.value
|
value := value_flow.value
|
||||||
declared := type_from_syntax(checker, statement.type, state.pkg, state.file)
|
declared := type_from_syntax(checker, statement.type, state.pkg, state.file, active_state=state)
|
||||||
if types.is_valid(declared) && !types.is_void(declared) {
|
if types.is_valid(declared) && !types.is_void(declared) {
|
||||||
value, ok = ct_coerce_value(state, value, declared, statement.span)
|
value, ok = ct_coerce_value(state, value, declared, statement.span)
|
||||||
}
|
}
|
||||||
@@ -3884,7 +3884,7 @@ ct_exec_statements :: proc(
|
|||||||
ok = ct_fail(state, .Not_Comptime, statement.span, "comptime value block must yield")
|
ok = ct_fail(state, .Not_Comptime, statement.span, "comptime value block must yield")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
declared := type_from_syntax(checker, statement.type, state.pkg, state.file)
|
declared := type_from_syntax(checker, statement.type, state.pkg, state.file, active_state=state)
|
||||||
expected := declared if types.is_valid(declared) && !types.is_void(declared) else types.INVALID
|
expected := declared if types.is_valid(declared) && !types.is_void(declared) else types.INVALID
|
||||||
value, expr_flow, expr_ok := ct_eval_expr(state, statement.expr, expected, depth+1)
|
value, expr_flow, expr_ok := ct_eval_expr(state, statement.expr, expected, depth+1)
|
||||||
ok = expr_ok
|
ok = expr_ok
|
||||||
|
|||||||
+3
-3
@@ -43,9 +43,9 @@ TypeInfo :: union(enum) {
|
|||||||
EnumFieldStruct func($E, $Field type, $default ?Field) type {
|
EnumFieldStruct func($E, $Field type, $default ?Field) type {
|
||||||
match typeinfo!(E) {
|
match typeinfo!(E) {
|
||||||
.enum |info|: {
|
.enum |info|: {
|
||||||
names [field!(typeinfo!(E), "enum").fields.len]mut []u8 = undefined
|
names [info.fields.len]mut []u8 = undefined
|
||||||
field_types [field!(typeinfo!(E), "enum").fields.len]mut type = undefined
|
field_types [info.fields.len]mut type = undefined
|
||||||
defaults [field!(typeinfo!(E), "enum").fields.len]mut ?Field = undefined
|
defaults [info.fields.len]mut ?Field = undefined
|
||||||
expand for info.fields |field, index| {
|
expand for info.fields |field, index| {
|
||||||
names[index] = field.name
|
names[index] = field.name
|
||||||
field_types[index] = Field
|
field_types[index] = Field
|
||||||
|
|||||||
Reference in New Issue
Block a user