Flow analysis
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 32/100
Rechercherichtung
Beginne damit, die aktuelle Roslyn-Integration der Flow-Analyse zu lokalisieren, die im Issue beschrieben ist, und verfolge, wie das GetNode-Beispiel Graphkanten erzeugt. Die Arbeit ist abgeschlossen, wenn Flow-State-Hilfsknoten die Nullable-Eigenschaft lokaler Variablen über Verzweigungen hinweg nachverfolgen und der Rückgabewert vom inferierten nicht-nullbaren Mapping-Typ statt vom deklarierten nullable Typ abhängt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Currently our inference re-uses Roslyn's flow-analysis.
However, this has some fundamental problems.
9: Dictionary<T, Node> mapping = new Dictionary<T, Node>();
11: Node? GetNode(T element)
{
13: Node? node;
14: if (!mapping.TryGetValue(element, out node))
15: {
16: node = new Node();
17: mapping.Add(element, node);
18: }
19: return node;
}

There's no edges created for line 16/17 because here Roslyn knows that node is non-null.
Line 14 creates two edges: one from <nullable> because TryGetValue will assign null when returning false; the other from mapping!1#2 (the mapping field's Node type argument) when TryGetValue returns true.
The return statement creates an edge from the variable's type, because Roslyn's flow analysis can't guarantee us that the variable is non-null -- our Roslyn code analysis runs under the pessimistic assumption that all types-to-be-inferred might end up nullable, so it considers mapping to be Dictionary<T, Node?>, which leaves open the possibility that GetNode returns null.
However, after our inference decides that mapping!1#2 is non-null, it would be correct to also indicate that the GetNode return value is non-null. After all, if no node exists yet, the function will create one.
The issue here is that Roslyn's flow analysis isn't aware of our types-to-be-inferred.
It would be better if, instead of using Roslyn's flow analysis, we had our own that keeps track of node's nullability.
The idea would be to create additional "helper" graph nodes for the different flow states of a local variable of reference type.
After TryGetValue initializes node, it's flow-state would be (true: mapping!1#2, false: <nullable>). Within the if body, the flow-state would initially be <nullable>, but after line 16 would change to <nonnull>.
After the if, the flow-state from both alternatives could be re-combined by creating a new node "node-after-line-18" and edges from the nodes from the two if-branches -- in this case <nonnull> from the then-branch and mapping!1#2 from the else branch.
Then the return statement would create an edge from this "node-after-line-18" instead of the node for the variable's declared type.
All flow-state nodes associated with a variable would have an edge to the variable's declared type node.
We'd end up with a graph somewhat like this:

Thus in the end, node would be inferred as nullable, but the GetNode return type would only depend on mapping!1#2 and thus can be inferred depending on whether there's a mapping.Add(x, null) access somewhere else in the program.
- Vorherrschende Sprache
- C#
- Sterne
- 38
- Forks
- 6
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus icsharpcode/NullabilityInference
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
icsharpcode/NullabilityInference#13 · 1 Reaktion ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 42/100
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 15/100
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
icsharpcode/NullabilityInference#6 · 2 Kommentare ·
Alle Issues in icsharpcode/NullabilityInference
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
umbraco/Umbraco.Automate#612 ·
Maintainer antworten meist innerhalb von 1 Tag
-
崩溃日志只按 CRLF 分行Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
PCL-Community/PCL-CE#3872 ·
Maintainer antworten meist innerhalb von 1 Tag
-
type:task ux
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
elsa-workflows/elsa-foundation#5253 ·
Maintainer antworten meist innerhalb von 1 Tag