Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1ec2217

Browse files
committedMay 8, 2016
Auto merge of #33130 - eddyb:mir-const, r=nikomatsakis
Implement constant support in MIR. All of the intended features in `trans::consts` are now supported by `mir::constant`. The implementation is considered a temporary measure until `miri` replaces it. A `-Z orbit` bootstrap build will only translate LLVM IR from AST for `#[rustc_no_mir]` functions. Furthermore, almost all checks of constant expressions have been moved to MIR. In non-`const` functions, trees of temporaries are promoted, as per RFC 1414 (rvalue promotion). Promotion before MIR borrowck would allow reasoning about promoted values' lifetimes. The improved checking comes at the cost of four `[breaking-change]`s: * repeat counts must contain a constant expression, e.g.: `let arr = [0; { println!("foo"); 5 }];` used to be allowed (it behaved like `let arr = [0; 5];`) * dereference of a reference to a `static` cannot be used in another `static`, e.g.: `static X: [u8; 1] = [1]; static Y: u8 = (&X)[0];` was unintentionally allowed before * the type of a `static` *must* be `Sync`, irrespective of the initializer, e.g. `static FOO: *const T = &BAR;` worked as `&T` is `Sync`, but it shouldn't because `*const T` isn't * a `static` cannot wrap `UnsafeCell` around a type that *may* need drop, e.g. `static X: MakeSync<UnsafeCell<Option<String>>> = MakeSync(UnsafeCell::new(None));` was previously allowed based on the fact `None` alone doesn't need drop, but in `UnsafeCell` it can be later changed to `Some(String)` which *does* need dropping The drop restrictions are relaxed by RFC 1440 (#33156), which is implemented, but feature-gated. However, creating `UnsafeCell` from constants is unstable, so users can just enable the feature gate.
2 parents d91f8ab + 3b0e27c commit 1ec2217

File tree

76 files changed

+3411
-1351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3411
-1351
lines changed
 

‎mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ DEPS_rustc_lint := rustc log syntax rustc_const_eval
111111
DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags
112112
DEPS_rustc_metadata := rustc syntax rbml rustc_const_math
113113
DEPS_rustc_passes := syntax rustc core rustc_const_eval
114-
DEPS_rustc_mir := rustc syntax rustc_const_math rustc_const_eval
114+
DEPS_rustc_mir := rustc syntax rustc_const_math rustc_const_eval rustc_bitflags
115115
DEPS_rustc_resolve := arena rustc log syntax
116116
DEPS_rustc_platform_intrinsics := std
117117
DEPS_rustc_plugin := rustc rustc_metadata syntax rustc_mir

‎src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub enum DepNode<D: Clone + Debug> {
6464
IntrinsicCheck(D),
6565
MatchCheck(D),
6666
MirMapConstruction(D),
67+
MirPass(D),
6768
MirTypeck(D),
6869
BorrowCheck(D),
6970
RvalueCheck(D),
@@ -186,6 +187,7 @@ impl<D: Clone + Debug> DepNode<D> {
186187
IntrinsicCheck(ref d) => op(d).map(IntrinsicCheck),
187188
MatchCheck(ref d) => op(d).map(MatchCheck),
188189
MirMapConstruction(ref d) => op(d).map(MirMapConstruction),
190+
MirPass(ref d) => op(d).map(MirPass),
189191
MirTypeck(ref d) => op(d).map(MirTypeck),
190192
BorrowCheck(ref d) => op(d).map(BorrowCheck),
191193
RvalueCheck(ref d) => op(d).map(RvalueCheck),

0 commit comments

Comments
 (0)
Please sign in to comment.