Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix #16274 - LazyInitializer.EnsureInitialized overload for reference types.#16507

Merged
stephentoub merged 7 commits into
dotnet:masterfrom
WinCPP:issue-3862
Mar 3, 2017
Merged

Fix #16274 - LazyInitializer.EnsureInitialized overload for reference types.#16507
stephentoub merged 7 commits into
dotnet:masterfrom
WinCPP:issue-3862

Conversation

@WinCPP
Copy link
Copy Markdown

@WinCPP WinCPP commented Feb 27, 2017

This PR is for the implementation of new overloads of LazyInitializer.EnsureInitialized for reference types.

@stephentoub @terrajobst @karelz Kindly review.

Depends on PR #9831 in CoreClr for compilation to succeed.

Thanks,
Mandar

@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Feb 27, 2017

Also please note that I missed creating a new branch in my fork for 16274 and commits ended up into 3862 branch. So you may see lots of commits below but the files changed tab shows only the relevant files. I tried creating a new branch and cherry-picking changes, but I got exhausted with git. Hope that is fine.

Thanks,
Mandar

Assert.Equal(1, ClassWithInitFunction.CountInitialized);
}

private class ClassBase
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I had created this as common base with counters and sleep function to be used for ctor based API overload test case. Now that is removed, but I missed merging this into the derived class...

@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Feb 27, 2017

@stephentoub @karelz seems like the builds are failing because of new API implementation in coreclr not yet being available on corefx side. Did I file the PR too early? Kindly advise.

@stephentoub
Copy link
Copy Markdown
Member

seems like the builds are failing because of new API implementation in coreclr not yet being available on corefx side

Right, this won't work until the CoreCLR changes are merged and resulting binaries are consumed into CoreFx.

Did I file the PR too early? Kindly advise.

It's fine. We can re-run it once the changes are available. It'd be good to link to that dependency PR from this PR description, though.

As an aside, before you submit PRs, please rebase your branch on top of the latest master, or at least squash it; there are 28 commits in this PR, most of which are merge commits.

@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Feb 27, 2017

As an aside, before you submit PRs, please rebase your branch on top of the latest master, or at least squash it; there are 28 commits in this PR, most of which are merge commits.

Actually, when I click 'Sync' button on github UI, it seems to be doing the push to remote, along with pull, and that is how all my commits were pushed to remote. Is it ok in this repository to use 'git push --force-with-lease' to push the rebased commit...?

@stephentoub
Copy link
Copy Markdown
Member

Is it ok in this repository to use 'git push --force-with-lease' to push the rebased commit...?

You don't have push access to the dotnet/corefx repo. But you can push whatever you want to your WinCPP/corefx repo, and any changes you make to your issue-3862 branch will be reflected in this PR.

@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Feb 28, 2017

@stephentoub @terrajobst @karelz I'm not sure what happened, but the squashing that I did, this PR got closed. I have reopened it. Now I see 1 commit with 2 files. Please check and review.

Thanks!

string f = null;
object fLock = null;
Assert.Equal(strTemplate, LazyInitializer.EnsureInitialized(ref f, ref fLock, () => strTemplate));
Assert.Equal(strTemplate, f);
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.

We should also Assert.NotNull(fLock)

string g = strTemplate;
object gLock = null;
Assert.Equal(strTemplate, LazyInitializer.EnsureInitialized(ref g, ref gLock, () => strTemplate + "bar"));
Assert.Equal(strTemplate, g);
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.

Here we should Assert.Null(gLock)

Copy link
Copy Markdown
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks

@stephentoub
Copy link
Copy Markdown
Member

stephentoub commented Mar 2, 2017

@WinCPP, this is failing because the added API doesn't yet exist in corert. Two things:

  1. Can you port your addition to https://github.com/dotnet/corert/blob/master/src/System.Private.CoreLib/src/System/Threading/LazyInitializer.cs ?
  2. For this PR to go through, we'll need to suppress the warning:
D:\j\workspace\AllConfigurat---c1564d53\Tools\ApiCompat.targets(53,5): error : MembersMustExist : Member 'System.Threading.LazyInitializer.EnsureInitialized<T>(T, System.Object, System.Func<T>)' does not exist in the implementation but it does exist in the contract. [D:\j\workspace\AllConfigurat---c1564d53\src\System.Threading\src\System.Threading.csproj]

That can be done by editing the https://github.com/dotnet/corefx/blob/master/src/System.Threading/src/ApiCompatBaseline.uapaot.txt file; you can use this recent PR as an example:
https://github.com/dotnet/corefx/pull/16561/files

@stephentoub
Copy link
Copy Markdown
Member

@WinCPP, why did you close this?

@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Mar 2, 2017

By mistake... I was trying to squash commit and same that as other day happened... Can you please help reopen it... I don't know what happened...

I have got the test case changes ready and I was trying to commit it... with force-with-lease... the 'git status' showed files in green color so I did a git push... (this was after git reset --soft git merge-base origin/master origin/issue-3862... looks like even if the files are in green, it requires a commit before git push --force-with-lease...

@stephentoub
Copy link
Copy Markdown
Member

I'm unable to because the new commits you added are no longer in your branch, so there's nothing new for the PR to display.
https://github.com/WinCPP/corefx/commits/issue-3862

not take boolean for tracking initialization status of the reference
type object. Null check on the object parameter is sufficient to whether
or not it has been initialized.
@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Mar 2, 2017

Phew... back open... I will do the changes that you mentioned above now... @stephentoub does it look ok from your side?

Assert.NotNull(LazyInitializer.EnsureInitialized(ref a, ref aInit, ref aLock));
Assert.NotNull(a);
Assert.True(aInit);
Assert.NotNull(aLock);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@stephentoub I have added asserts for true / not null in earlier test cases as well. Please let me know if this is ok...

@karelz
Copy link
Copy Markdown
Member

karelz commented Mar 2, 2017

@stephentoub for my own education - how is CoreRT API surface/implementation propagated to CoreFX? Is there similar regular ingestion like for CoreCLR?

not take boolean for tracking initialization status of the reference
type object. Null check on the object parameter is sufficient to whether
or not it has been initialized.
@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Mar 2, 2017

@stephentoub I have done the two tasks

  1. Porting code to corert: pull request link.
  2. Done the modifications to suppress warnings.

Please check.

@stephentoub
Copy link
Copy Markdown
Member

Is there similar regular ingestion like for CoreCLR?

Yes

CannotRemoveBaseTypeOrInterface : Type 'System.Threading.Tasks.Task' does not implement interface 'System.IDisposable' in the implementation but it does in the contract.
MembersMustExist : Member 'System.Threading.Tasks.Task.Dispose()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Threading.Tasks.Task.Dispose(System.Boolean)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Threading.LazyInitializer.EnsureInitialized<T>(T, System.Object, System.Func<T>)'
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.

This needs to be the full error message, as in the other cases in the file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm sorry. While cutting out the trailing csproj in compilation error, I chewed up a bit more. I should have seen other lines. Honestly, been doing silly mistakes over my limit. Need to introspect why.

@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Mar 2, 2017

@stephentoub Is the above edit sufficient... because those two builds are still failing with same error... I hope I'm not missing something else.

@stephentoub
Copy link
Copy Markdown
Member

Is the above edit sufficient

It's the wrong file. It needs to be the one in src\System.Threading\ rather than src\System.Runtime

@WinCPP
Copy link
Copy Markdown
Author

WinCPP commented Mar 2, 2017

It's the wrong file. It needs to be the one in src\System.Threading\ rather than src\System.Runtime
😶 hope it goes through...

Copy link
Copy Markdown
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks!

@stephentoub stephentoub merged commit bb8a57c into dotnet:master Mar 3, 2017
@karelz karelz modified the milestone: 2.0.0 Mar 7, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…for reference types. (dotnet/corefx#16507)

* LazyInitializer.EnsureInitialized overload for reference types that does
not take boolean for tracking initialization status of the reference
type object. Null check on the object parameter is sufficient to whether
or not it has been initialized.

Commit migrated from dotnet/corefx@bb8a57c
Sign up for free to 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.

6 participants