Skip to content

Allow constant expressions to refer to other constants #1272

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

Closed
marijnh opened this issue Dec 8, 2011 · 3 comments
Closed

Allow constant expressions to refer to other constants #1272

marijnh opened this issue Dec 8, 2011 · 3 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-linkage Area: linking into static, shared libraries and binaries

Comments

@marijnh
Copy link
Contributor

marijnh commented Dec 8, 2011

const tag_a: uint = 12u;
const first_free_tag: uint = tag_a + 1u;

This'll require some resolution pass that complains about dependencies. It'll make implementing #1193 viable.

@ghost ghost assigned marijnh Dec 8, 2011
@marijnh
Copy link
Contributor Author

marijnh commented Dec 8, 2011

Actually, if we stick to our 'no init-time computing' policy, it won't be possible to support this for crate-external consts. Those aren't available at compile time, so if you say const x: int = std::int::max_value - 1;, the const will have to be filled in during initialization.

(Or we could just grab the current value from the .so, but that seems fragile.)

@graydon
Copy link
Contributor

graydon commented Dec 16, 2011

I think the crate-external part can probably block on figuring out how we're going to do cross-crate inlining. It's the same issue. If you export a constant as "inline" you should be able to use it in another crate as part of another const; the value gets copied across at compile time. Otherwise not.

(aside: it is sometimes held among language designers that inline-ness should be declared at the call site not the definition-side; if we go down that road then "const x = external::foo" could well count as an inline-requiring-use. or require some kind of expression-form declaration like "const x = inline(external::foo) + 1")

@catamorphism
Copy link
Contributor

Now that CCI is implemented, it should be easy to finish this?

@graydon graydon closed this as completed in f0775d7 Aug 9, 2012
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
* Update Rust Toolchain to 2022-06-09

* minor fixes. layout.might_permit_raw_init

* Rust made Call have an unconditional return Place. Remove unused codegen_drop hook

* New subcategories of pointer casts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-linkage Area: linking into static, shared libraries and binaries
Projects
None yet
Development

No branches or pull requests

3 participants