Replies: 2 comments 2 replies
-
Other ideas: -Expand Type from -Provide a method to fully traverse the -Introduce a new stage between the |
Beta Was this translation helpful? Give feedback.
1 reply
-
Have you seen Checker.update_unresolved_fixed_sizes()? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The current flags in TypeFlag are as follows:
Can it be expanded to:
I'm currently facing a tricky issue in the development a PR to support Feature requested by #25183.
In the original code, fixed-length array types are registered in the
parser
usingfind_or_register_array_fixed()
. However, during the parse stage, due to incomplete information (such as const variables in other files), it's impossible to correctly resolve all constant expressionssize_expr
in[size_expr]int{}
.My approach is to register an array type during the
parser
stage usingfind_or_register_array_fixed_unresolved_size(elem_type Type, size_expr Expr, is_fn_ret bool, mod_name string)
. Then, during thechecker
stage, after obtaining sufficient information, resolve thesize_expr
for all fixed-length array types intype_symbols
, and then callfind_or_register_array_fixed_with_size(elem_type Type, size int, is_fn_ret bool)
to register the new array type.The problem now is that multiple different fixed-length arrays from the
parser
stage may resolve to the same fixed-length array. For example, in module main:During the parser stage, two fixed-length arrays
[a]int{}
and[b]int{}
are registered. Since the values ofa
andb
are unknown at this stage, they are registered as different array types (let's say types123
and124
).However, during the checker stage, after resolution, it's discovered that
a = b = 2
. Thus, both should map to the same fixed-length array[2]int{}
(let's say type200
).As a result, the system now has three fixed-length array types:
123
,124
, and200
. But in reality, they should all be type200
.This causes issues in many parts of the
checker
andcgen
code. For example, in an assignment statement, the type is determined as123
during theparser
stage. Ifchecker
orcgen
uses123
for type checking or code generation, errors occur. The correct approach is to use type200
for checking and code generation.By introducing an unresolved type flag in
TypeFlag
and a type redirection mechanism, this issue can likely be solved. For example, we can introduce amap[int]int
in thetable
to implement mapping from unresolved types to resolved types. At every point where type information is needed, we must check whether redirection is required.Another approach is to traverse the entire AST and replace all types after resolving all unresolved types.
Or there is a better way to solve this problem?
BTW, the current space in TypeFlag seems insufficient.
Beta Was this translation helpful? Give feedback.
All reactions