Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

354 duplicate functions should be a problem #622

Merged
merged 10 commits into from
Nov 4, 2022

Conversation

riederm
Copy link
Collaborator

@riederm riederm commented Oct 29, 2022

Introduced SymbolMap which is a MultiMap that keeps the insertion order alive when iterating the elements. That way we keep exisiting tests working (I tried the multimap-create and it mixes up the order of stuff in the index which results in different order of elements generated in IR, so basically 80% of all tests would require a review).

Furthermore I introduced the global_validator.rs which validates stuff using the index. This commit extends Diagnostics to more than one location. first location remains the diagnostics main location, following locations are treated as secondary/see-also hints.

fixes #285
fixes #354
fixes #602

The symbolmap is an IndexMap<K, Vec<V>> that allows the index
to store more than one entry for a given name.

It is manually implemented (in favor of a MultiMap-Crate)
because the MultiMap crates that I tested would mix the order
of stuff in the index dramatically wich would:
1) create a huuuge change in .snaps that are very hard to verify
2) obfuscate the resulting IR by arbitrarily mixing the symbols
   (indexMap has a stable orderung)
introduced SymbolMap which is a simple yet stable (order) Multimap
that would not change the huge number of snapshot-tests by changing
the order of generated symbols (like the multimap crate does)
the first location is used as the primary label, the rest of
the locations are treated as secondary labels.
the first location is used as the primary label, the rest of
the locations are treated as secondary labels.
SourceMap moved to its own file to reduce the size
of index.rs
@riederm riederm linked an issue Oct 29, 2022 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Oct 29, 2022

Codecov Report

Base: 93.70% // Head: 93.78% // Increases project coverage by +0.07% 🎉

Coverage data is based on head (eec5e99) compared to base (c2bd800).
Patch coverage: 93.14% of modified lines in pull request are covered.

❗ Current head eec5e99 differs from pull request most recent head 6804219. Consider uploading reports for the commit 6804219 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #622      +/-   ##
==========================================
+ Coverage   93.70%   93.78%   +0.07%     
==========================================
  Files          44       46       +2     
  Lines       16846    17460     +614     
==========================================
+ Hits        15786    16374     +588     
- Misses       1060     1086      +26     
Impacted Files Coverage Δ
src/ast.rs 94.23% <ø> (ø)
src/diagnostics.rs 81.81% <69.48%> (-0.71%) ⬇️
src/index/symbol.rs 97.63% <97.63%> (ø)
src/index.rs 97.29% <99.20%> (-0.30%) ⬇️
src/codegen/generators/data_type_generator.rs 93.63% <100.00%> (ø)
src/codegen/generators/pou_generator.rs 92.27% <100.00%> (ø)
src/codegen/generators/variable_generator.rs 94.11% <100.00%> (+0.36%) ⬆️
src/index/instance_iterator.rs 99.18% <100.00%> (-0.02%) ⬇️
src/index/visitor.rs 96.53% <100.00%> (+0.14%) ⬆️
src/lexer.rs 97.55% <100.00%> (ø)
... and 18 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@riederm riederm requested a review from ghaith October 31, 2022 14:36
Copy link
Collaborator

@ghaith ghaith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it
I think it might make sense to try the iterator generic to avoid the needless collection and add the test to cover a global variable clashing with POUs i seem to have missed it.

src/lib.rs Outdated
// ### PHASE 2 ###
// annotation & validation everything
let mut annotated_units: Vec<CompilationUnit> = Vec::new();
let mut all_annotations = AnnotationMapImpl::default();
let mut all_literals = StringLiterals::default();
for (file_id, syntax_errors, unit) in all_units.into_iter() {
//todo get rid of the file_id
for (_, syntax_errors, unit) in all_units.into_iter() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not do that already? Too many changes/test changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ... I forgot that ... I'll give it a try

@@ -0,0 +1,202 @@
use crate::{ast::SourceRange, diagnostics::Diagnostic, test_utils::tests::parse_and_validate};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more examples:
A global variable and a program with the same name
A global function block instance and a function of the same name

@riederm riederm requested a review from ghaith November 3, 2022 15:01
- check uniqueness of everything callable
- check uniqueness of everything that can be a variable-access
- check uniqueness of everything that can be used as a Type
- check uniqueness of POUs

added additional tests to cover corner-cases
@riederm riederm force-pushed the 354-duplicate-functions-should-be-a-problem branch from eec5e99 to 338654c Compare November 3, 2022 15:02
Copy link
Collaborator

@ghaith ghaith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@riederm riederm merged commit c40c765 into master Nov 4, 2022
@riederm riederm deleted the 354-duplicate-functions-should-be-a-problem branch November 4, 2022 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants