Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/analyzer/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::attribute_table;
use crate::comb_loop_detect;
use crate::conv::{Context, Conv};
use crate::definition_table;
use crate::dynamic_for_check;
use crate::generic_inference_table;
use crate::handlers::*;
use crate::ir::{Ir, IrResult};
Expand Down Expand Up @@ -266,6 +267,7 @@ impl Analyzer {

ret.append(&mut symbol_table::check_unused_variable());
ret.append(&mut symbol_table::check_wavedrom());
ret.append(&mut dynamic_for_check::check(ir));
ret.append(&mut comb_loop_detect::check(ir));

ret
Expand Down
26 changes: 26 additions & 0 deletions crates/analyzer/src/analyzer_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,23 @@ pub enum AnalyzerError {
token_source: TokenSource,
},

#[diagnostic(
severity(Warning),
code(mutable_for_bound),
help("move the assignment outside the loop or iterate over a separate, stable bound; this will become an error in a future release"),
url("https://doc.veryl-lang.org/book/07_appendix/02_semantic_error.html#{}", self.code().unwrap())
)]
#[error(
"for-loop continuation bound is modified by the loop body, so backends may execute different iteration counts"
)]
MutableForBound {
#[source_code]
input: MultiSources,
#[label("Warning location")]
error_location: SourceSpan,
token_source: TokenSource,
},

#[diagnostic(
severity(Error),
code(invalid_for_step),
Expand Down Expand Up @@ -2076,6 +2093,7 @@ impl AnalyzerError {
AnalyzerError::MissingTri { input, .. } => input,
AnalyzerError::MixedFunctionArgument { input, .. } => input,
AnalyzerError::MixedStructUnionMember { input, .. } => input,
AnalyzerError::MutableForBound { input, .. } => input,
AnalyzerError::MultipleAssignment { input, .. } => input,
AnalyzerError::MultipleDefault { input, .. } => input,
AnalyzerError::NonConstantSelectWidth { input, .. } => input,
Expand Down Expand Up @@ -2197,6 +2215,7 @@ impl AnalyzerError {
AnalyzerError::MissingTri { token_source, .. } => *token_source,
AnalyzerError::MixedFunctionArgument { token_source, .. } => *token_source,
AnalyzerError::MixedStructUnionMember { token_source, .. } => *token_source,
AnalyzerError::MutableForBound { token_source, .. } => *token_source,
AnalyzerError::MultipleAssignment { token_source, .. } => *token_source,
AnalyzerError::MultipleDefault { token_source, .. } => *token_source,
AnalyzerError::PrivateMember { token_source, .. } => *token_source,
Expand Down Expand Up @@ -2638,6 +2657,13 @@ impl AnalyzerError {
token_source: token.source(),
}
}
pub fn mutable_for_bound(token: &TokenRange) -> Self {
AnalyzerError::MutableForBound {
input: source(token),
error_location: token.into(),
token_source: token.source(),
}
}
pub fn invalid_for_step(cause: InvalidForStepKind, token: &TokenRange) -> Self {
AnalyzerError::InvalidForStep {
cause,
Expand Down
7 changes: 7 additions & 0 deletions crates/analyzer/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct Pattern {
pub missing_reset_statement: StrId,
pub unused_variable: StrId,
pub unassign_variable: StrId,
pub mutable_for_bound: StrId,
pub enum_encoding: StrId,
pub sequential: StrId,
pub onehot: StrId,
Expand Down Expand Up @@ -231,6 +232,7 @@ impl Pattern {
missing_reset_statement: resource_table::insert_str("missing_reset_statement"),
unused_variable: resource_table::insert_str("unused_variable"),
unassign_variable: resource_table::insert_str("unassign_variable"),
mutable_for_bound: resource_table::insert_str("mutable_for_bound"),
enum_encoding: resource_table::insert_str("enum_encoding"),
sequential: resource_table::insert_str("sequential"),
onehot: resource_table::insert_str("onehot"),
Expand Down Expand Up @@ -348,6 +350,9 @@ impl TryFrom<&veryl_parser::veryl_grammar_trait::Attribute> for Attribute {
x if x == pat.unassign_variable => {
Ok(Attribute::Allow(AllowItem::UnassignVariable))
}
x if x == pat.mutable_for_bound => {
Ok(Attribute::Allow(AllowItem::MutableForBound))
}
_ => Err(err),
}
} else {
Expand Down Expand Up @@ -536,6 +541,7 @@ pub enum AllowItem {
MissingResetStatement,
UnusedVariable,
UnassignVariable,
MutableForBound,
}

impl AllowItem {
Expand All @@ -558,6 +564,7 @@ impl fmt::Display for AllowItem {
AllowItem::MissingResetStatement => "missing_reset_statement",
AllowItem::UnusedVariable => "unused_variable",
AllowItem::UnassignVariable => "unassign_variable",
AllowItem::MutableForBound => "mutable_for_bound",
};
text.fmt(f)
}
Expand Down
Loading
Loading