Skip to content

Fix non-determinism in Regex source generator - #78103

Merged
stephentoub merged 2 commits into
dotnet:mainfrom
stephentoub:regexdeterministic
Nov 10, 2022
Merged

Fix non-determinism in Regex source generator#78103
stephentoub merged 2 commits into
dotnet:mainfrom
stephentoub:regexdeterministic

Conversation

@stephentoub

@stephentoubstephentoub commented Nov 9, 2022

Copy link
Copy Markdown
Member

The source generator enumerates a Hashtable to write out its contents. When the keys of the Hashtable are strings, string hash code randomization may result in the order of that enumeration being different in different processes, leading to non-deterministic ordering of values written out and thus non-deterministic source generator output.

Fixes#76774 (though we'll want to backport this to release/7.0)
cc: @MichalStrehovsky, @ViktorHofer, @joperezr

@jaredpar, another source of non-determinism for your list.

The source generator enumerates a Hashtable to write out its contents. When the keys of the Hashtable are strings, string hash code randomization may result in the order of that enumeration being different in different processes, leading to non-deterministic ordering of values written out and thus non-deterministic source generator output.
@ghost

ghost commented Nov 9, 2022

Copy link
Copy Markdown

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

Issue Details

The source generator enumerates a Hashtable to write out its contents. When the keys of the Hashtable are strings, string hash code randomization may result in the order of that enumeration being different in different processes, leading to non-deterministic ordering of values written out and thus non-deterministic source generator output.

Fixes #76774
cc: @MichalStrehovsky, @ViktorHofer, @joperezr

@jaredpar, another source of non-determinism for your list.

Author:stephentoub
Assignees:-
Labels:

area-System.Text.RegularExpressions

Milestone:-

Comment threadsrc/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs Outdated

@joperezrjoperezr left a comment

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.

LGTM

@stephentoub
stephentoub merged commit 6b372fb into dotnet:mainNov 10, 2022
@stephentoub
stephentoub deleted the regexdeterministic branch November 10, 2022 10:42
@stephentoub

Copy link
Copy Markdown
MemberAuthor

/backport to release/7.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3436073260

@ghostghost locked as resolved and limited conversation to collaborators Dec 10, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build libs with /p:Deterministic=true some libraray make diff

4 participants

@stephentoub@jaredpar@danmoseley@joperezr