Skip to content

Commit

Permalink
Fix errors not being reported from flattening
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Aug 24, 2024
1 parent 975e2ef commit 8814190
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Changelog
- Standard library is shipped with the compiler now in the [stl/](stl/) directory.
- Changed template definition and usage syntax to named arguments in `#()` instead of `::<>` (See [philosophy/template_troubles.md](philosophy/template_troubles.md))
11 changes: 10 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl ErrorStore {
self.did_error = checkpoint.1;
}

/// Returns true if no errors have been reported
pub fn is_untouched(&self) -> bool {
self.errors.is_empty()
}
Expand Down Expand Up @@ -112,7 +113,7 @@ impl<'linker> ErrorCollector<'linker> {

/// Turn the collector back into a [ErrorStore]
pub fn into_storage(self) -> ErrorStore {
self.error_store.into_inner()
self.error_store.replace(ErrorStore::new())
}

fn assert_span_good(&self, span: Span) {
Expand Down Expand Up @@ -167,6 +168,14 @@ impl<'linker> ErrorCollector<'linker> {
}
}

impl<'l> Drop for ErrorCollector<'l> {
fn drop(&mut self) {
if !self.error_store.borrow().is_untouched() {
panic!("ErrorCollector should have been emptied!");
}
}
}

pub struct ErrorReference<'ec> {
err_collector: &'ec ErrorCollector<'ec>,
pos: usize,
Expand Down
16 changes: 11 additions & 5 deletions src/flattening/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,12 @@ impl<'l, 'errs : 'l> FlatteningContext<'l, 'errs> {
(TemplateInputKind::Type(_), TemplateArgKind::Type(_))
| (TemplateInputKind::Generative(_), TemplateArgKind::Value(_)) => {
// Correct pairing
if let Some(prev) = &template_arg_map[id] {
let elem = &mut template_arg_map[id];
if let Some(prev) = elem {
self.errors.error(name_span, format!("'{name}' has already been defined previously"))
.info_same_file(prev.name_span, "Defined here previously");
} else {
template_arg_map[id] = Some(TemplateArg { name_span, kind: template_arg });
*elem = Some(TemplateArg { name_span, kind: template_arg });
}
}
(TemplateInputKind::Type(_), TemplateArgKind::Value(_)) => {
Expand Down Expand Up @@ -1465,8 +1466,8 @@ pub fn flatten_all_modules(linker: &mut Linker) {
assert!(context.ports_to_visit.is_empty());

let instructions = context.instructions;
match file_obj {

let link_info : &mut LinkInfo = match file_obj {
NameElem::Module(module_uuid) => {
let md = &mut linker.modules[module_uuid];
// Set all declaration_instruction values
Expand All @@ -1490,6 +1491,7 @@ pub fn flatten_all_modules(linker: &mut Linker) {
}
}
md.instructions = instructions;
&mut md.link_info
}
NameElem::Type(type_uuid) => {
let typ = &mut linker.types[type_uuid];
Expand All @@ -1515,11 +1517,15 @@ pub fn flatten_all_modules(linker: &mut Linker) {
}
}
typ.instructions = instructions;
&mut typ.link_info
}
NameElem::Constant(const_uuid) => {
todo!("TODO Constant flattening")
}
}
};

link_info.resolved_globals = errors_globals.1.into_inner();
link_info.errors = errors_globals.0.into_storage();
});
});
span_debugger.defuse();
Expand Down
2 changes: 1 addition & 1 deletion test.sus
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ module replicate #(T, int NUM_REPLS) {
}

module use_replicate {
replicate #(NUM_REPLS: 50, T: type bool) a
replicate #(NUM_REPLS: 50, NUM_REPLS: 30, T: type bool) a
replicate #(NUM_REPLS: 20, T: type int[30]) b
}

Expand Down
14 changes: 14 additions & 0 deletions tinyTestFile.sus
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@

module replicatee #(T, int NUM_REPLS) {
interface replicatee: T data -> T[NUM_REPLS] result

for int i in 0..NUM_REPLS {
result[i] = data
}
}

module use_replicatee {
replicatee #(NUM_REPLS: 50, T: type bool) a

bool[50] repls = a(true)
}

extern module TestExtern {
input int in_a'3

Expand Down

0 comments on commit 8814190

Please sign in to comment.