Skip to content

Commit b3c0a71

Browse files
author
alexrp
committed
---
yaml --- r: 23086 b: refs/heads/master c: d67314d h: refs/heads/master v: v3
1 parent e2f82d6 commit b3c0a71

File tree

6 files changed

+33
-171
lines changed

6 files changed

+33
-171
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: edf1d0c245e7ba4eed4be89101073d8515a0f129
2+
refs/heads/master: d67314d5fcfeb75da8281794f8e6af3583705c2f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/rust.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,13 +1927,15 @@ x <- copy y;
19271927

19281928
The former is just more terse and familiar.
19291929

1930-
#### Operator-assignment expressions
1930+
#### Compound assignment expressions
19311931

19321932
The `+`, `-`, `*`, `/`, `%`, `&`, `|`, `^`, `<<`, `>>`, and `>>>`
19331933
operators may be composed with the `=` operator. The expression `lval
19341934
OP= val` is equivalent to `lval = lval OP val`. For example, `x = x +
19351935
1` may be written as `x += 1`.
19361936

1937+
Any such expression always has the [`nil`](#primitive-types) type.
1938+
19371939
#### Operator precedence
19381940

19391941
The precedence of Rust binary operators is ordered as follows, going

trunk/src/rustc/middle/typeck.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export vtable_res;
7979
export vtable_origin;
8080
export method_static, method_param, method_trait;
8181
export vtable_static, vtable_param, vtable_trait;
82-
export provided_methods_map;
8382

8483
#[auto_serialize]
8584
enum method_origin {
@@ -152,23 +151,15 @@ enum vtable_origin {
152151

153152
type vtable_map = hashmap<ast::node_id, vtable_res>;
154153

155-
// Stores information about provided methods, aka "default methods" in traits.
156-
// Maps from a trait's def_id to a MethodInfo about
157-
// that method in that trait.
158-
type provided_methods_map = hashmap<ast::node_id,
159-
~[@resolve3::MethodInfo]>;
160-
161154
type ty_param_substs_and_ty = {substs: ty::substs, ty: ty::t};
162155

163-
type crate_ctxt_ = {impl_map: resolve3::ImplMap,
156+
type ty_table = hashmap<ast::def_id, ty::t>;
164157

165-
// A mapping from method call sites to traits that have
166-
// that method.
158+
type crate_ctxt_ = {impl_map: resolve3::ImplMap,
167159
trait_map: resolve3::TraitMap,
168160
method_map: method_map,
169161
vtable_map: vtable_map,
170162
coherence_info: @coherence::CoherenceInfo,
171-
provided_methods_map: provided_methods_map,
172163
tcx: ty::ctxt};
173164

174165
enum crate_ctxt {
@@ -311,7 +302,6 @@ fn check_crate(tcx: ty::ctxt,
311302
method_map: std::map::int_hash(),
312303
vtable_map: std::map::int_hash(),
313304
coherence_info: @coherence::CoherenceInfo(),
314-
provided_methods_map: std::map::int_hash(),
315305
tcx: tcx});
316306
collect::collect_item_types(ccx, crate);
317307
coherence::check_coherence(ccx, crate);

trunk/src/rustc/middle/typeck/check/method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ class lookup {
366366
}
367367

368368
fn add_candidates_from_scope(use_assignability: bool) {
369-
370369
// If we're using coherence and this is one of the method invocation
371370
// forms it supports, don't use this method; it'll result in lots of
372371
// multiple-methods-in-scope errors.
372+
373373
if self.fcx.ccx.trait_map.contains_key(self.expr.id) {
374374
return;
375375
}

trunk/src/rustc/middle/typeck/coherence.rs

Lines changed: 25 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import metadata::csearch::{each_path, get_impl_traits, get_impls_for_mod};
88
import metadata::cstore::{cstore, iter_crate_data};
99
import metadata::decoder::{dl_def, dl_field, dl_impl};
10-
import middle::resolve3::{Impl, MethodInfo};
10+
import middle::resolve3::Impl;
1111
import middle::ty::{get, lookup_item_type, subst, t, ty_box};
1212
import middle::ty::{ty_uniq, ty_ptr, ty_rptr, ty_enum};
1313
import middle::ty::{ty_class, ty_nil, ty_bot, ty_bool, ty_int, ty_uint};
@@ -108,16 +108,6 @@ fn get_base_type_def_id(inference_context: infer_ctxt,
108108
}
109109
}
110110

111-
112-
fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
113-
@{
114-
did: local_def(ast_method.id),
115-
n_tps: ast_method.tps.len(),
116-
ident: ast_method.ident,
117-
self_type: ast_method.self_ty.node
118-
}
119-
}
120-
121111
class CoherenceInfo {
122112
// Contains implementations of methods that are inherent to a type.
123113
// Methods in these implementations don't need to be exported.
@@ -161,70 +151,10 @@ class CoherenceChecker {
161151
self.privileged_types = new_def_hash();
162152
}
163153

164-
// Create a mapping containing a MethodInfo for every provided
165-
// method in every trait.
166-
fn build_provided_methods_map(crate: @crate) {
167-
168-
let pmm = self.crate_context.provided_methods_map;
169-
170-
visit_crate(*crate, (), mk_simple_visitor(@{
171-
visit_item: |item| {
172-
match item.node {
173-
item_trait(_, _, trait_methods) => {
174-
for trait_methods.each |trait_method| {
175-
debug!{"(building provided methods map) checking \
176-
trait `%s` with id %d", *item.ident, item.id};
177-
178-
match trait_method {
179-
required(_) => { /* fall through */}
180-
provided(m) => {
181-
// For every provided method in the
182-
// trait, store a MethodInfo.
183-
let mi = method_to_MethodInfo(m);
184-
185-
match pmm.find(item.id) {
186-
some(mis) => {
187-
// If the trait already has an
188-
// entry in the
189-
// provided_methods_map, we just
190-
// need to add this method to
191-
// that entry.
192-
debug!{"(building provided \
193-
methods map) adding \
194-
method `%s` to entry for \
195-
existing trait",
196-
*mi.ident};
197-
let mut method_infos = mis;
198-
push(method_infos, mi);
199-
pmm.insert(item.id, method_infos);
200-
}
201-
none => {
202-
// If the trait doesn't have an
203-
// entry yet, create one.
204-
debug!{"(building provided \
205-
methods map) creating new \
206-
entry for method `%s`",
207-
*mi.ident};
208-
pmm.insert(item.id, ~[mi]);
209-
}
210-
}
211-
}
212-
}
213-
}
214-
}
215-
_ => {
216-
// Nothing to do.
217-
}
218-
};
219-
}
220-
with *default_simple_visitor()
221-
}));
222-
}
223-
224154
fn check_coherence(crate: @crate) {
225-
226155
// Check implementations. This populates the tables containing the
227156
// inherent methods and extension methods.
157+
228158
visit_crate(*crate, (), mk_simple_visitor(@{
229159
visit_item: |item| {
230160
debug!{"(checking coherence) item '%s'", *item.ident};
@@ -257,6 +187,7 @@ class CoherenceChecker {
257187
// Bring in external crates. It's fine for this to happen after the
258188
// coherence checks, because we ensure by construction that no errors
259189
// can happen at link time.
190+
260191
self.add_external_crates();
261192
}
262193

@@ -272,8 +203,8 @@ class CoherenceChecker {
272203
*item.ident};
273204

274205
match get_base_type_def_id(self.inference_context,
275-
item.span,
276-
self_type.ty) {
206+
item.span,
207+
self_type.ty) {
277208
none => {
278209
let session = self.crate_context.tcx.sess;
279210
session.span_err(item.span,
@@ -420,6 +351,7 @@ class CoherenceChecker {
420351
}
421352

422353
// Privileged scope checking
354+
423355
fn check_privileged_scopes(crate: @crate) {
424356
// Gather up all privileged types.
425357
let privileged_types =
@@ -498,13 +430,15 @@ class CoherenceChecker {
498430
// trait was defined in this
499431
// crate.
500432

501-
let trait_def_id =
502-
self.trait_ref_to_trait_def_id(
503-
trait_ref);
504-
505-
if trait_def_id.crate != local_crate {
506-
let session =
507-
self.crate_context.tcx.sess;
433+
let def_map = self.crate_context.tcx
434+
.def_map;
435+
let trait_def = def_map.get
436+
(trait_ref.ref_id);
437+
let trait_id =
438+
def_id_of_def(trait_def);
439+
if trait_id.crate != local_crate {
440+
let session = self.crate_context
441+
.tcx.sess;
508442
session.span_err(item.span,
509443
~"cannot \
510444
provide an \
@@ -532,13 +466,6 @@ class CoherenceChecker {
532466
}));
533467
}
534468
535-
fn trait_ref_to_trait_def_id(trait_ref: @trait_ref) -> def_id {
536-
let def_map = self.crate_context.tcx.def_map;
537-
let trait_def = def_map.get(trait_ref.ref_id);
538-
let trait_id = def_id_of_def(trait_def);
539-
return trait_id;
540-
}
541-
542469
fn gather_privileged_types(items: ~[@item]) -> @dvec<def_id> {
543470
let results = @dvec();
544471
for items.each |item| {
@@ -560,70 +487,16 @@ class CoherenceChecker {
560487
561488
// Converts an implementation in the AST to an Impl structure.
562489
fn create_impl_from_item(item: @item) -> @Impl {
563-
564-
fn add_provided_methods(inherent_methods: ~[@MethodInfo],
565-
all_provided_methods: ~[@MethodInfo])
566-
-> ~[@MethodInfo] {
567-
568-
let mut methods = inherent_methods;
569-
570-
// If there's no inherent method with the same name as a
571-
// provided method, add that provided method to `methods`.
572-
for all_provided_methods.each |provided_method| {
573-
let mut method_inherent_to_impl = false;
574-
for inherent_methods.each |inherent_method| {
575-
if provided_method.ident == inherent_method.ident {
576-
method_inherent_to_impl = true;
577-
}
578-
}
579-
580-
if !method_inherent_to_impl {
581-
debug!{"(creating impl) adding provided method `%s` to \
582-
impl", *provided_method.ident};
583-
push(methods, provided_method);
584-
}
585-
}
586-
587-
return methods;
588-
}
589-
590490
match item.node {
591-
item_impl(ty_params, trait_refs, _, ast_methods) => {
491+
item_impl(ty_params, _, _, ast_methods) => {
592492
let mut methods = ~[];
593-
594493
for ast_methods.each |ast_method| {
595-
push(methods,
596-
method_to_MethodInfo(ast_method));
597-
}
598-
599-
// For each trait that the impl implements, see what
600-
// methods are provided. For each of those methods,
601-
// if a method of that name is not inherent to the
602-
// impl, use the provided definition in the trait.
603-
for trait_refs.each |trait_ref| {
604-
605-
let trait_did = self.trait_ref_to_trait_def_id(trait_ref);
606-
607-
match self.crate_context.provided_methods_map
608-
.find(trait_did.node) {
609-
none => {
610-
debug!{"(creating impl) trait with node_id `%d` \
611-
has no provided methods", trait_did.node};
612-
/* fall through */
613-
}
614-
some(all_provided)
615-
=> {
616-
debug!{"(creating impl) trait with node_id `%d` \
617-
has provided methods", trait_did.node};
618-
// Selectively add only those provided
619-
// methods that aren't inherent to the
620-
// trait.
621-
622-
// XXX: could probably be doing this with filter.
623-
methods = add_provided_methods(methods,
624-
all_provided);
625-
}
626-
}
494+
push(methods, @{
495+
did: local_def(ast_method.id),
496+
n_tps: ast_method.tps.len(),
497+
ident: ast_method.ident,
498+
self_type: ast_method.self_ty.node
499+
});
627500
}
628501
629502
return @{
@@ -715,8 +588,8 @@ class CoherenceChecker {
715588

716589
if associated_traits.len() == 0 {
717590
match get_base_type_def_id(self.inference_context,
718-
dummy_sp(),
719-
self_type.ty) {
591+
dummy_sp(),
592+
self_type.ty) {
720593
none => {
721594
let session = self.crate_context.tcx.sess;
722595
session.bug(fmt!{"no base type for external impl \
@@ -796,8 +669,6 @@ class CoherenceChecker {
796669
}
797670

798671
fn check_coherence(crate_context: @crate_ctxt, crate: @crate) {
799-
let coherence_checker = @CoherenceChecker(crate_context);
800-
(*coherence_checker).build_provided_methods_map(crate);
801-
(*coherence_checker).check_coherence(crate);
672+
CoherenceChecker(crate_context).check_coherence(crate);
802673
}
803674

trunk/src/rustc/middle/typeck/collect.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) {
197197

198198
let tcx = ccx.tcx;
199199
let rp = tcx.region_paramd_items.contains_key(id);
200-
match tcx.items.get(id) {
200+
match check tcx.items.get(id) {
201201
ast_map::node_item(@{node: ast::item_trait(params, _, ms), _}, _) => {
202202
store_methods::<ast::trait_method>(ccx, id, ms, |m| {
203203
let trait_bounds = ty_param_bounds(ccx, params);
@@ -218,7 +218,6 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) {
218218
ty_of_method(ccx, m, rp)
219219
});
220220
}
221-
_ => { /* Ignore things that aren't traits or classes */ }
222221
}
223222
}
224223

0 commit comments

Comments
 (0)