workaround a horribly obscure resolve bug
This commit is contained in:
parent
a559329692
commit
67ca37ac61
6 changed files with 79 additions and 76 deletions
|
@ -1683,7 +1683,7 @@ fn trans_assign_op(bcx: block, ex: @ast::expr, op: ast::binop,
|
||||||
|
|
||||||
fn root_value(bcx: block, val: ValueRef, ty: ty::t,
|
fn root_value(bcx: block, val: ValueRef, ty: ty::t,
|
||||||
scope_id: ast::node_id) {
|
scope_id: ast::node_id) {
|
||||||
if !bcx.sess().opts.no_asm_comments {
|
if !bcx.sess().no_asm_comments() {
|
||||||
add_comment(bcx, #fmt["preserving until end of scope %d",
|
add_comment(bcx, #fmt["preserving until end of scope %d",
|
||||||
scope_id]);
|
scope_id]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ an rptr (`&r.T`) use the region `r` that appears in the rptr.
|
||||||
"];
|
"];
|
||||||
|
|
||||||
import check::fn_ctxt;
|
import check::fn_ctxt;
|
||||||
|
import rscope::*;
|
||||||
|
|
||||||
iface ast_conv {
|
iface ast_conv {
|
||||||
fn tcx() -> ty::ctxt;
|
fn tcx() -> ty::ctxt;
|
||||||
|
@ -55,74 +56,6 @@ iface ast_conv {
|
||||||
fn ty_infer(span: span) -> ty::t;
|
fn ty_infer(span: span) -> ty::t;
|
||||||
}
|
}
|
||||||
|
|
||||||
iface region_scope {
|
|
||||||
fn anon_region() -> result<ty::region, str>;
|
|
||||||
fn named_region(id: str) -> result<ty::region, str>;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum empty_rscope { empty_rscope }
|
|
||||||
impl of region_scope for empty_rscope {
|
|
||||||
fn anon_region() -> result<ty::region, str> {
|
|
||||||
result::err("region types are not allowed here")
|
|
||||||
}
|
|
||||||
fn named_region(id: str) -> result<ty::region, str> {
|
|
||||||
if id == "static" { result::ok(ty::re_static) }
|
|
||||||
else { result::err("only the static region is allowed here") }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum type_rscope = ast::region_param;
|
|
||||||
impl of region_scope for type_rscope {
|
|
||||||
fn anon_region() -> result<ty::region, str> {
|
|
||||||
alt *self {
|
|
||||||
ast::rp_self { result::ok(ty::re_bound(ty::br_self)) }
|
|
||||||
ast::rp_none {
|
|
||||||
result::err("to use region types here, the containing type \
|
|
||||||
must be declared with a region bound")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn named_region(id: str) -> result<ty::region, str> {
|
|
||||||
empty_rscope.named_region(id).chain_err { |_e|
|
|
||||||
if id == "self" { self.anon_region() }
|
|
||||||
else {
|
|
||||||
result::err("named regions other than `self` are not \
|
|
||||||
allowed as part of a type declaration")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum anon_rscope = {anon: ty::region, base: region_scope};
|
|
||||||
fn in_anon_rscope<RS: region_scope copy>(self: RS, r: ty::region)
|
|
||||||
-> @anon_rscope {
|
|
||||||
@anon_rscope({anon: r, base: self as region_scope})
|
|
||||||
}
|
|
||||||
impl of region_scope for @anon_rscope {
|
|
||||||
fn anon_region() -> result<ty::region, str> {
|
|
||||||
result::ok(self.anon)
|
|
||||||
}
|
|
||||||
fn named_region(id: str) -> result<ty::region, str> {
|
|
||||||
self.base.named_region(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum binding_rscope = {base: region_scope};
|
|
||||||
fn in_binding_rscope<RS: region_scope copy>(self: RS) -> @binding_rscope {
|
|
||||||
let base = self as region_scope;
|
|
||||||
@binding_rscope({base: base})
|
|
||||||
}
|
|
||||||
impl of region_scope for @binding_rscope {
|
|
||||||
fn anon_region() -> result<ty::region, str> {
|
|
||||||
result::ok(ty::re_bound(ty::br_anon))
|
|
||||||
}
|
|
||||||
fn named_region(id: str) -> result<ty::region, str> {
|
|
||||||
self.base.named_region(id).chain_err {|_e|
|
|
||||||
result::ok(ty::re_bound(ty::br_named(id)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_region_reporting_err(tcx: ty::ctxt,
|
fn get_region_reporting_err(tcx: ty::ctxt,
|
||||||
span: span,
|
span: span,
|
||||||
res: result<ty::region, str>) -> ty::region {
|
res: result<ty::region, str>) -> ty::region {
|
||||||
|
|
|
@ -66,13 +66,13 @@ type parameter).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import astconv::{ast_conv, region_scope, empty_rscope, ast_ty_to_ty,
|
import astconv::{ast_conv, ast_ty_to_ty};
|
||||||
in_anon_rscope};
|
|
||||||
import collect::{methods}; // ccx.to_ty()
|
import collect::{methods}; // ccx.to_ty()
|
||||||
import method::{methods}; // methods for method::lookup
|
import method::{methods}; // methods for method::lookup
|
||||||
import regionmanip::{universally_quantify_regions_before_call,
|
import regionmanip::{universally_quantify_regions_before_call,
|
||||||
region_of, replace_bound_regions,
|
region_of, replace_bound_regions,
|
||||||
collect_bound_regions_in_tys};
|
collect_bound_regions_in_tys};
|
||||||
|
import rscope::*;
|
||||||
|
|
||||||
type fn_ctxt =
|
type fn_ctxt =
|
||||||
// var_bindings, locals and next_var_id are shared
|
// var_bindings, locals and next_var_id are shared
|
||||||
|
@ -335,7 +335,7 @@ fn class_types(ccx: @crate_ctxt, members: [@ast::class_member],
|
||||||
rp: ast::region_param) -> class_map {
|
rp: ast::region_param) -> class_map {
|
||||||
|
|
||||||
let rslt = int_hash::<ty::t>();
|
let rslt = int_hash::<ty::t>();
|
||||||
let rs = astconv::type_rscope(rp);
|
let rs = rscope::type_rscope(rp);
|
||||||
for members.each { |m|
|
for members.each { |m|
|
||||||
alt m.node {
|
alt m.node {
|
||||||
ast::instance_var(_,t,_,id,_) {
|
ast::instance_var(_,t,_,id,_) {
|
||||||
|
@ -375,7 +375,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
|
||||||
check_bare_fn(ccx, decl, body, dtor_id, none);
|
check_bare_fn(ccx, decl, body, dtor_id, none);
|
||||||
}
|
}
|
||||||
ast::item_impl(tps, rp, _, ty, ms) {
|
ast::item_impl(tps, rp, _, ty, ms) {
|
||||||
let self_ty = ccx.to_ty(astconv::type_rscope(rp), ty);
|
let self_ty = ccx.to_ty(rscope::type_rscope(rp), ty);
|
||||||
for ms.each {|m| check_method(ccx, m, self_ty);}
|
for ms.each {|m| check_method(ccx, m, self_ty);}
|
||||||
}
|
}
|
||||||
ast::item_class(tps, ifaces, members, ctor, m_dtor, rp) {
|
ast::item_class(tps, ifaces, members, ctor, m_dtor, rp) {
|
||||||
|
@ -652,7 +652,7 @@ fn impl_self_ty(fcx: @fn_ctxt, did: ast::def_id) -> ty_param_substs_and_ty {
|
||||||
_}, _)) {
|
_}, _)) {
|
||||||
{n_tps: ts.len(),
|
{n_tps: ts.len(),
|
||||||
rp: rp,
|
rp: rp,
|
||||||
raw_ty: fcx.ccx.to_ty(astconv::type_rscope(rp), st)}
|
raw_ty: fcx.ccx.to_ty(rscope::type_rscope(rp), st)}
|
||||||
}
|
}
|
||||||
some(ast_map::node_item(@{node: ast::item_class(ts,
|
some(ast_map::node_item(@{node: ast::item_class(ts,
|
||||||
_,_,_,_,rp), id: class_id, _},_)) {
|
_,_,_,_,rp), id: class_id, _},_)) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ are represented as `ty_param()` instances.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import astconv::{type_rscope, empty_rscope, in_binding_rscope, ast_conv,
|
import astconv::{ast_conv, ty_of_fn_decl, ty_of_arg, ast_ty_to_ty};
|
||||||
ty_of_fn_decl, ty_of_arg, region_scope, ast_ty_to_ty};
|
import rscope::*;
|
||||||
|
|
||||||
fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
|
fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
|
||||||
|
|
||||||
|
|
69
src/rustc/middle/typeck/rscope.rs
Normal file
69
src/rustc/middle/typeck/rscope.rs
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
import result::result;
|
||||||
|
|
||||||
|
iface region_scope {
|
||||||
|
fn anon_region() -> result<ty::region, str>;
|
||||||
|
fn named_region(id: str) -> result<ty::region, str>;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum empty_rscope { empty_rscope }
|
||||||
|
impl of region_scope for empty_rscope {
|
||||||
|
fn anon_region() -> result<ty::region, str> {
|
||||||
|
result::err("region types are not allowed here")
|
||||||
|
}
|
||||||
|
fn named_region(id: str) -> result<ty::region, str> {
|
||||||
|
if id == "static" { result::ok(ty::re_static) }
|
||||||
|
else { result::err("only the static region is allowed here") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum type_rscope = ast::region_param;
|
||||||
|
impl of region_scope for type_rscope {
|
||||||
|
fn anon_region() -> result<ty::region, str> {
|
||||||
|
alt *self {
|
||||||
|
ast::rp_self { result::ok(ty::re_bound(ty::br_self)) }
|
||||||
|
ast::rp_none {
|
||||||
|
result::err("to use region types here, the containing type \
|
||||||
|
must be declared with a region bound")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn named_region(id: str) -> result<ty::region, str> {
|
||||||
|
empty_rscope.named_region(id).chain_err { |_e|
|
||||||
|
if id == "self" { self.anon_region() }
|
||||||
|
else {
|
||||||
|
result::err("named regions other than `self` are not \
|
||||||
|
allowed as part of a type declaration")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum anon_rscope = {anon: ty::region, base: region_scope};
|
||||||
|
fn in_anon_rscope<RS: region_scope copy>(self: RS, r: ty::region)
|
||||||
|
-> @anon_rscope {
|
||||||
|
@anon_rscope({anon: r, base: self as region_scope})
|
||||||
|
}
|
||||||
|
impl of region_scope for @anon_rscope {
|
||||||
|
fn anon_region() -> result<ty::region, str> {
|
||||||
|
result::ok(self.anon)
|
||||||
|
}
|
||||||
|
fn named_region(id: str) -> result<ty::region, str> {
|
||||||
|
self.base.named_region(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum binding_rscope = {base: region_scope};
|
||||||
|
fn in_binding_rscope<RS: region_scope copy>(self: RS) -> @binding_rscope {
|
||||||
|
let base = self as region_scope;
|
||||||
|
@binding_rscope({base: base})
|
||||||
|
}
|
||||||
|
impl of region_scope for @binding_rscope {
|
||||||
|
fn anon_region() -> result<ty::region, str> {
|
||||||
|
result::ok(ty::re_bound(ty::br_anon))
|
||||||
|
}
|
||||||
|
fn named_region(id: str) -> result<ty::region, str> {
|
||||||
|
self.base.named_region(id).chain_err {|_e|
|
||||||
|
result::ok(ty::re_bound(ty::br_named(id)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -61,6 +61,7 @@ mod middle {
|
||||||
mod demand;
|
mod demand;
|
||||||
mod method;
|
mod method;
|
||||||
}
|
}
|
||||||
|
mod rscope;
|
||||||
mod astconv;
|
mod astconv;
|
||||||
mod infer;
|
mod infer;
|
||||||
mod collect;
|
mod collect;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue