qsharp-compiler icon indicating copy to clipboard operation
qsharp-compiler copied to clipboard

Hashes are used incorrectly

Open bamarsha opened this issue 4 years ago • 0 comments

The compiler defines three hash generating functions in NamespaceManager: TypeHash, ExpressionHash, and HeaderHash. These hash functions are not used correctly and can cause incorrect compilation.

Examples:

https://github.com/microsoft/qsharp-compiler/blob/47fce24f420be04526258ef06f32eec53b2d4655/src/QsCompiler/Core/SymbolTable/NamespaceManager.fs#L496-L497

This code may incorrectly generate duplicate attribute warnings if two distinct attributes have a hash collision.

https://github.com/microsoft/qsharp-compiler/blob/47fce24f420be04526258ef06f32eec53b2d4655/src/QsCompiler/CompilationManager/TypeChecking.cs#L2063-L2089

This code may not type check the syntax tree correctly after changes are made if a hash collision occurs.

Hash equality is a necessary but not sufficient condition for actual equality. These examples should be fixed to check for actual equality of syntax tree items.

bamarsha avatar Apr 12 '21 19:04 bamarsha