Simplest fix to a dependency bug.

Better commenting-out
This commit is contained in:
David Ungar
2020-06-05 20:33:21 -07:00
parent aef3464e73
commit de7033c479

View File

@@ -79,14 +79,30 @@ void AbstractSourceFileDepGraphFactory::addAUsedDecl(
const DependencyKey &defKey, const DependencyKey &useKey) {
auto *defNode =
g.findExistingNodeOrCreateIfNew(defKey, None, false /* = !isProvides */);
// If the depended-upon node is defined in this file, then don't
// create an arc to the user, when the user is the whole file.
// Otherwise, if the defNode's type-body fingerprint changes,
// the whole file will be marked as dirty, losing the benefit of the
// fingerprint.
if (defNode->getIsProvides() &&
useKey.getKind() == NodeKind::sourceFileProvide)
return;
// if (defNode->getIsProvides() &&
// useKey.getKind() == NodeKind::sourceFileProvide)
// return;
// Turns out the above three lines cause miscompiles, so comment them out
// for now. We might want them back if we can change the inputs to this
// function to be more precise.
// Example of a miscompile:
// In main.swift
// func foo(_: Any) { print("Hello Any") }
// foo(123)
// Then add the following line to another file:
// func foo(_: Int) { print("Hello Int") }
// Although main.swift needs to get recompiled, the commented-out code below
// prevents that.
auto nullableUse = g.findExistingNode(useKey);
assert(nullableUse.isNonNull() && "Use must be an already-added provides");
auto *useNode = nullableUse.get();