From 971b5d5151f79582252fa1281edb09cf86fd63ff Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Sat, 14 May 2011 19:02:30 -0700 Subject: Started adding support for return checking and non-returning function annotations * Reorganized typestate into several modules. * Made typestate check that any function with a non-nil return type returns a value. For now, the check is a warning and not an error (see next item). * Added a "bot" type (prettyprinted as _|_), for constructs like be, ret, break, cont, and fail that don't locally return a value that can be inspected. "bot" is distinct from "nil". There is no concrete syntax for _|_, while the concrete syntax for the nil type is (). * Added support to the parser for a ! annotation on functions whose result type is _|_. Such a function is required to have either a fail or a call to another ! function that is reached in all control flow paths. The point of this annotation is to mark functions like unimpl() and span_err(), so that an alt with a call to err() in one case isn't a false positive for the return-value checker. I haven't actually annotated anything with it yet. * Random bugfixes: * * Fixed bug in trans::trans_binary that was throwing away the cleanups for nested subexpressions of an and or or (tests: box-inside-if and box-inside-if2). ** In typeck, unify the expected type arguments of a tag with the actual specified arguments. --- src/comp/driver/rustc.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/comp/driver') diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index d538e1711a6..d9d5633d05d 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -9,7 +9,7 @@ import middle::trans; import middle::resolve; import middle::ty; import middle::typeck; -import middle::typestate_check; +import middle::tstate::ck; import back::link; import lib::llvm; import util::common; @@ -105,7 +105,8 @@ fn compile_input(session::session sess, if (sess.get_opts().run_typestate) { crate = time(time_passes, "typestate checking", - bind typestate_check::check_crate(crate, def_map)); + bind middle::tstate::ck::check_crate(node_type_table, + ty_cx, crate)); } auto llmod = time[llvm::ModuleRef](time_passes, "translation", -- cgit 1.4.1-3-g733a5 From 387a8888ee338bbe4628640cd4cd72037ac57032 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 16 May 2011 14:33:22 -0700 Subject: Fix get_os and get_arch get_os and get_arch were failing to return a value in the error case; they were also assuming that strings are indexed from 1. No idea how they ever worked, but anyway, fixed. --- src/comp/driver/rustc.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/comp/driver') diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index d9d5633d05d..6dd57ac0232 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -166,26 +166,31 @@ options: } fn get_os(str triple) -> session::os { - if (_str::find(triple, "win32") > 0 || - _str::find(triple, "mingw32") > 0 ) { + if (_str::find(triple, "win32") >= 0 || + _str::find(triple, "mingw32") >= 0 ) { ret session::os_win32; - } else if (_str::find(triple, "darwin") > 0) { ret session::os_macos; } - else if (_str::find(triple, "linux") > 0) { ret session::os_linux; } + } else if (_str::find(triple, "darwin") >= 0) { ret session::os_macos; } + else if (_str::find(triple, "linux") >= 0) { ret session::os_linux; } + else { log_err "Unknown operating system!"; fail; } } fn get_arch(str triple) -> session::arch { - if (_str::find(triple, "i386") > 0 || - _str::find(triple, "i486") > 0 || - _str::find(triple, "i586") > 0 || - _str::find(triple, "i686") > 0 || - _str::find(triple, "i786") > 0 ) { + if (_str::find(triple, "i386") >= 0 || + _str::find(triple, "i486") >= 0 || + _str::find(triple, "i586") >= 0 || + _str::find(triple, "i686") >= 0 || + _str::find(triple, "i786") >= 0 ) { ret session::arch_x86; - } else if (_str::find(triple, "x86_64") > 0) { + } else if (_str::find(triple, "x86_64") >= 0) { ret session::arch_x64; - } else if (_str::find(triple, "arm") > 0 || - _str::find(triple, "xscale") > 0 ) { + } else if (_str::find(triple, "arm") >= 0 || + _str::find(triple, "xscale") >= 0 ) { ret session::arch_arm; } + else { + log_err ("Unknown architecture! " + triple); + fail; + } } fn get_default_sysroot(str binary) -> str { -- cgit 1.4.1-3-g733a5