Skip to content

Commit

Permalink
Fix I forgot to add Domain Variables to ConditionStack
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Oct 19, 2024
1 parent 247b09d commit 0133780
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
21 changes: 9 additions & 12 deletions src/flattening/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,13 @@ impl<'l, 'errs : 'l> FlatteningContext<'l, 'errs> {

fn flatten_assign_function_call(
&mut self,
to: Vec<(Option<(WireReference, bool, WriteModifiers)>, Span)>,
to: Vec<(Option<(WireReference, WriteModifiers)>, Span)>,
cursor: &mut Cursor,
) {
// Error on all to items that require writing a generative value
for (to_item, to_span) in &to {
if let Some((_to, generative_required, _write_modifiers)) = to_item {
if *generative_required {
if let Some((to, _write_modifiers)) = to_item {
if to.is_generative {
self.errors.error(*to_span, "A generative value must be written to this, but function calls cannot return generative values");
}
}
Expand Down Expand Up @@ -1198,7 +1198,7 @@ impl<'l, 'errs : 'l> FlatteningContext<'l, 'errs> {

let mut to_iter = to.into_iter();
for port in outputs {
if let Some((Some((to, _generative_required, write_modifiers)), to_span)) = to_iter.next() {
if let Some((Some((to, write_modifiers)), to_span)) = to_iter.next() {
let from =
self.instructions.alloc(Instruction::Wire(WireInstance {
typ: self.type_alloc.alloc_unset_type(DomainAllocOption::NonGenerativeUnknown), // TODO Generative Function Calls https://github.com/pc2/sus-compiler/issues/10
Expand All @@ -1225,7 +1225,7 @@ impl<'l, 'errs : 'l> FlatteningContext<'l, 'errs> {
to.into_iter()
};
for leftover_to in to_iter {
if let (Some((to, _generative_required, write_modifiers)), to_span) = leftover_to {
if let (Some((to, write_modifiers)), to_span) = leftover_to {
let err_id = self.instructions.alloc(Instruction::Wire(WireInstance {
typ: self.type_alloc.alloc_unset_type(DomainAllocOption::NonGenerativeUnknown),
span: func_call_span,
Expand Down Expand Up @@ -1272,8 +1272,8 @@ impl<'l, 'errs : 'l> FlatteningContext<'l, 'errs> {
if to.len() != 1 {
self.errors.error(span, format!("Non-function assignments must output exactly 1 output instead of {}", to.len()));
}
if let Some((Some((to, requires_generative, write_modifiers)), to_span)) = to.into_iter().next() {
let to_type = self.type_alloc.alloc_unset_type(if requires_generative {DomainAllocOption::Generative} else {DomainAllocOption::NonGenerativeUnknown});
if let Some((Some((to, write_modifiers)), to_span)) = to.into_iter().next() {
let to_type = self.type_alloc.alloc_unset_type(if to.is_generative {DomainAllocOption::Generative} else {DomainAllocOption::NonGenerativeUnknown});
self.instructions.alloc(Instruction::Write(Write{from: read_side, to, to_span, write_modifiers, to_type}));
}
}
Expand Down Expand Up @@ -1371,7 +1371,7 @@ impl<'l, 'errs : 'l> FlatteningContext<'l, 'errs> {
fn flatten_assignment_left_side(
&mut self,
cursor: &mut Cursor,
) -> Vec<(Option<(WireReference, bool, WriteModifiers)>, Span)> {
) -> Vec<(Option<(WireReference, WriteModifiers)>, Span)> {
cursor.collect_list(kind!("assign_left_side"), |cursor| {
cursor.go_down(kind!("assign_to"), |cursor| {
let write_modifiers = self.flatten_write_modifiers(cursor);
Expand All @@ -1389,21 +1389,18 @@ impl<'l, 'errs : 'l> FlatteningContext<'l, 'errs> {
);
let flat_root_decl = self.instructions[root].unwrap_wire_declaration();
let is_generative = flat_root_decl.identifier_type.is_generative();
let requires_generative = is_generative || write_modifiers.requires_generative();
Some((
WireReference {
root: WireReferenceRoot::LocalDecl(root, flat_root_decl.name_span),
is_generative,
path: Vec::new(),
},
requires_generative,
write_modifiers,
))
} else {
// It's _expression
if let Some(wire_ref) = self.flatten_wire_reference(cursor).expect_wireref(self) {
let requires_generative = wire_ref.is_generative || write_modifiers.requires_generative();
Some((wire_ref, requires_generative, write_modifiers))
Some((wire_ref, write_modifiers))
} else {
None
}
Expand Down
12 changes: 6 additions & 6 deletions src/flattening/typechecking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn typecheck_all_modules(linker: &mut Linker) {
struct ConditionStackElem {
ends_at: FlatID,
span: Span,
domain: DomainID,
domain: DomainType,
}

struct TypeCheckingContext<'l, 'errs> {
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'l, 'errs> TypeCheckingContext<'l, 'errs> {
self.get_type_of_port(port.port, port.submodule_decl)
}
};
self.type_checker.typecheck_domain_from_to(&root_type.domain, &output_typ.domain, whole_span, "array access array");
self.type_checker.typecheck_domain_from_to(&root_type.domain, &output_typ.domain, whole_span, "wire reference root with root type");

let mut current_type_in_progress = root_type.typ;
for p in &wire_ref.path {
Expand Down Expand Up @@ -267,11 +267,11 @@ impl<'l, 'errs> TypeCheckingContext<'l, 'errs> {
}
Instruction::IfStatement(if_stmt) => {
let condition_wire = self.modules.working_on.instructions[if_stmt.condition].unwrap_wire();
if let DomainType::Physical(domain) = condition_wire.typ.domain {
if !condition_wire.typ.domain.is_generative() {
self.runtime_condition_stack.push(ConditionStackElem {
ends_at: if_stmt.else_end,
span: condition_wire.span,
domain,
domain: condition_wire.typ.domain.clone(),
});
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ impl<'l, 'errs> TypeCheckingContext<'l, 'errs> {
/// outside of a condition block
fn join_with_condition(&self, ref_domain: &DomainType, span: Span) {
if let Some(condition_domain) = self.get_current_condition_domain() {
self.type_checker.typecheck_domain_from_to(ref_domain, &DomainType::Physical(condition_domain.0), span, "condition join");
self.type_checker.typecheck_domain_from_to(ref_domain, &condition_domain.0, span, "condition join");
}
}

Expand Down Expand Up @@ -490,7 +490,7 @@ impl<'l, 'errs> TypeCheckingContext<'l, 'errs> {
}
}

fn get_current_condition_domain(&self) -> Option<(DomainID, Span)> {
fn get_current_condition_domain(&self) -> Option<(DomainType, Span)> {
let last = self.runtime_condition_stack.last()?;
Some((last.domain, last.span))
}
Expand Down
2 changes: 1 addition & 1 deletion src/typing/abstract_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<'linker, 'errs> TypeUnifier<'linker, 'errs> {
match (from_domain.is_generative(), to_domain.is_generative()) {
(true, _) => {} // From domain is generative, so nothing needs to be done
(false, true) => {
self.errors.error(span, format!("Attempting use a non-generative variable in a generative context. "));
self.errors.error(span, format!("Attempting use a non-generative variable in a generative context: {context}"));
}
(false, false) => {
self.domain_substitutor.unify_report_error(&from_domain, &to_domain, span, context);
Expand Down

0 comments on commit 0133780

Please sign in to comment.