Skip to content

Commit

Permalink
Fix no error & execute crash on bad declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Oct 29, 2024
1 parent 3110f7b commit 0048e17
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ In this example, we create a memory block with a read port and a write port. Thi
- [x] Generative For Loops
- [ ] Generative While Loops
- [x] Generative Parameters
- [ ] Generative Default Arguments
- [ ] Generative Parameter Default Arguments
- [x] Type Parameters
- [ ] Generative Asserts
- [x] Multi-Interface Syntax
Expand All @@ -210,7 +210,9 @@ In this example, we create a memory block with a read port and a write port. Thi
- [ ] Conflicting assignments (such as calling the same module twice in a single cycle, multiple assignments to a single variable)

### Typing & Inference
- [ ] Hindley-Milner typing
- [x] Hindley-Milner typing for Abstract Types
- [x] Hindley-Milner typing for Domain Types
- [ ] Hindley-Milner typing for Concrete Types
- [ ] Template Type Inference
- [ ] Generative Parameter Inference
- [ ] Latency Count Inference
Expand Down
2 changes: 2 additions & 0 deletions src/typing/abstract_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl TypeUnifier {
if !size_instr.typ.domain.is_generative() {
errors.error(array_bracket_span.inner_span(), "The size of arrays must be a generative value. (gen)");
}

self.type_substitutor.unify_report_error(&size_instr.typ.typ, &INT_TYPE, array_bracket_span.inner_span(), "array size");

let arr_content_variable = AbstractType::Unknown(self.alloc_typ_variable());

Expand Down
16 changes: 16 additions & 0 deletions test.sus
Original file line number Diff line number Diff line change
Expand Up @@ -917,3 +917,19 @@ module use_no_main_interface {
int x = no_interface_named()
int y = no_main_interface()
}

module moduleWithBadDeclaration {
int[true] a
}

module moduleWithBadInterface {
interface moduleWithBadInterface : int[true] a
}

module useModuleWithBadInterface {
int[3] xyz
moduleWithBadInterface(xyz)

xyz[3] = true
}

42 changes: 42 additions & 0 deletions test.sus_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1137,3 +1137,45 @@ Warning: Unused Variable: This variable does not affect the output ports of this
│ ┬
│ ╰── Unused Variable: This variable does not affect the output ports of this module
─────╯
Error: Typing Error: array size expects a ::int but was given a ::bool
╭─[test.sus:922:6]
922 │ int[true] a
│ ──┬─
│ ╰─── Typing Error: array size expects a ::int but was given a ::bool
─────╯
Warning: Unused Variable: This variable does not affect the output ports of this module
╭─[test.sus:922:12]
922 │ int[true] a
│ ┬
│ ╰── Unused Variable: This variable does not affect the output ports of this module
─────╯
Error: Typing Error: array size expects a ::int but was given a ::bool
╭─[test.sus:926:41]
926 │ interface moduleWithBadInterface : int[true] a
│ ──┬─
│ ╰─── Typing Error: array size expects a ::int but was given a ::bool
─────╯
Warning: Unused Variable: This variable does not affect the output ports of this module
╭─[test.sus:926:47]
926 │ interface moduleWithBadInterface : int[true] a
│ ┬
│ ╰── Unused Variable: This variable does not affect the output ports of this module
─────╯
Error: Typing Error: connection expects a ::int but was given a ::bool
╭─[test.sus:933:11]
933 │ xyz[3] = true
│ ──┬─
│ ╰─── Typing Error: connection expects a ::int but was given a ::bool
─────╯
Warning: Unused Variable: This variable does not affect the output ports of this module
╭─[test.sus:930:9]
930 │ int[3] xyz
│ ─┬─
│ ╰─── Unused Variable: This variable does not affect the output ports of this module
─────╯
9 changes: 9 additions & 0 deletions test.sus_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ TREE SITTER module! instruction_decoder
TREE SITTER module! run_instruction
TREE SITTER module! no_main_interface
TREE SITTER module! use_no_main_interface
TREE SITTER module! moduleWithBadDeclaration
TREE SITTER module! moduleWithBadInterface
TREE SITTER module! useModuleWithBadInterface
Typechecking DualPortMem
Typechecking UseDualPortMem
Typechecking FIFO
Expand Down Expand Up @@ -197,6 +200,9 @@ Typechecking instruction_decoder
Typechecking run_instruction
Typechecking no_main_interface
Typechecking use_no_main_interface
Typechecking moduleWithBadDeclaration
Typechecking moduleWithBadInterface
Typechecking useModuleWithBadInterface
Instantiating UseDualPortMem
Instantiating submodules for UseDualPortMem
Instantiating DualPortMem
Expand Down Expand Up @@ -560,3 +566,6 @@ Instantiating submodules for no_main_interface
Concrete Typechecking no_main_interface
Latency Counting no_main_interface
Not Instantiating use_no_main_interface due to flattening errors
Not Instantiating moduleWithBadDeclaration due to flattening errors
Not Instantiating moduleWithBadInterface due to flattening errors
Not Instantiating useModuleWithBadInterface due to flattening errors
File renamed without changes.

0 comments on commit 0048e17

Please sign in to comment.