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

Float infer #3940

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions src/libcore/extfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub mod ct {
pub enum Piece { PieceString(~str), PieceConv(Conv), }
pub type ErrorFn = fn@(&str) -> ! ;

pub fn parse_fmt_string(s: &str, error: ErrorFn) -> ~[Piece] {
pub fn parse_fmt_string(s: &str, err: ErrorFn) -> ~[Piece] {
let mut pieces: ~[Piece] = ~[];
let lim = str::len(s);
let mut buf = ~"";
Expand All @@ -103,15 +103,15 @@ pub mod ct {
if curr == ~"%" {
i += 1;
if i >= lim {
error(~"unterminated conversion at end of string");
err(~"unterminated conversion at end of string");
}
let curr2 = str::slice(s, i, i+1);
if curr2 == ~"%" {
buf += curr2;
i += 1;
} else {
buf = flush_buf(move buf, &mut pieces);
let rs = parse_conversion(s, i, lim, error);
let rs = parse_conversion(s, i, lim, err);
pieces.push(copy rs.piece);
i = rs.next;
}
Expand Down Expand Up @@ -143,13 +143,13 @@ pub mod ct {
}
}
pub fn parse_conversion(s: &str, i: uint, lim: uint,
error: ErrorFn) ->
err: ErrorFn) ->
{piece: Piece, next: uint} {
let parm = parse_parameter(s, i, lim);
let flags = parse_flags(s, parm.next, lim);
let width = parse_count(s, flags.next, lim);
let prec = parse_precision(s, width.next, lim);
let ty = parse_type(s, prec.next, lim, error);
let ty = parse_type(s, prec.next, lim, err);
return {piece:
PieceConv({param: parm.param,
flags: copy flags.flags,
Expand Down Expand Up @@ -239,9 +239,9 @@ pub mod ct {
}
} else { {count: CountImplied, next: i} };
}
pub fn parse_type(s: &str, i: uint, lim: uint, error: ErrorFn) ->
pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) ->
{ty: Ty, next: uint} {
if i >= lim { error(~"missing type in conversion"); }
if i >= lim { err(~"missing type in conversion"); }
let tstr = str::slice(s, i, i+1u);
// FIXME (#2249): Do we really want two signed types here?
// How important is it to be printf compatible?
Expand All @@ -268,7 +268,7 @@ pub mod ct {
TyFloat
} else if tstr == ~"?" {
TyPoly
} else { error(~"unknown type in conversion: " + tstr) };
} else { err(~"unknown type in conversion: " + tstr) };
return {ty: t, next: i + 1u};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/send_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait SendMap<K:Eq Hash, V: Copy> {

/// Open addressing with linear probing.
pub mod linear {
const initial_capacity: uint = 32u; // 2^5
const INITIAL_CAPACITY: uint = 32u; // 2^5

struct Bucket<K:Eq Hash,V> {
hash: uint,
Expand All @@ -62,7 +62,7 @@ pub mod linear {
}

pub fn LinearMap<K:Eq Hash,V>() -> LinearMap<K,V> {
linear_map_with_capacity(32)
linear_map_with_capacity(INITIAL_CAPACITY)
}

pub fn linear_map_with_capacity<K:Eq Hash,V>(
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,15 +959,15 @@ extern mod llvm {
/** Opens an object file. */
fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
/** Closes an object file. */
fn LLVMDisposeObjectFile(ObjectFile: ObjectFileRef);
fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);

/** Enumerates the sections in an object file. */
fn LLVMGetSections(ObjectFile: ObjectFileRef) -> SectionIteratorRef;
fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
/** Destroys a section iterator. */
fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
/** Returns true if the section iterator is at the end of the section
list: */
fn LLVMIsSectionIteratorAtEnd(ObjectFile: ObjectFileRef,
fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
SI: SectionIteratorRef) -> Bool;
/** Moves the section iterator to point to the next section. */
fn LLVMMoveToNextSection(SI: SectionIteratorRef);
Expand Down Expand Up @@ -1228,9 +1228,9 @@ struct object_file_res {
drop { llvm::LLVMDisposeObjectFile(self.ObjectFile); }
}

fn object_file_res(ObjectFile: ObjectFileRef) -> object_file_res{
fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
object_file_res {
ObjectFile: ObjectFile
ObjectFile: ObjFile
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
w.write_char('I');
w.write_uint(id.to_uint());
}
ty::ty_infer(ty::FloatVar(id)) => {
w.write_char('X');
w.write_char('F');
w.write_uint(id.to_uint());
}
ty::ty_param({idx: id, def_id: did}) => {
w.write_char('p');
w.write_str(cx.ds(did));
Expand Down
10 changes: 9 additions & 1 deletion src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,15 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
visit::fk_anon(*) | visit::fk_fn_block(*) |
visit::fk_method(*) | visit::fk_item_fn(*) |
visit::fk_dtor(*) => {
self.fn_args = @decl.inputs.map(|i| i.id );
let mut fn_args = ~[];
for decl.inputs.each |input| {
do pat_util::pat_bindings(self.tcx().def_map,
input.pat)
|_a, pat_id, _b, _c| {
fn_args.push(pat_id);
}
}
self.fn_args = @move fn_args;
}
}

Expand Down
43 changes: 39 additions & 4 deletions src/librustc/middle/check_alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) {
visit::visit_crate(*crate, (), visit::mk_vt(@{
visit_expr: |a,b,c| check_expr(tcx, a, b, c),
visit_local: |a,b,c| check_local(tcx, a, b, c),
visit_fn: |kind, decl, body, sp, id, e, v|
check_fn(tcx, kind, decl, body, sp, id, e, v),
.. *visit::default_visitor::<()>()
}));
tcx.sess.abort_if_errors();
Expand Down Expand Up @@ -372,8 +374,8 @@ fn specialize(tcx: ty::ctxt, r: ~[@pat], ctor_id: ctor, arity: uint,
ty::ty_rec(flds) => flds,
_ => fail ~"bad type for pat_rec"
};
let args = vec::map(ty_flds, |ty_f| {
match vec::find(flds, |f| f.ident == ty_f.ident ) {
let args = vec::map(ty_flds, |ty_fld| {
match vec::find(flds, |f| f.ident == ty_fld.ident ) {
Some(f) => f.pat,
_ => wild()
}
Expand All @@ -386,8 +388,8 @@ fn specialize(tcx: ty::ctxt, r: ~[@pat], ctor_id: ctor, arity: uint,
def_variant(_, variant_id) => {
if variant(variant_id) == ctor_id {
// XXX: Is this right? --pcw
let args = flds.map(|ty_f| {
match vec::find(flds, |f| f.ident == ty_f.ident) {
let args = flds.map(|ty_field| {
match vec::find(flds, |f| f.ident == ty_field.ident) {
Some(f) => f.pat,
_ => wild()
}
Expand Down Expand Up @@ -465,6 +467,39 @@ fn check_local(tcx: ty::ctxt, loc: @local, &&s: (), v: visit::vt<()>) {
}
}

fn check_fn(tcx: ty::ctxt,
kind: visit::fn_kind,
decl: fn_decl,
body: blk,
sp: span,
id: node_id,
&&s: (),
v: visit::vt<()>) {
visit::visit_fn(kind, decl, body, sp, id, s, v);
for decl.inputs.each |input| {
if is_refutable(tcx, input.pat) {
tcx.sess.span_err(input.pat.span,
~"refutable pattern in function argument");
}

// Ensure that no complex patterns are used if the argument doesn't
// have + mode.
match input.pat.node {
pat_ident(*) => {} // Always OK.
_ => {
match ty::resolved_mode(tcx, input.mode) {
by_copy => {} // OK.
_ => {
tcx.sess.span_err(input.pat.span,
~"patterns may only be used in \
arguments with + mode");
}
}
}
}
}
}

fn is_refutable(tcx: ty::ctxt, pat: &pat) -> bool {
match tcx.def_map.find(pat.id) {
Some(def_variant(enum_id, _)) => {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ fn lit_to_const(lit: @lit) -> const_val {
lit_uint(n, _) => const_uint(n),
lit_int_unsuffixed(n) => const_int(n),
lit_float(n, _) => const_float(float::from_str(*n).get() as f64),
lit_float_unsuffixed(n) =>
const_float(float::from_str(*n).get() as f64),
lit_nil => const_int(0i64),
lit_bool(b) => const_bool(b)
}
Expand Down
26 changes: 18 additions & 8 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,13 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
debug!("creating fn_maps: %x", ptr::addr_of(&(*fn_maps)) as uint);

for decl.inputs.each |arg| {
debug!("adding argument %d", arg.id);
let mode = ty::resolved_mode(self.tcx, arg.mode);
(*fn_maps).add_variable(Arg(arg.id, arg.ident, mode));
do pat_util::pat_bindings(self.tcx.def_map, arg.pat)
|_bm, arg_id, _x, path| {
debug!("adding argument %d", arg_id);
let ident = ast_util::path_to_ident(path);
(*fn_maps).add_variable(Arg(arg_id, ident, mode));
}
};

// gather up the various local variables, significant expressions,
Expand Down Expand Up @@ -447,7 +451,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
});
check_vt.visit_block(body, lsets, check_vt);
lsets.check_ret(id, sp, fk, entry_ln);
lsets.warn_about_unused_args(sp, decl, entry_ln);
lsets.warn_about_unused_args(decl, entry_ln);
}

fn visit_local(local: @local, &&self: @IrMaps, vt: vt<@IrMaps>) {
Expand Down Expand Up @@ -937,8 +941,11 @@ impl Liveness {
// the end. This will prevent us from moving out of
// such variables but also prevent us from registering
// last uses and so forth.
let var = self.variable(arg.id, blk.span);
self.acc(self.s.exit_ln, var, ACC_READ);
do pat_util::pat_bindings(self.tcx.def_map, arg.pat)
|_bm, arg_id, _sp, _path| {
let var = self.variable(arg_id, blk.span);
self.acc(self.s.exit_ln, var, ACC_READ);
}
}
by_move | by_copy => {
// These are owned modes. If we don't use the
Expand Down Expand Up @@ -1791,10 +1798,13 @@ impl @Liveness {
if name[0] == ('_' as u8) {None} else {Some(name)}
}

fn warn_about_unused_args(sp: span, decl: fn_decl, entry_ln: LiveNode) {
fn warn_about_unused_args(decl: fn_decl, entry_ln: LiveNode) {
for decl.inputs.each |arg| {
let var = self.variable(arg.id, arg.ty.span);
self.warn_about_unused(sp, entry_ln, var);
do pat_util::pat_bindings(self.tcx.def_map, arg.pat)
|_bm, p_id, sp, _n| {
let var = self.variable(p_id, sp);
self.warn_about_unused(sp, entry_ln, var);
}
}
}

Expand Down
50 changes: 38 additions & 12 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use syntax::ast::{foreign_item, foreign_item_const, foreign_item_fn, ge};
use syntax::ast::{gt, ident, impure_fn, inherited, item, item_class};
use syntax::ast::{item_const, item_enum, item_fn, item_foreign_mod};
use syntax::ast::{item_impl, item_mac, item_mod, item_trait, item_ty, le};
use syntax::ast::{local, local_crate, lt, method, module_ns, mul, ne, neg};
use syntax::ast::{node_id, pat, pat_enum, pat_ident, path, prim_ty};
use syntax::ast::{local, local_crate, lt, method, mode, module_ns, mul, ne};
use syntax::ast::{neg, node_id, pat, pat_enum, pat_ident, path, prim_ty};
use syntax::ast::{pat_box, pat_lit, pat_range, pat_rec, pat_struct};
use syntax::ast::{pat_tup, pat_uniq, pat_wild, private, provided, public};
use syntax::ast::{required, rem, self_ty_, shl, shr, stmt_decl};
Expand Down Expand Up @@ -103,12 +103,32 @@ struct Export2 {

enum PatternBindingMode {
RefutableMode,
IrrefutableMode
LocalIrrefutableMode,
ArgumentIrrefutableMode(mode)
}

impl PatternBindingMode : cmp::Eq {
pure fn eq(other: &PatternBindingMode) -> bool {
(self as uint) == ((*other) as uint)
match self {
RefutableMode => {
match *other {
RefutableMode => true,
_ => false
}
}
LocalIrrefutableMode => {
match *other {
LocalIrrefutableMode => true,
_ => false
}
}
ArgumentIrrefutableMode(mode_a) => {
match *other {
ArgumentIrrefutableMode(mode_b) => mode_a == mode_b,
_ => false
}
}
}
}
pure fn ne(other: &PatternBindingMode) -> bool { !self.eq(other) }
}
Expand Down Expand Up @@ -3770,15 +3790,17 @@ impl Resolver {
}
Some(declaration) => {
for declaration.inputs.each |argument| {
let name = argument.ident;
let def_like = dl_def(def_arg(argument.id,
argument.mode));
(*function_value_rib).bindings.insert(name, def_like);
let binding_mode =
ArgumentIrrefutableMode(argument.mode);
self.resolve_pattern(argument.pat,
binding_mode,
Immutable,
None,
visitor);

self.resolve_type(argument.ty, visitor);

debug!("(resolving function) recorded argument `%s`",
self.session.str_of(name));
debug!("(resolving function) recorded argument");
}

self.resolve_type(declaration.output, visitor);
Expand Down Expand Up @@ -4013,7 +4035,7 @@ impl Resolver {
}

// Resolve the pattern.
self.resolve_pattern(local.node.pat, IrrefutableMode, mutability,
self.resolve_pattern(local.node.pat, LocalIrrefutableMode, mutability,
None, visitor);
}

Expand Down Expand Up @@ -4249,10 +4271,14 @@ impl Resolver {

def_binding(pattern.id, binding_mode)
}
IrrefutableMode => {
LocalIrrefutableMode => {
// But for locals, we use `def_local`.
def_local(pattern.id, is_mutable)
}
ArgumentIrrefutableMode(argument_mode) => {
// And for function arguments, `def_arg`.
def_arg(pattern.id, argument_mode)
}
};

// Record the definition so that later passes
Expand Down
Loading