as is well-known, DocC relies on truncated FNV-1 hashes to disambiguate colliding symbol names. FNV-1 hash collisions are uncommon but trivial to produce in the general case, and while it’s harder for the subset of swift USR strings to collide, my suspicion is that it is quite possible for two compiler-generated USRs to collide.
for disambiguation they only need to be unique for symbols with the same full name after case-folding, but if you want to use the hash as an ID for the symbol in a database (since symbol strings can grow to be very long), it needs to be unique at least at the module level.
We're aware that the hash collisions are possible but for what DocC uses the truncated FNV-1 hashes they're unique enough.
DocC only uses the truncated FNV-1 hash as disambiguation for symbols that have the same name in the same scope (and the same module). This significantly narrows the scope and reduces the risk of collisions.
Using one example from the collisions you found: "2ZV9P" could be the hash for either of these symbols or possible another symbol in the developers own code:
These are in different modules, so that already avoids the link collision, but even if they were in the same module, the first is named objectiveCValue(for:) and the other is named isHTTPOnly so this hash collision isn't an issue for DocC because DocC doesn't use the hash without also using the symbol name.
We haven't explored how unique these hashes are within a module because we've haven't needed to use them as unique identifiers in DocC.
still, seeing as there is a non-negligible probability of the compiler generating USRs with the same truncated hash, it is only a matter of time until a hash collision occurs between two symbols with the same name across the vast multitude of swift packages in existence. what is the fallback mechanism available when FNV-1 hashes cannot be used to disambiguate between two symbols?
If they are different kinds of symbols, then their links can be disambiguated by the symbol kind. The only other fallback would be to add more leading path components until the link starts with the module name.
For example; even in a relative link the isHTTPOnly symbol above could also be written like HTTPCookie/isHTTPOnly or like FoundationNetworking/HTTPCookie/isHTTPOnly.
If two symbols in the same module have all the same path components, are the same kind of symbol, and have a collision in the truncated FNV-1 hash then a couple of things would break;
DocC wouldn't be able to know which of the two symbols an authored link was referring to
Both symbols would have the same web URL and same file path within the .doccarchive—likely resulting in only one of them getting a page.
DocC operates under the assumption that within a module, the combination of full symbol path, symbol kind, and truncated symbol hash is always unique. There isn't a fallback mechanism today if that assumption is proven wrong.
yes, this is the edge case i am concerned about. my feeling is that certain scopes can get quite crowded with overloads (due to Encoder/Decoder conformances, gybbed interfaces, and soon, macros) and that drives up the probability of a hash collision.