Skip to content

Avoid filesystem dependencies in pathless Unix errno mapping - #137072

Open
MichalStrehovsky wants to merge 2 commits into
dotnet:mainfrom
MichalStrehovsky:errno
Open

MichalStrehovsky wants to merge 2 commits into
dotnet:mainfrom
MichalStrehovsky:errno

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

I wondered why Hello World needs to use Path APIs and check directory existence. This is the reason.

This provides a 1.84% size saving for the size-optimized WASI NativeAOT Release Hello World: 823,214 to 808,084 bytes, saving 15,130 bytes.

Select parent-directory handling through a static-abstract interface and sealed policy classes so pathless callers do not retain filesystem APIs. Preserve existing exception mappings and path-aware behavior.

This provides a 1.84% size saving for the size-optimized WASI NativeAOT Release Hello World: 823,214 to 808,084 bytes, saving 15,130 bytes.

Validated WASI Release/Checked errno mappings against the original implementation, filesystem error paths, Sleep, Preinitialization, and Hello World.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9bc3dfee-1040-4648-bdad-86922a749613
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

// For Windows compatibility, throw DirectoryNotFoundException instead of FileNotFoundException
// when the parent folder does not exist.
if (!isDirError && (path is null || ParentDirectoryExists(path)))
if (!isDirError && (path is null || TPathHandling.ParentDirectoryExists(path)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of duplicating the native code for the whole implementation using generic tricks, can we just check for ENOENT in the overload that may need the special path handling and forward the rest to the common impl?

@jkotas jkotas Nov 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

duplicating the native code

Ok - it is not duplicating the native code, but creating shared generic structures instead. Still, I think it would be better without generics.

Handle the ENOENT parent-directory check in the path-aware overload and share exception mapping through GetExceptionForIoErrnoCore. Document the separation needed for better trimming of pathless callers.

Validated WASI Release and Checked errno mappings, filesystem checks, Sleep, and Preinitialization. Matching-toolchain stripped Hello World saves 15,635 bytes (1.83%) versus the original mapper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a33cda55-cbd2-452e-9a41-5aa6a1c97aca

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants