Skip to content

SystemIo: target .NET 10 (stacked on the source generator PR) - #2

Open
ghostflyby wants to merge 37 commits into
mainfrom
pathio-net10
Open

ghostflyby wants to merge 37 commits into
mainfrom
pathio-net10

Conversation

@ghostflyby

Copy link
Copy Markdown
Owner

Summary

Add a net10.0 target to TruePath.SystemIo (stacked on top of the source generator PR #1; see ForNeVeR#249 for the dependency), exposing the .NET 10 BCL surface through the generator: 112 extension methods including the span- and Memory-based overloads.

Changes

  • TruePath.SystemIo: add net10.0 to TargetFrameworks. No other change needed: the generator projects the per-target-framework BCL automatically (ReadOnlySpan/ReadOnlySpan contents overloads, ReadOnlyMemory-based async overloads, AppendAllBytes family).
  • TruePath.Tests: add net10.0 so the reflection completeness test validates the generated net10.0 surface against the matching runtime.

Testing

  • dotnet build TruePath.sln -p:CheckXmlDoc=true: all targets, zero warnings.
  • dotnet test --framework net10.0: 472/472 pass (completeness test runs against the net10 surface).

Note: this PR is stacked on pathio-source-generator; until that branch merges, the diff includes its changes.

hamdiakin and others added 28 commits October 22, 2026 04:56
Remove the constants and enum members of TruePath.Kernel32 that nothing in
the codebase uses, as recommended by the maintainer in ForNeVeR#241.

Among the dropped members are the two whose values did not match the
Windows headers: FileShare.Delete (0x03 instead of 0x04) and
FileAttributes.PosixSemantics (0x0100000 instead of 0x01000000).

The remaining declarations are now covered by Kernel32ConstantsTests,
pinning their values to the Windows headers so hand-copied constants
cannot silently go stale again.

Closes ForNeVeR#241
…vior w.r.t. the exceptions

Only return null when the target is not found, not in any other cases.
…rator

Add TruePath.PathIoGenerator, a Roslyn incremental source generator that
fills the other partial part of PathIo (marked with
GenerateSystemIoExtensionsAttribute) with forwarding extension methods for
every public static File/Directory method of the current target framework,
with the BCL XML documentation copied verbatim.

- PathIo.cs keeps only the members with custom behavior or documentation;
  pure forwarders are generated (93 methods on net8.0, 66 on
  netstandard2.0), introducing previously missing APIs (symlinks,
  OpenHandle, Replace, EnumerateDirectories, GetParent, etc.).
- Hand-written members win over generated ones, both by rewritten
  signature and by the forwarding call inside their body; File wins over
  Directory on duplicate signatures; path-io-exclusions.txt lists APIs
  deliberately not exposed.
- BCL XML docs reach the generator via AdditionalFiles (the command-line
  compiler does not attach them to references), are extracted
  line-by-line to survive malformed netstandard.xml, and param/paramref
  names are normalized against the generated parameters; path parameters
  keep the historical sourceFile/destFile names.
- Generated code uses short type names for imported namespaces.
- Tests: generator unit tests plus a reflection completeness test
  asserting BCL API ⊆ generated ∪ hand-written ∪ exclusions.
…ndex

- Drop dead test helpers, redundant nullability and qualifiers, an unused
  RenderFile parameter, and a redundant currentName check in BclDocIndex.
- Store parsed XElement members in the doc index instead of raw strings:
  XElement.Parse is now called exactly once per member with its result
  actually used, instead of a validation-only call with a discarded
  return value followed by a second parse at emission time. The cached
  element is cloned before doc formatting, which renames param elements
  in place.
- Strip the UTF-8 BOM from TruePath.sln introduced by an editor.
- Add a REUSE license companion for path-io-exclusions.txt.
- Pin the generator test references to the Basic.Reference.Assemblies
  package: discovering the SDK's reference packs from the test host's
  runtime directory is not reliable on CI runners where the runtime and
  the SDK live in different roots. The test helper now also surfaces the
  driver diagnostics when the expected generated tree is missing.
- The completeness test now mirrors the generator's third exclusion rule:
  BCL overloads that hand-written members forward to with path.Value as
  the first argument (previously flagged Directory.Delete(string,bool)).
The SPDX tags emitted into the generated file are string literals in the
generator source; REUSE picked them up as this file's own tags and failed
on the trailing C# syntax inside the expression.
- Reject nested marked classes with the new TPG004 diagnostic instead of
  silently generating a same-named top-level class, and derive the hint
  name from the full type name (sanitized) so same-named types cannot
  collide.
- Hoist the exclusion file texts and the XML documentation index into
  their own cached pipeline nodes: the .xml filter now happens before
  BclDocIndex.Build, so editing path-io-exclusions.txt no longer
  re-scans the ~15 MB documentation files, and the exclusion file is
  matched by exact file name.
- Move the hand-written member analysis into the syntax-anchored
  ForAttributeWithMetadataName transform (equatable MarkedType payload
  with sorted arrays), so it is cached across edits in unrelated files
  instead of re-running on every compilation change.
- Clone the member element inside DocFormatting.ToDocLines rather than
  at the call site, and read the XML documentation files through
  SourceText.Lines instead of ToString/Replace/Split (three fewer full
  copies of the text).

Generated output verified byte-identical on both target frameworks
before and after the change.
…int names

- Render every special type with its C# keyword inside generic arguments
  too: net10 span-based APIs like ReadOnlySpan<char> previously rendered
  as ReadOnlySpan<Char> because System_Char was missing from the table.
- Emit the generated file under the simple type name again
  (PathIo.Generated.g.cs): the full-name sanitization was only needed
  for nested marked types, which are now rejected with TPG004.

Both verified by temporarily building TruePath.SystemIo against net10.0,
which generates 112 methods including the new span- and Memory-based
overloads without any rule changes.
A handwritten member only covers the BCL overload it forwards to when its own
parameter list is the leading part of the overload's generated parameter list,
i.e. when it is that overload with its trailing arguments pinned. Overload
identity is the parameter list alone, so a member that forwards to the same BCL
method with a different parameter type is an addition next to the generated one
rather than a replacement for it.

GetFiles(AbsolutePath, LocalPathPattern) is exactly that case: it forwards to
Directory.GetFiles(string, string) but replaces the second parameter type, so
the old blanket "forwards to it" rule suppressed GetFiles(AbsolutePath, string)
and silently dropped it from the public API.

Signature identity also ignores nullability now, because C# overloads do not
differ by it and because a reference assembly compiled before nullable reference
types existed reports every reference type as oblivious.

AppendAllText and WriteAllText keep handwritten `string? contents` overloads for
the same reason: netstandard2.0's reference assembly has no NRT metadata, so the
generator would render a non-nullable parameter and break the released contract.
The BCL accepts null there by design (it writes an empty file or nothing), which
the released baseline records as `string?`.

The public API baselines gain the newly generated members: 25 for net8.0 and 16
for netstandard2.0.
Directory.GetParent returns null for a filesystem root, and the net8.0 baseline
already records GetParent as `DirectoryInfo?`. The netstandard2.0 reference
assembly carries no NRT metadata, so the generator renders the same member as
non-nullable and the baseline recorded a `DirectoryInfo!` contract that the
implementation does not honour. Declare the member by hand for the same reason
AppendAllText and WriteAllText are handwritten.

Also compare generated overload keys against handwritten ones with the
nullability-insensitive renderer on both sides. Previously the generated key kept
its annotations while the handwritten key dropped them, so the two only matched
for oblivious reference assemblies.
Add a net10.0 target (the current LTS) to TruePath.SystemIo. With the source
generator from ForNeVeR#249 in place this is nearly a one-line change: the generator
projects the per-target-framework BCL automatically, exposing 123 extension
methods on this target, including the new span- and Memory-based overloads:

- AppendAllText/WriteAllText with ReadOnlySpan<char> contents,
- AppendAllBytes/WriteAllBytes with ReadOnlySpan<byte>,
- the ReadOnlyMemory-based async counterparts of all of the above.

The existing netstandard2.0 and net8.0 targets are unchanged.

The net10.0 public API baseline records the 110 members that already exist on the
other targets as shipped, and only the 14 span- and Memory-based overloads this
target adds as unshipped. Keeping them shipped matches how the net8.0 and
netstandard2.0 baselines are maintained: each lists the full API surface of its
target at the last release rather than its difference from the other targets.

TruePath.Tests also gains a net10.0 target so the reflection completeness test
validates the generated net10.0 surface against the matching runtime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants