Conversation
dd18158 to
75a985f
Compare
There was a problem hiding this comment.
Checker for generic reference (check_generic_reference) is rewritten based on IR evaluation.
This is to share the checker routines with generic expression checker.
To implement this, IR evaluation needs to handle component reference and component instnace because they are given as generic args.
Module, Package and Instance are added as new enum variants of ir::TypeKind for this purpose.
https://github.com/taichi-ishitani/veryl/blob/75a985f958a8b18094cc291703a3f768cd49d88a/crates/analyzer/src/ir/comptime.rs#L757-L761
Component referecne and instance are converted into ir::Factor::Value if the expression is in gen declaration.
| let namespace = self.inner_namespace(); | ||
| for (name, r#const) in &consts { | ||
| let maps = vec![map.clone()]; | ||
| if let Some(mut path) = Self::expr_to_generic_symbol_path(&r#const.value, &maps) { |
There was a problem hiding this comment.
Generic consts are evaluated when resolving generic params of the generic component.
The evaluated result is converted to GenericSymbolPath and added to the resolved generic map.
Resolved generic consts acts like generic args.
| pub enum GenericSymbolPathKind { | ||
| Identifier, | ||
| TypeLiteral, | ||
| VariableType(Vec<usize>), |
There was a problem hiding this comment.
VariableType handles variable type declaration (e.g. logic<8>).
| EnumMemberValue::UnevaluableValue => None, | ||
| }; | ||
|
|
||
| if let Some(mut factor) = factor { |
There was a problem hiding this comment.
Type kind of enum member should be its parent enum. The replacement below is for this.
| if x.path == member_path { | ||
| let mut comptime = expr.eval_comptime(context, None).clone(); | ||
| comptime.token = token; | ||
| comptime.r#type = get_member_type(context, member_symbol)?; |
There was a problem hiding this comment.
struct member is typed so type of evaluation result should be restored with the struct member type.
| base: Option<&Symbol>, | ||
| token: TokenRange, | ||
| ) -> Option<AnalyzerError> { | ||
| let mut paths = collect_symbol_paths(expression); |
There was a problem hiding this comment.
Identifiers in the given expression are collected by iterating factors in the expression.
They are converted into generic symbol pashs and used to check if the expression is referable from the generic context.
At first, I implmented this check by adding a flag showing a factor can be used as generic arg to Comptime and propagting the flag during IR evaluation.
However, value of the flag is incorrect when processing the check because namespace used for the check is not provided when creating IR.
Therefore, I implemented the check based on iterating identifiers.
9436476 to
05197ea
Compare
06d19d0 to
8e8a730
Compare
ec1137c to
e82b571
Compare
e82b571 to
8613234
Compare
close #2349
gendeclaration is a new declaration likeconstdeclaration forgenericsfeature. This is used to definegenreicconst which can be given as generic asg.By using
gendeclaration, you can provide result of expression andvariabletype declaratoin to generic arg like below.Expression in
gendeclaration has the same limitation with generic arg becuasegenericconsts are used as gneric arg. Therefore, the given expression can include following factors: