Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Arc::new_cyclic #75505

Merged
merged 5 commits into from
Aug 24, 2020
Merged

Add Arc::new_cyclic #75505

merged 5 commits into from
Aug 24, 2020

Conversation

Dylan-DPC-zz
Copy link

@Dylan-DPC-zz Dylan-DPC-zz commented Aug 13, 2020

Rework of #72443

References #75861

cc @Diggsey @RalfJung

r? @KodrAus

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 13, 2020
/// # Examples
/// ```
/// #![feature(arc_new_cyclic)]
/// #![allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// #![allow(dead_code)]
/// # #![allow(dead_code)]

@@ -328,6 +328,79 @@ impl<T> Arc<T> {
Self::from_inner(Box::leak(x).into())
}

/// Constructs a new `Arc<T>` using a weak reference to itself. Attempting
/// to upgrade the weak reference before this function returns will result
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the indentation for docs is off starting here.

Copy link
Member

Choose a reason for hiding this comment

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

That's odd, is this not just cherry-picking the commits of #72443?

Copy link
Author

Choose a reason for hiding this comment

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

cherry picking took a while due to some conflicts since this pr was small, I pasted the contents directly into respectively files. I ran tidy again now which would have fixed this issues

/// let foo = Arc::new_cyclic(|me| Foo {
/// me: me.clone(),
/// });
/// ```
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the use case for this example? I don't understand by just looking at the example, maybe we should provide a more realistic use case?

library/alloc/src/sync.rs Outdated Show resolved Hide resolved
@@ -1608,8 +1682,11 @@ impl<T: ?Sized> Weak<T> {
abort();
}

// Relaxed is valid for the same reason it is on Arc's Clone impl
match inner.strong.compare_exchange_weak(n, n + 1, Relaxed, Relaxed) {
// Relaxed is fine for the failure case because we don't have any expectations about the new state.
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this comment too long?

Copy link
Contributor

Choose a reason for hiding this comment

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

I find it helpful so +1

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

As noted before, a similar API should be added to Rc.

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 20, 2020
@KodrAus KodrAus mentioned this pull request Aug 24, 2020
4 tasks
/// });
/// ```
#[inline]
#[unstable(feature = "arc_new_cyclic", issue = "none")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[unstable(feature = "arc_new_cyclic", issue = "none")]
#[unstable(feature = "arc_new_cyclic", issue = "75861")]

@KodrAus
Copy link
Contributor

KodrAus commented Aug 24, 2020

I've opened up #75861 as a tracking issue with a note about adding a similar API for Rc.

r=me with the current suggested edits added.

@Dylan-DPC-zz
Copy link
Author

@bors r=KodrAus

@bors
Copy link
Contributor

bors commented Aug 24, 2020

📌 Commit c26a8d5 has been approved by KodrAus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 24, 2020
@bors
Copy link
Contributor

bors commented Aug 24, 2020

⌛ Testing commit c26a8d5 with merge 9288641c15b77a6a4651e2d4ca5a6583d0e19d92...

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
+ /scripts/validate-toolstate.sh
Cloning into 'rust-toolstate'...
<Nothing changed>
Traceback (most recent call last):
  File "../../src/tools/publish_toolstate.py", line 283, in <module>
    validate_maintainers(repo, github_token)
  File "../../src/tools/publish_toolstate.py", line 84, in validate_maintainers
    'Accept': 'application/vnd.github.hellcat-preview+json',
  File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
  local time: Mon Aug 24 02:10:43 UTC 2020
  network time: Mon, 24 Aug 2020 02:10:44 GMT
== end clock drift check ==
== end clock drift check ==
##[error]Process completed with exit code 1.
Terminate orphan process: pid (6067) (node)
Terminate orphan process: pid (6094) (python)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@bors
Copy link
Contributor

bors commented Aug 24, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 24, 2020
@RalfJung
Copy link
Member

Not sure what this is:

+ /scripts/validate-toolstate.sh
Cloning into 'rust-toolstate'...
<Nothing changed>
Traceback (most recent call last):
  File "../../src/tools/publish_toolstate.py", line 283, in <module>
    validate_maintainers(repo, github_token)
  File "../../src/tools/publish_toolstate.py", line 84, in validate_maintainers
    'Accept': 'application/vnd.github.hellcat-preview+json',
  File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

But let's hope it's a spurious network issue.

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 24, 2020
@bors
Copy link
Contributor

bors commented Aug 24, 2020

⌛ Testing commit c26a8d5 with merge 9d74562...

@bors
Copy link
Contributor

bors commented Aug 24, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: KodrAus
Pushing 9d74562 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 24, 2020
@bors bors merged commit 9d74562 into rust-lang:master Aug 24, 2020
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants