@@ -433,6 +433,26 @@ respect to incremental compilation:
433433 the result of the query has changed. As a consequence anything depending
434434 on a ` no_hash ` query will always be re-executed.
435435
436+ Using ` no_hash ` for a query can make sense in two circumstances:
437+
438+ - If the result of the query is very likely to change whenever one of its
439+ inputs changes, e.g. a function like ` |a, b, c| -> (a * b * c) ` . In such
440+ a case recomputing the query will always yield a red node if one of the
441+ inputs is red so we can spare us the trouble and default to red immediately.
442+ A counter example would be a function like ` |a| -> (a == 42) ` where the
443+ result does not change for most changes of ` a ` .
444+
445+ - If the result of a query is a big, monolithic collection (e.g. ` index_hir ` )
446+ and there are "projection queries" reading from that collection
447+ (e.g. ` hir_owner ` ). In such a case the big collection will likely fulfill the
448+ condition above (any changed input means recomputing the whole collection)
449+ and the results of the projection queries will be hashed anyway. If we also
450+ hashed the collection query it would mean that we effectively hash the same
451+ data twice: once when hashing the collection and another time when hashing all
452+ the projection query results. ` no_hash ` allows us to avoid that redundancy
453+ and the projection queries act as a "firewall", shielding their dependents
454+ from the unconditionally red ` no_hash ` node.
455+
436456 - ` cache_on_disk_if ` - This attribute is what determines which query results
437457 are persisted in the incremental compilation query result cache. The
438458 attribute takes an expression that allows per query invocation
0 commit comments