Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort upstream facts based on package paths #68

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions inference/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.uber.org/nilaway/annotation"
"go.uber.org/nilaway/assertion/function/assertiontree"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"golang.org/x/tools/go/analysis"
)

Expand Down Expand Up @@ -79,12 +80,24 @@ func (e *Engine) InferredMap() *InferredMap {
// added to Mapping but not UpstreamMapping, then, on a call to Export, only the information
// present in Mapping but not UpstreamMapping is exported to ensure minimization of output.
func (e *Engine) ObserveUpstream() {
var facts []analysis.PackageFact
for _, packageFact := range e.pass.AllPackageFacts() {
importedMap, ok := packageFact.Fact.(*InferredMap)
if !ok {
continue
// We only care about NilAway-related facts here.
if _, ok := packageFact.Fact.(*InferredMap); ok {
facts = append(facts, packageFact)
}
importedMap.OrderedRange(func(site primitiveSite, val InferredVal) bool {
}

// `pass.AllPackageFacts()` returns the slice of package facts in _unspecified_ order. Here
// we sort the facts by package path to ensure deterministic iteration order, which is
// important for determinism in NilAway since our inference algorithm depends on the order of
// trigger / site nilability applications.
slices.SortFunc(facts, func(i, j analysis.PackageFact) bool {
return i.Package.Path() < j.Package.Path()
})

for _, f := range facts {
f.Fact.(*InferredMap).OrderedRange(func(site primitiveSite, val InferredVal) bool {
switch v := val.(type) {
case *DeterminedVal:
// Fix as an Explained site any sites that `otherMap` knows are explained
Expand Down
Loading