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

Allow enum discriminants to not be uint, and use smallest possible size by default. #9613

Merged
merged 17 commits into from
Oct 30, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mk/tests.mk
Original file line number Diff line number Diff line change
@@ -455,6 +455,17 @@ $(foreach host,$(CFG_HOST_TRIPLES), \
$(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
))))))

# FIXME (#10104): Raise the stack size to work around rustpkg bypassing
# the code in rustc that would take care of it.
define DEF_RUSTPKG_STACK_FIX
$$(call TEST_OK_FILE,$(1),$(2),$(3),rustpkg): export RUST_MIN_STACK=8000000
endef

$(foreach host,$(CFG_HOST_TRIPLES), \
$(foreach target,$(CFG_TARGET_TRIPLES), \
$(foreach stage,$(STAGES), \
$(eval $(call DEF_RUSTPKG_STACK_FIX,$(stage),$(target),$(host))))))


######################################################################
# Rules for the compiletest tests (rpass, rfail, etc.)
27 changes: 25 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
@@ -281,7 +281,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
};
let config = &mut config;
let cmds = props.debugger_cmds.connect("\n");
let check_lines = props.check_lines.clone();
let check_lines = &props.check_lines;

// compile test file (it shoud have 'compile-flags:-g' in the header)
let mut ProcRes = compile_test(config, props, testfile);
@@ -315,11 +315,34 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {

let num_check_lines = check_lines.len();
if num_check_lines > 0 {
// Allow check lines to leave parts unspecified (e.g., uninitialized
// bits in the wrong case of an enum) with the notation "[...]".
let check_fragments: ~[~[&str]] = check_lines.map(|s| s.split_str_iter("[...]").collect());
// check if each line in props.check_lines appears in the
// output (in order)
let mut i = 0u;
for line in ProcRes.stdout.line_iter() {
if check_lines[i].trim() == line.trim() {
let mut rest = line.trim();
let mut first = true;
let mut failed = false;
for &frag in check_fragments[i].iter() {
let found = if first {
if rest.starts_with(frag) { Some(0) } else { None }
} else {
rest.find_str(frag)
};
match found {
None => {
failed = true;
break;
}
Some(i) => {
rest = rest.slice_from(i + frag.len());
}
}
first = false;
}
if !failed && rest.len() == 0 {
i += 1u;
}
if i == num_check_lines {
1 change: 1 addition & 0 deletions src/libextra/enum_set.rs
Original file line number Diff line number Diff line change
@@ -140,6 +140,7 @@ mod test {
use enum_set::*;

#[deriving(Eq)]
#[repr(uint)]
Copy link
Member

Choose a reason for hiding this comment

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

Are these (and some related tags) all still necessary? It looks like the enum should be automatically sized so this shouldn't be necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a transmute from uint to that enum a few lines farther down, in the enum_set::CLike impl; without the attribute, it won't compile.

enum Foo {
A, B, C
}
6 changes: 6 additions & 0 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
@@ -147,6 +147,7 @@ pub static Vector: TypeKind = 13;
pub static Metadata: TypeKind = 14;
pub static X86_MMX: TypeKind = 15;

#[repr(C)]
pub enum AtomicBinOp {
Xchg = 0,
Add = 1,
@@ -161,6 +162,7 @@ pub enum AtomicBinOp {
UMin = 10,
}

#[repr(C)]
pub enum AtomicOrdering {
NotAtomic = 0,
Unordered = 1,
@@ -173,6 +175,7 @@ pub enum AtomicOrdering {
}

// Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
#[repr(C)]
pub enum FileType {
AssemblyFile = 0,
ObjectFile = 1
@@ -194,20 +197,23 @@ pub enum AsmDialect {
}

#[deriving(Eq)]
#[repr(C)]
pub enum CodeGenOptLevel {
CodeGenLevelNone = 0,
CodeGenLevelLess = 1,
CodeGenLevelDefault = 2,
CodeGenLevelAggressive = 3,
}

#[repr(C)]
pub enum RelocMode {
RelocDefault = 0,
RelocStatic = 1,
RelocPIC = 2,
RelocDynamicNoPic = 3,
}

#[repr(C)]
pub enum CodeGenModel {
CodeModelDefault = 0,
CodeModelJITDefault = 1,
3 changes: 2 additions & 1 deletion src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
@@ -112,6 +112,7 @@ pub static tag_items_data_item_reexport_name: uint = 0x4f;

// used to encode crate_ctxt side tables
#[deriving(Eq)]
#[repr(uint)]
pub enum astencode_tag { // Reserves 0x50 -- 0x6f
tag_ast = 0x50,

@@ -143,7 +144,7 @@ impl astencode_tag {
pub fn from_uint(value : uint) -> Option<astencode_tag> {
let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag;
if !is_a_tag { None } else {
Some(unsafe { cast::transmute(value as int) })
Some(unsafe { cast::transmute(value) })
}
}
}
1 change: 1 addition & 0 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
@@ -989,6 +989,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_family(ebml_w, 't');
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(ecx, ebml_w, item.ident);
encode_attributes(ebml_w, item.attrs);
for v in (*enum_definition).variants.iter() {
encode_variant_id(ebml_w, local_def(v.node.id));
}
9 changes: 9 additions & 0 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
//! Context itself, span_lint should be used instead of add_lint.

use driver::session;
use middle::trans::adt; // for `adt::is_ffi_safe`
use middle::ty;
use middle::pat_util;
use metadata::csearch;
@@ -627,6 +628,14 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) {
"found rust type `uint` in foreign module, while \
libc::c_uint or libc::c_ulong should be used");
}
ast::DefTy(def_id) => {
if !adt::is_ffi_safe(cx.tcx, def_id) {
cx.span_lint(ctypes, ty.span,
"found enum type without foreign-function-safe \
representation annotation in foreign module");
// NOTE this message could be more helpful
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this is definitely worthy of a span_note explaining a little bit about repr, although that may require reorganization of linting somewhat to pass through the note.

}
}
_ => ()
}
}
Loading