Skip to content

Allow and implement recursive static variables.#26630

Merged
bors merged 3 commits into
rust-lang:masterfrom
eefriedman:recursive-static
Jul 25, 2015
Merged

Allow and implement recursive static variables.#26630
bors merged 3 commits into
rust-lang:masterfrom
eefriedman:recursive-static

Conversation

@eefriedman

Copy link
Copy Markdown
Contributor

_Edit: Fixed now._ I'm pretty sure the way I'm using LLVMReplaceAllUsesWith here is
unsafe... but before I figure out how to fix that, I'd like a
reality-check: is this actually useful?

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb

eddyb commented Jun 28, 2015

Copy link
Copy Markdown
Contributor

This would be really neat for &'static cycles, e.g. a safe doubly linked static list.

@eefriedman eefriedman changed the title [WIP] Allow and implement recursive static variables. Allow and implement recursive static variables. Jun 28, 2015
@eefriedman

Copy link
Copy Markdown
Contributor Author

Updated; should be safe now. Also added an extra commit to remove the restriction on types which can't be instantiated, to allow implementing a static doubly-linked list.

@alexcrichton

Copy link
Copy Markdown
Member

cc @rust-lang/lang, not sure if this is a large enough change to warrant an RFC, it'd probably be nice to have a "static specification" but that may be a bit of a pipe dream.

@nrc

nrc commented Jun 29, 2015

Copy link
Copy Markdown
Member

I don't think it needs an RFC and I think it is a good idea. I do think it probably deserves some eyes on it, so I created an announcement in our internals discourse: https://internals.rust-lang.org/t/heads-up-allowing-recursive-static-variables/2309

@ftxqxd

ftxqxd commented Jun 30, 2015

Copy link
Copy Markdown
Contributor

Are nonsensical cycles like static FOO: T = FOO; and static FOO: T = BAR; static BAR: T = FOO; still disallowed by this PR?

Also, perhaps the tests that are deleted in this PR should instead just be moved to run-pass.

@eefriedman

Copy link
Copy Markdown
Contributor Author

@P1start The initializer for a static item can't read the contents of any static item, so static FOO: T = FOO; is still rejected.

Not sure the tests are particularly useful, but I guess I could move them.

@eefriedman

Copy link
Copy Markdown
Contributor Author

Tests re-added.

@pnkfelix

pnkfelix commented Jul 2, 2015

Copy link
Copy Markdown
Contributor

Surely this should at least be feature gated?

@pnkfelix

pnkfelix commented Jul 2, 2015

Copy link
Copy Markdown
Contributor

(that is, I can understand side-stepping the RFC process, though I'm not 100% sure I agree with doing so, even for a feature like this. But with or without an RFC, it still seems prudent to feature-gate new functionality in the language, just so that we can kick the tires on it in nightly without worry about whether it could inadvertantly leak out into the other distribution channels.)

@eefriedman

Copy link
Copy Markdown
Contributor Author

static_recursion feature gate added. I strongly doubt there will be any issues in practice, but better to be on the safe side, I guess.

@eddyb

eddyb commented Jul 3, 2015

Copy link
Copy Markdown
Contributor

AFAICT you had to revert the removal of is_instantiable. I guess it will go away once the feature gate is lifted.

@bors

bors commented Jul 7, 2015

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #26747) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix

pnkfelix commented Jul 8, 2015

Copy link
Copy Markdown
Contributor

@eefriedman sorry I have not reviewed this yet. I hope I will get to it this week but I am not sure if I will.

@eefriedman

Copy link
Copy Markdown
Contributor Author

@pnkfelix Ping.

@pnkfelix

Copy link
Copy Markdown
Contributor

@eefriedman sorry for the delay

Comment thread src/librustc_trans/trans/context.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: as far as I can tell the acronym "RAUW" does not occur elsewhere in our code.

So, please expand this occurrence and then include the acronym afterwards in parentheses, effectively defining the acronym. Like so: "static variables which need to be passed through the LLVM Replace All Uses With (RAUW) functionality"

@pnkfelix

Copy link
Copy Markdown
Contributor

okay looks good as far as my knowledge of LLVM goes.

r=me after next rebase (and hopefully the noted nit is addressed).

There isn't any particularly good reason for this restriction, so just
get rid of it, and fix trans to handle this case.
The borrow checker doesn't allow constructing such a type at runtime
using safe code, but there isn't any reason to ban them in the type checker.

Included in this commit is an example of a neat static doubly-linked list.

Feature-gated under the static_recursion gate to be on the safe side, but
there are unlikely to be any reasons this shouldn't be turned on by
default.
@eefriedman

Copy link
Copy Markdown
Contributor Author

@pnkfelix Rebased.

@pnkfelix

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jul 25, 2015

Copy link
Copy Markdown
Collaborator

📌 Commit 0eea0f6 has been approved by pnkfelix

@bors

bors commented Jul 25, 2015

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 0eea0f6 with merge e333e6a...

bors added a commit that referenced this pull request Jul 25, 2015
***Edit: Fixed now.*** I'm pretty sure the way I'm using LLVMReplaceAllUsesWith here is
unsafe... but before I figure out how to fix that, I'd like a
reality-check: is this actually useful?
@bors bors merged commit 0eea0f6 into rust-lang:master Jul 25, 2015
@brson brson added the relnotes Marks issues that should be documented in the release notes of the next release. label Jul 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotes Marks issues that should be documented in the release notes of the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants