Skip to content

32-bit hash is way too small when collisions are deadly

Not sure if I have ever received this error in my life. But maybe I did without realizing it. I stopped using generics long ago because of STRANGE errors that can be related to this, giving they always use CRC.

Several parts of the compiler use CRC-32 to shorten names. Sadly, due to the birthday paradox this results in a non-trivial probability of collisions that give cryptic error messages.

Can they be replaced with something longer, at least CRC-64 (or WyHash64 :D), or maybe even somehow do it without hashing at all, e.g. have all units store long string tables and reference their elements by number?

Compiling this on x86-** yields Error: Asm: Duplicate label P$PROGRAM$_$SOMETYPE_$_SOMENESTEDTYPE_$_YETANOTHERNESTEDTYPE_$__$$_HELLO$crc4ED50114. May depend on the compiler and platform though. Can probably get something even worse (Error while linking, I think?) if you are even more unlucky.

{$mode objfpc}
type
	Collide29685295 = type uint32;
	Collide32060020 = type uint32;

	SomeType = class
	type
		SomeNestedType = class
		type
			YetAnotherNestedType = class
				class procedure Hello(arg: YetAnotherNestedType; arg2: Collide29685295); static;
				class procedure Hello(arg: YetAnotherNestedType; arg2: Collide32060020); static;
			end;
		end;
	end;

	class procedure SomeType.SomeNestedType.YetAnotherNestedType.Hello(arg: YetAnotherNestedType; arg2: Collide29685295);
	begin
	end;

	class procedure SomeType.SomeNestedType.YetAnotherNestedType.Hello(arg: YetAnotherNestedType; arg2: Collide32060020);
	begin
	end;

begin
end.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information