Skip to content

Take the current index into account in the QueryTrieNodeResult. #16085

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

Merged
merged 3 commits into from
Oct 10, 2023

Conversation

nojaf
Copy link
Contributor

@nojaf nojaf commented Oct 7, 2023

When playing around with GBC in https://github.com/fslaborg/Graphoscope/blob/developer/src/Graphoscope/Graphoscope.fsproj I discovered another edge case.

Consider the following setup:

        scenario
            "Ghost dependency via top-level namespace"
            [
                sourceFile
                    "Graph.fs"
                    """
namespace Graphoscope.Graph
type UndirectedGraph = obj
"""
                    Set.empty
                sourceFile
                    "DiGraph.fs"
                    """
namespace Graphoscope
open Graphoscope
type DiGraph = obj 
"""
                    (set [| 0 |])
            ]

DiGraph.fs should depend on Graph.fs to satisfy the open Graphoscope.
The open statement can safely be removed in the actual code but is valid nonetheless given the file order.

The Trie:

classDiagram

class root

root <|-- ns_Graphoscope
class ns_Graphoscope {
    DiGraph.fs[1]

    Graph.fs(0)
}

ns_Graphoscope <|-- ns_Graph
class ns_Graph {
    Graph.fs[0]

}
Loading

DiGraph.fs adds data to ns_Graphoscope, but Graph.fs does not.
Out of necessity to resolve the open Graphoscope we need to establish that from DiGraph.fs point of view the node (ns_Graphoscope) does not expose data and thus the ghost dependency resolution should kick in.

In practice, the more obvious thing to do is of course to remove the unused open statement, but we will want to be able to type-check the project using GBC.

@safesparrow could you take a look at this one as well, please?

@nojaf nojaf requested a review from a team as a code owner October 7, 2023 08:59
Copy link
Contributor

@safesparrow safesparrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the described issue, so happy for it to be merged.

I found it a bit hard to understand what the actual problem is and how this change fixes it. It might be worth elaborating that on the PR or in the code comments.
As I understand, what happened is:

  1. When a file references a namespace (rather than any symbols inside), by default we create a link to all the files that define that namespace and contain any inferable items inside it.
  2. We avoid creating links to files that don't list any inferable items as a graph optimisation.
  3. In the case that no files list any inferable items for a namespace, that namespace is still relevant for open x lines, but the main mechanism doesn't generate a link - we have a separate mechanism for ensuring that a link is created for these situations when needed, and we call such links "ghost dependencies".
  4. The "ghost dependency" link adding is only enabled when we think we need it.
  5. The problematic case is when a namespace does contain inferable items defined in some files, but all of those files are listed after the file referencing the namespace.
  6. In the above case, old code doesn't add the "ghost dependency", because it thinks that some files "exposing data" for a namespace is enough, but it doesn't consider where in the compilation order those files are.
  7. New code handles it by checking that at least one of the files "exposing data" can be "seen"/referenced by the file currently being scanned.

Please correct if that's wrong.

Similar to the other PR, to me this one indicates that the time to update/refactor the design might be soon - but less urgent than merging this.

@nojaf
Copy link
Contributor Author

nojaf commented Oct 9, 2023

Yes, your explanation is correct. We should indeed at some point refactor this a little bit to take the ghost dependency problem better into account. For now, I would merge this as is.

@psfinaki
Copy link
Member

psfinaki commented Oct 9, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@T-Gro T-Gro enabled auto-merge (squash) October 10, 2023 09:20
@T-Gro T-Gro merged commit 5f564a8 into dotnet:main Oct 10, 2023
@nojaf nojaf mentioned this pull request Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants