Unique constant names#177
Open
rgwohlbold wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Duplicate constant names account for a significant portion of the error category
bug: duplicate identifier in consistency check (no crash)on https://prusti-stdlib-support.rgwohlbold.de.The current implementation takes the
lineandcolof the span where the constant is defined. This has several problems:lineandcolare the ones of the macro definition site:yields to the error
Note the spans 44:15 and 44:23 which are inside the standard library source code (where
assert_eq!is defined), not user source code.self.span.source_callsite()instead ofself.spanleads to the problem where within one macro invocation likeassert_eq!([1, 2, 3], [1, 2, 3]), both constants have the sameself.span.source_callsite().lo, another naming conflict:then yields the error
Notice the span 2:4 now refers to the
aofassert_eq!, but it is the same for both arguments.Combining
self.spanwithself.span.source_callsite()is not sufficient either. We found two cases this goes wrong:mir::Consts. This can happen because of constant promotion, for example in the following code snippet:Here, we have one
const ARRand oneconst test_const_multi_use::promoted[0]. Thelo()of the spans is the same, but thehi()is different, corresponding toARRandARR[1]respectively.[[1, 2], [3, 4]]are problematic since the inner arrays are encoded separately on the Viper level, but don't have separate spans, triggering a conflict. A solution could be to thread aidx_path: &[usize]through the recursion inencode_const_val_treeAfter this investigation, it seems like we can try to add more and more information to the constant names, but this makes them less and less readable, and the code more convoluted, just to get a reasonable identifier. Instead, I propose to add a global counter to the constant names for deduplication and use
source_callsite()to translate to user source position (instead of macro definition site) as a compromise.