From cdd6f38220ae4b6d6b84524fa4b8f684898bad55 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 21 Feb 2013 11:08:50 -0800 Subject: [PATCH 1/4] librustc: De-mut resolve. rs=demuting --- src/librustc/middle/resolve.rs | 396 +++++++++++++++++++-------------- 1 file changed, 223 insertions(+), 173 deletions(-) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 72ef23b3fd712..9c5e4b9f0e086 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -150,7 +150,7 @@ pub enum NamespaceResult { UnboundResult, /// Means that resolve has determined that the name is bound in the Module /// argument, and specified by the NameBindings argument. - BoundResult(@Module, @mut NameBindings) + BoundResult(@mut Module, @mut NameBindings) } pub impl NamespaceResult { @@ -196,7 +196,7 @@ pub enum ImportDirectiveSubclass { /// The context that we thread through while building the reduced graph. pub enum ReducedGraphParent { - ModuleReducedGraphParent(@Module) + ModuleReducedGraphParent(@mut Module) } pub enum ResolveResult { @@ -293,7 +293,7 @@ pub enum SearchThroughModulesFlag { pub enum ModulePrefixResult { NoPrefixFound, - PrefixFound(@Module, uint) + PrefixFound(@mut Module, uint) } #[deriving_eq] @@ -368,11 +368,13 @@ pub fn ImportDirective(privacy: Privacy, /// The item that an import resolves to. pub struct Target { - target_module: @Module, + target_module: @mut Module, bindings: @mut NameBindings, } -pub fn Target(target_module: @Module, bindings: @mut NameBindings) -> Target { +pub fn Target(target_module: @mut Module, + bindings: @mut NameBindings) + -> Target { Target { target_module: target_module, bindings: bindings @@ -435,8 +437,8 @@ pub fn ImportState() -> ImportState { /// The link from a module up to its nearest parent node. pub enum ParentLink { NoParentLink, - ModuleParentLink(@Module, ident), - BlockParentLink(@Module, node_id) + ModuleParentLink(@mut Module, ident), + BlockParentLink(@mut Module, node_id) } /// The type of module this is. @@ -450,11 +452,11 @@ pub enum ModuleKind { /// One node in the tree of modules. pub struct Module { parent_link: ParentLink, - mut def_id: Option, + def_id: Option, kind: ModuleKind, - children: HashMap, - imports: DVec<@ImportDirective>, + children: @HashMap, + imports: @DVec<@ImportDirective>, // The anonymous children of this node. Anonymous children are pseudo- // modules that are implicitly created around items contained within @@ -471,16 +473,16 @@ pub struct Module { // There will be an anonymous module created around `g` with the ID of the // entry block for `f`. - anonymous_children: HashMap, + anonymous_children: @HashMap, // The status of resolving each import in this module. - import_resolutions: HashMap, + import_resolutions: @HashMap, // The number of unresolved globs that this module exports. - mut glob_count: uint, + glob_count: uint, // The index of the import we're resolving. - mut resolved_import_count: uint, + resolved_import_count: uint, } pub fn Module(parent_link: ParentLink, @@ -491,10 +493,10 @@ pub fn Module(parent_link: ParentLink, parent_link: parent_link, def_id: def_id, kind: kind, - children: HashMap(), - imports: DVec(), - anonymous_children: HashMap(), - import_resolutions: HashMap(), + children: @HashMap(), + imports: @DVec(), + anonymous_children: @HashMap(), + import_resolutions: @HashMap(), glob_count: 0, resolved_import_count: 0 } @@ -519,7 +521,7 @@ pub fn unused_import_lint_level(session: Session) -> level { // Records a possibly-private type definition. pub struct TypeNsDef { privacy: Privacy, - module_def: Option<@Module>, + module_def: Option<@mut Module>, type_def: Option } @@ -550,7 +552,7 @@ pub impl NameBindings { kind: ModuleKind, sp: span) { // Merges the module with the existing type def or creates a new one. - let module_ = @Module(parent_link, def_id, kind); + let module_ = @mut Module(parent_link, def_id, kind); match self.type_def { None => { self.type_def = Some(TypeNsDef { @@ -599,7 +601,7 @@ pub impl NameBindings { } /// Returns the module node if applicable. - fn get_module_if_available() -> Option<@Module> { + fn get_module_if_available() -> Option<@mut Module> { match self.type_def { Some(ref type_def) => (*type_def).module_def, None => None @@ -610,7 +612,7 @@ pub impl NameBindings { * Returns the module node. Fails if this node does not have a module * definition. */ - fn get_module(@mut self) -> @Module { + fn get_module(@mut self) -> @mut Module { match self.get_module_if_available() { None => { fail!(~"get_module called on a node with no module \ @@ -759,7 +761,7 @@ pub fn Resolver(session: Session, let current_module = graph_root.get_module(); let self = Resolver { - session: session, + session: @session, lang_items: copy lang_items, crate: crate, @@ -770,8 +772,8 @@ pub fn Resolver(session: Session, unused_import_lint_level: unused_import_lint_level(session), - trait_info: HashMap(), - structs: HashMap(), + trait_info: @HashMap(), + structs: @HashMap(), unresolved_imports: 0, @@ -794,8 +796,8 @@ pub fn Resolver(session: Session, attr_main_fn: None, main_fns: ~[], - def_map: HashMap(), - export_map2: HashMap(), + def_map: @HashMap(), + export_map2: @HashMap(), trait_map: @HashMap(), intr: session.intr() @@ -806,7 +808,7 @@ pub fn Resolver(session: Session, /// The main resolver class. pub struct Resolver { - session: Session, + session: @Session, lang_items: LanguageItems, crate: @crate, @@ -816,14 +818,14 @@ pub struct Resolver { unused_import_lint_level: level, - trait_info: HashMap>, - structs: HashMap, + trait_info: @HashMap>, + structs: @HashMap, // The number of imports that are currently unresolved. - mut unresolved_imports: uint, + unresolved_imports: uint, // The module that represents the current item scope. - mut current_module: @Module, + current_module: @mut Module, // The current set of local scopes, for values. // FIXME #4948: Reuse ribs to avoid allocation. @@ -837,10 +839,10 @@ pub struct Resolver { // Whether the current context is an X-ray context. An X-ray context is // allowed to access private names of any module. - mut xray_context: XrayFlag, + xray_context: XrayFlag, // The trait that the current context can refer to. - mut current_trait_refs: Option<@DVec>, + current_trait_refs: Option<@DVec>, // The ident for the keyword "self". self_ident: ident, @@ -854,19 +856,19 @@ pub struct Resolver { namespaces: ~[Namespace], // The function that has attribute named 'main' - mut attr_main_fn: Option<(node_id, span)>, + attr_main_fn: Option<(node_id, span)>, // The functions named 'main' - mut main_fns: ~[Option<(node_id, span)>], + main_fns: ~[Option<(node_id, span)>], - def_map: DefMap, - export_map2: ExportMap2, + def_map: @DefMap, + export_map2: @ExportMap2, trait_map: TraitMap, } pub impl Resolver { /// The main name resolution procedure. - fn resolve(@self, this: @Resolver) { - self.build_reduced_graph(this); + fn resolve(@mut self) { + self.build_reduced_graph(); self.session.abort_if_errors(); self.resolve_imports(); @@ -890,25 +892,25 @@ pub impl Resolver { // /// Constructs the reduced graph for the entire crate. - fn build_reduced_graph(this: @Resolver) { + fn build_reduced_graph(@mut self) { let initial_parent = ModuleReducedGraphParent(self.graph_root.get_module()); visit_crate(*self.crate, initial_parent, mk_vt(@Visitor { visit_item: |item, context, visitor| - (*this).build_reduced_graph_for_item(item, context, visitor), + self.build_reduced_graph_for_item(item, context, visitor), visit_foreign_item: |foreign_item, context, visitor| - (*this).build_reduced_graph_for_foreign_item(foreign_item, + self.build_reduced_graph_for_foreign_item(foreign_item, context, visitor), visit_view_item: |view_item, context, visitor| - (*this).build_reduced_graph_for_view_item(view_item, + self.build_reduced_graph_for_view_item(view_item, context, visitor), visit_block: |block, context, visitor| - (*this).build_reduced_graph_for_block(block, + self.build_reduced_graph_for_block(block, context, visitor), @@ -917,8 +919,9 @@ pub impl Resolver { } /// Returns the current module tracked by the reduced graph parent. - fn get_module_from_parent(reduced_graph_parent: ReducedGraphParent) - -> @Module { + fn get_module_from_parent(@mut self, + reduced_graph_parent: ReducedGraphParent) + -> @mut Module { match reduced_graph_parent { ModuleReducedGraphParent(module_) => { return module_; @@ -936,7 +939,8 @@ pub impl Resolver { * If this node does not have a module definition and we are not inside * a block, fails. */ - fn add_child(name: ident, + fn add_child(@mut self, + name: ident, reduced_graph_parent: ReducedGraphParent, duplicate_checking_mode: DuplicateCheckingMode, // For printing errors @@ -1023,7 +1027,7 @@ pub impl Resolver { } } - fn block_needs_anonymous_module(block: blk) -> bool { + fn block_needs_anonymous_module(@mut self, block: blk) -> bool { // If the block has view items, we need an anonymous module. if block.node.view_items.len() > 0 { return true; @@ -1054,8 +1058,10 @@ pub impl Resolver { return false; } - fn get_parent_link(parent: ReducedGraphParent, - name: ident) -> ParentLink { + fn get_parent_link(@mut self, + parent: ReducedGraphParent, + name: ident) + -> ParentLink { match parent { ModuleReducedGraphParent(module_) => { return ModuleParentLink(module_, name); @@ -1064,7 +1070,8 @@ pub impl Resolver { } /// Constructs the reduced graph for one item. - fn build_reduced_graph_for_item(item: @item, + fn build_reduced_graph_for_item(@mut self, + item: @item, parent: ReducedGraphParent, &&visitor: vt) { let ident = item.ident; @@ -1339,12 +1346,12 @@ pub impl Resolver { // Constructs the reduced graph for one variant. Variants exist in the // type and/or value namespaces. - fn build_reduced_graph_for_variant(variant: variant, + fn build_reduced_graph_for_variant(@mut self, + variant: variant, item_id: def_id, +parent_privacy: Privacy, parent: ReducedGraphParent, &&visitor: vt) { - let ident = variant.node.name; let (child, _) = self.add_child(ident, parent, ForbidDuplicateValues, variant.span); @@ -1387,7 +1394,8 @@ pub impl Resolver { * Constructs the reduced graph for one 'view item'. View items consist * of imports and use directives. */ - fn build_reduced_graph_for_view_item(view_item: @view_item, + fn build_reduced_graph_for_view_item(@mut self, + view_item: @view_item, parent: ReducedGraphParent, &&_visitor: vt) { let privacy = visibility_to_privacy(view_item.vis); @@ -1495,11 +1503,11 @@ pub impl Resolver { } /// Constructs the reduced graph for one foreign item. - fn build_reduced_graph_for_foreign_item(foreign_item: @foreign_item, + fn build_reduced_graph_for_foreign_item(@mut self, + foreign_item: @foreign_item, parent: ReducedGraphParent, &&visitor: vt) { - let name = foreign_item.ident; let (name_bindings, new_parent) = self.add_child(name, parent, ForbidDuplicateValues, @@ -1525,10 +1533,10 @@ pub impl Resolver { } } - fn build_reduced_graph_for_block(block: blk, + fn build_reduced_graph_for_block(@mut self, + block: blk, parent: ReducedGraphParent, &&visitor: vt) { - let mut new_parent; if self.block_needs_anonymous_module(block) { let block_id = block.node.id; @@ -1538,9 +1546,10 @@ pub impl Resolver { block_id); let parent_module = self.get_module_from_parent(parent); - let new_module = @Module(BlockParentLink(parent_module, block_id), - None, - AnonymousModuleKind); + let new_module = @mut Module( + BlockParentLink(parent_module, block_id), + None, + AnonymousModuleKind); parent_module.anonymous_children.insert(block_id, new_module); new_parent = ModuleReducedGraphParent(new_module); } else { @@ -1550,8 +1559,9 @@ pub impl Resolver { visit_block(block, new_parent, visitor); } - fn handle_external_def(def: def, - modules: HashMap, + fn handle_external_def(@mut self, + def: def, + modules: HashMap, child_name_bindings: @mut NameBindings, final_ident: &str, ident: ident, @@ -1671,7 +1681,7 @@ pub impl Resolver { * Builds the reduced graph rooted at the 'use' directive for an external * crate. */ - fn build_reduced_graph_for_external_crate(root: @Module) { + fn build_reduced_graph_for_external_crate(@mut self, root: @mut Module) { let modules = HashMap(); // Create all the items reachable by paths. @@ -1842,8 +1852,9 @@ pub impl Resolver { } /// Creates and adds an import directive to the given module. - fn build_import_directive(privacy: Privacy, - module_: @Module, + fn build_import_directive(@mut self, + privacy: Privacy, + module_: @mut Module, module_path: @DVec, subclass: @ImportDirectiveSubclass, span: span, @@ -1908,7 +1919,7 @@ pub impl Resolver { * Resolves all imports for the crate. This method performs the fixed- * point iteration. */ - fn resolve_imports() { + fn resolve_imports(@mut self) { let mut i = 0; let mut prev_unresolved_imports = 0; loop { @@ -1938,7 +1949,7 @@ pub impl Resolver { * Attempts to resolve imports for the given module and all of its * submodules. */ - fn resolve_imports_for_module_subtree(module_: @Module) { + fn resolve_imports_for_module_subtree(@mut self, module_: @mut Module) { debug!("(resolving imports for module subtree) resolving %s", self.module_to_str(module_)); self.resolve_imports_for_module(module_); @@ -1960,7 +1971,7 @@ pub impl Resolver { } /// Attempts to resolve imports for the given module only. - fn resolve_imports_for_module(module_: @Module) { + fn resolve_imports_for_module(@mut self, module_: @mut Module) { if (*module_).all_imports_resolved() { debug!("(resolving imports for module) all imports resolved for \ %s", @@ -1994,23 +2005,26 @@ pub impl Resolver { } } - fn idents_to_str(idents: ~[ident]) -> ~str { + fn idents_to_str(@mut self, idents: ~[ident]) -> ~str { let ident_strs = do idents.map |ident| { /*bad*/ copy *self.session.str_of(*ident) }; str::connect(ident_strs, "::") } - fn import_directive_subclass_to_str(subclass: ImportDirectiveSubclass) - -> @~str { + fn import_directive_subclass_to_str(@mut self, + subclass: ImportDirectiveSubclass) + -> @~str { match subclass { SingleImport(_target, source, _ns) => self.session.str_of(source), GlobImport => @~"*" } } - fn import_path_to_str(idents: ~[ident], subclass: ImportDirectiveSubclass) - -> @~str { + fn import_path_to_str(@mut self, + idents: ~[ident], + subclass: ImportDirectiveSubclass) + -> @~str { if idents.is_empty() { self.import_directive_subclass_to_str(subclass) } else { @@ -2027,10 +2041,10 @@ pub impl Resolver { * currently-unresolved imports, or success if we know the name exists. * If successful, the resolved bindings are written into the module. */ - fn resolve_import_for_module(module_: @Module, + fn resolve_import_for_module(@mut self, + module_: @mut Module, import_directive: @ImportDirective) -> ResolveResult<()> { - let mut resolution_result; let module_path = import_directive.module_path; @@ -2122,12 +2136,12 @@ pub impl Resolver { return resolution_result; } - fn resolve_single_import(module_: @Module, - containing_module: @Module, + fn resolve_single_import(@mut self, + module_: @mut Module, + containing_module: @mut Module, target: ident, source: ident) -> ResolveResult<()> { - debug!("(resolving single import) resolving `%s` = `%s::%s` from \ `%s`", *self.session.str_of(target), @@ -2314,12 +2328,12 @@ pub impl Resolver { return Success(()); } - fn resolve_single_module_import(module_: @Module, - containing_module: @Module, + fn resolve_single_module_import(@mut self, + module_: @mut Module, + containing_module: @mut Module, target: ident, source: ident) -> ResolveResult<()> { - debug!("(resolving single module import) resolving `%s` = `%s::%s` \ from `%s`", *self.session.str_of(target), @@ -2443,9 +2457,10 @@ pub impl Resolver { * succeeds or bails out (as importing * from an empty module or a module * that exports nothing is valid). */ - fn resolve_glob_import(privacy: Privacy, - module_: @Module, - containing_module: @Module, + fn resolve_glob_import(@mut self, + privacy: Privacy, + module_: @mut Module, + containing_module: @mut Module, span: span) -> ResolveResult<()> { // This function works in a highly imperative manner; it eagerly adds @@ -2557,11 +2572,12 @@ pub impl Resolver { return Success(()); } - fn resolve_module_path_from_root(module_: @Module, + fn resolve_module_path_from_root(@mut self, + module_: @mut Module, module_path: @DVec, index: uint, span: span) - -> ResolveResult<@Module> { + -> ResolveResult<@mut Module> { let mut search_module = module_; let mut index = index; let module_path_len = (*module_path).len(); @@ -2629,12 +2645,12 @@ pub impl Resolver { * Attempts to resolve the module part of an import directive or path * rooted at the given module. */ - fn resolve_module_path_for_import(module_: @Module, + fn resolve_module_path_for_import(@mut self, + module_: @mut Module, module_path: @DVec, use_lexical_scope: UseLexicalScopeFlag, span: span) - -> ResolveResult<@Module> { - + -> ResolveResult<@mut Module> { let module_path_len = (*module_path).len(); assert module_path_len > 0; @@ -2708,13 +2724,13 @@ pub impl Resolver { span); } - fn resolve_item_in_lexical_scope(module_: @Module, + fn resolve_item_in_lexical_scope(@mut self, + module_: @mut Module, name: ident, namespace: Namespace, search_through_modules: SearchThroughModulesFlag) -> ResolveResult { - debug!("(resolving item in lexical scope) resolving `%s` in \ namespace %? in `%s`", *self.session.str_of(name), @@ -2822,8 +2838,10 @@ pub impl Resolver { } /** Resolves a module name in the current lexical scope. */ - fn resolve_module_in_lexical_scope(module_: @Module, name: ident) - -> ResolveResult<@Module> { + fn resolve_module_in_lexical_scope(@mut self, + module_: @mut Module, + name: ident) + -> ResolveResult<@mut Module> { // If this module is an anonymous module, resolve the item in the // lexical scope. Otherwise, resolve the item from the crate root. let resolve_result = self.resolve_item_in_lexical_scope( @@ -2867,7 +2885,8 @@ pub impl Resolver { /** * Returns the nearest normal module parent of the given module. */ - fn get_nearest_normal_module_parent(module_: @Module) -> Option<@Module> { + fn get_nearest_normal_module_parent(@mut self, module_: @mut Module) + -> Option<@mut Module> { let mut module_ = module_; loop { match module_.parent_link { @@ -2889,7 +2908,9 @@ pub impl Resolver { * Returns the nearest normal module parent of the given module, or the * module itself if it is a normal module. */ - fn get_nearest_normal_module_parent_or_self(module_: @Module) -> @Module { + fn get_nearest_normal_module_parent_or_self(@mut self, + module_: @mut Module) + -> @mut Module { match module_.kind { NormalModuleKind => return module_, ExternModuleKind | TraitModuleKind | AnonymousModuleKind => { @@ -2905,7 +2926,8 @@ pub impl Resolver { * Resolves a "module prefix". A module prefix is one of (a) `self::`; * (b) some chain of `super::`. */ - fn resolve_module_prefix(module_: @Module, + fn resolve_module_prefix(@mut self, + module_: @mut Module, module_path: @DVec) -> ResolveResult { let interner = self.session.parse_sess.interner; @@ -2951,7 +2973,8 @@ pub impl Resolver { * given namespace. If successful, returns the target corresponding to * the name. */ - fn resolve_name_in_module(module_: @Module, + fn resolve_name_in_module(@mut self, + module_: @mut Module, name: ident, namespace: Namespace, allow_globs: bool) @@ -3020,10 +3043,10 @@ pub impl Resolver { * This needs special handling, as, unlike all of the other imports, it * needs to look in the scope chain for modules and non-modules alike. */ - fn resolve_one_level_renaming_import(module_: @Module, + fn resolve_one_level_renaming_import(@mut self, + module_: @mut Module, import_directive: @ImportDirective) -> ResolveResult<()> { - let mut target_name; let mut source_name; let allowable_namespaces; @@ -3177,7 +3200,7 @@ pub impl Resolver { return Success(()); } - fn report_unresolved_imports(module_: @Module) { + fn report_unresolved_imports(@mut self, module_: @mut Module) { let index = module_.resolved_import_count; let import_count = module_.imports.len(); if index != import_count { @@ -3211,12 +3234,12 @@ pub impl Resolver { // Then this operation can simply be performed as part of item (or import) // processing. - fn record_exports() { + fn record_exports(@mut self) { let root_module = self.graph_root.get_module(); self.record_exports_for_module_subtree(root_module); } - fn record_exports_for_module_subtree(module_: @Module) { + fn record_exports_for_module_subtree(@mut self, module_: @mut Module) { // If this isn't a local crate, then bail out. We don't need to record // exports for nonlocal crates. @@ -3258,7 +3281,7 @@ pub impl Resolver { } } - fn record_exports_for_module(module_: @Module) { + fn record_exports_for_module(@mut self, module_: @mut Module) { let mut exports2 = ~[]; self.add_exports_for_module(&mut exports2, module_); @@ -3272,8 +3295,8 @@ pub impl Resolver { } } - - fn add_exports_of_namebindings(exports2: &mut ~[Export2], + fn add_exports_of_namebindings(@mut self, + exports2: &mut ~[Export2], ident: ident, namebindings: @mut NameBindings, ns: Namespace, @@ -3300,7 +3323,9 @@ pub impl Resolver { } } - fn add_exports_for_module(exports2: &mut ~[Export2], module_: @Module) { + fn add_exports_for_module(@mut self, + exports2: &mut ~[Export2], + module_: @mut Module) { for module_.children.each |ident, namebindings| { debug!("(computing exports) maybe export '%s'", *self.session.str_of(*ident)); @@ -3357,7 +3382,7 @@ pub impl Resolver { // generate a fake "implementation scope" containing all the // implementations thus found, for compatibility with old resolve pass. - fn with_scope(name: Option, f: fn()) { + fn with_scope(@mut self, name: Option, f: fn()) { let orig_module = self.current_module; // Move down in the graph. @@ -3397,10 +3422,13 @@ pub impl Resolver { // Wraps the given definition in the appropriate number of `def_upvar` // wrappers. - fn upvarify(ribs: @DVec<@Rib>, rib_index: uint, def_like: def_like, - span: span, allow_capturing_self: AllowCapturingSelfFlag) + fn upvarify(@mut self, + ribs: @DVec<@Rib>, + rib_index: uint, + def_like: def_like, + span: span, + allow_capturing_self: AllowCapturingSelfFlag) -> Option { - let mut def; let mut is_ty_param; @@ -3504,10 +3532,12 @@ pub impl Resolver { return Some(dl_def(def)); } - fn search_ribs(ribs: @DVec<@Rib>, name: ident, span: span, + fn search_ribs(@mut self, + ribs: @DVec<@Rib>, + name: ident, + span: span, allow_capturing_self: AllowCapturingSelfFlag) -> Option { - // FIXME #4950: This should not use a while loop. // FIXME #4950: Try caching? @@ -3529,7 +3559,7 @@ pub impl Resolver { return None; } - fn resolve_crate(@self) { + fn resolve_crate(@mut self) { debug!("(resolving crate) starting"); visit_crate(*self.crate, (), mk_vt(@Visitor { @@ -3549,7 +3579,7 @@ pub impl Resolver { })); } - fn resolve_item(item: @item, visitor: ResolveVisitor) { + fn resolve_item(@mut self, item: @item, visitor: ResolveVisitor) { debug!("(resolving item) resolving %s", *self.session.str_of(item.ident)); @@ -3777,7 +3807,9 @@ pub impl Resolver { self.xray_context = orig_xray_flag; } - fn with_type_parameter_rib(type_parameters: TypeParameters, f: fn()) { + fn with_type_parameter_rib(@mut self, + type_parameters: TypeParameters, + f: fn()) { match type_parameters { HasTypeParameters(type_parameters, node_id, initial_index, rib_kind) => { @@ -3818,19 +3850,20 @@ pub impl Resolver { } } - fn with_label_rib(f: fn()) { + fn with_label_rib(@mut self, f: fn()) { (*self.label_ribs).push(@Rib(NormalRibKind)); f(); (*self.label_ribs).pop(); } - fn with_constant_rib(f: fn()) { + + fn with_constant_rib(@mut self, f: fn()) { (*self.value_ribs).push(@Rib(ConstantItemRibKind)); f(); (*self.value_ribs).pop(); } - - fn resolve_function(rib_kind: RibKind, + fn resolve_function(@mut self, + rib_kind: RibKind, optional_declaration: Option<@fn_decl>, type_parameters: TypeParameters, block: blk, @@ -3906,7 +3939,8 @@ pub impl Resolver { (*self.value_ribs).pop(); } - fn resolve_type_parameters(type_parameters: ~[ty_param], + fn resolve_type_parameters(@mut self, + type_parameters: ~[ty_param], visitor: ResolveVisitor) { for type_parameters.each |type_parameter| { for type_parameter.bounds.each |&bound| { @@ -3918,11 +3952,12 @@ pub impl Resolver { } } - fn resolve_struct(id: node_id, - type_parameters: @~[ty_param], - fields: ~[@struct_field], - optional_destructor: Option, - visitor: ResolveVisitor) { + fn resolve_struct(@mut self, + id: node_id, + type_parameters: @~[ty_param], + fields: ~[@struct_field], + optional_destructor: Option, + visitor: ResolveVisitor) { // If applicable, create a rib for the type parameters. let borrowed_type_parameters: &~[ty_param] = &*type_parameters; do self.with_type_parameter_rib(HasTypeParameters @@ -3959,7 +3994,8 @@ pub impl Resolver { // Does this really need to take a RibKind or is it always going // to be NormalRibKind? - fn resolve_method(rib_kind: RibKind, + fn resolve_method(@mut self, + rib_kind: RibKind, method: @method, outer_type_parameter_count: uint, visitor: ResolveVisitor) { @@ -3984,7 +4020,8 @@ pub impl Resolver { visitor); } - fn resolve_implementation(id: node_id, + fn resolve_implementation(@mut self, + id: node_id, span: span, type_parameters: ~[ty_param], opt_trait_reference: Option<@trait_ref>, @@ -4060,15 +4097,18 @@ pub impl Resolver { } } - fn resolve_module(module_: _mod, span: span, _name: ident, id: node_id, + fn resolve_module(@mut self, + module_: _mod, + span: span, + _name: ident, + id: node_id, visitor: ResolveVisitor) { - // Write the implementations in scope into the module metadata. debug!("(resolving module) resolving module ID %d", id); visit_mod(module_, span, id, (), visitor); } - fn resolve_local(local: @local, visitor: ResolveVisitor) { + fn resolve_local(@mut self, local: @local, visitor: ResolveVisitor) { let mutability = if local.node.is_mutbl {Mutable} else {Immutable}; // Resolve the type. @@ -4089,9 +4129,9 @@ pub impl Resolver { None, visitor); } - fn binding_mode_map(pat: @pat) -> BindingMap { + fn binding_mode_map(@mut self, pat: @pat) -> BindingMap { let result = HashMap(); - do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| { + do pat_bindings(*self.def_map, pat) |binding_mode, _id, sp, path| { let ident = path_to_ident(path); result.insert(ident, binding_info {span: sp, @@ -4100,7 +4140,7 @@ pub impl Resolver { return result; } - fn check_consistent_bindings(arm: arm) { + fn check_consistent_bindings(@mut self, arm: arm) { if arm.pats.len() == 0 { return; } let map_0 = self.binding_mode_map(arm.pats[0]); for arm.pats.eachi() |i, p| { @@ -4139,7 +4179,7 @@ pub impl Resolver { } } - fn resolve_arm(arm: arm, visitor: ResolveVisitor) { + fn resolve_arm(@mut self, arm: arm, visitor: ResolveVisitor) { (*self.value_ribs).push(@Rib(NormalRibKind)); let bindings_list = HashMap(); @@ -4158,7 +4198,7 @@ pub impl Resolver { (*self.value_ribs).pop(); } - fn resolve_block(block: blk, visitor: ResolveVisitor) { + fn resolve_block(@mut self, block: blk, visitor: ResolveVisitor) { debug!("(resolving block) entering block"); (*self.value_ribs).push(@Rib(NormalRibKind)); @@ -4183,7 +4223,7 @@ pub impl Resolver { debug!("(resolving block) leaving block"); } - fn resolve_type(ty: @Ty, visitor: ResolveVisitor) { + fn resolve_type(@mut self, ty: @Ty, visitor: ResolveVisitor) { match ty.node { // Like path expressions, the interpretation of path types depends // on whether the path has multiple elements in it or not. @@ -4256,14 +4296,14 @@ pub impl Resolver { } } - fn resolve_pattern(pattern: @pat, + fn resolve_pattern(@mut self, + pattern: @pat, mode: PatternBindingMode, mutability: Mutability, // Maps idents to the node ID for the (outermost) // pattern that binds them bindings_list: Option>, visitor: ResolveVisitor) { - let pat_id = pattern.id; do walk_pat(pattern) |pattern| { match pattern.node { @@ -4463,7 +4503,7 @@ pub impl Resolver { } } - fn resolve_bare_identifier_pattern(name: ident) + fn resolve_bare_identifier_pattern(@mut self, name: ident) -> BareIdentifierPatternResolution { match self.resolve_item_in_lexical_scope(self.current_module, name, @@ -4505,7 +4545,8 @@ pub impl Resolver { * If `check_ribs` is true, checks the local definitions first; i.e. * doesn't skip straight to the containing module. */ - fn resolve_path(path: @path, + fn resolve_path(@mut self, + path: @path, namespace: Namespace, check_ribs: bool, visitor: ResolveVisitor) @@ -4533,12 +4574,12 @@ pub impl Resolver { path.span); } - fn resolve_identifier(identifier: ident, + fn resolve_identifier(@mut self, + identifier: ident, namespace: Namespace, check_ribs: bool, span: span) -> Option { - if check_ribs { match self.resolve_identifier_in_local_ribs(identifier, namespace, @@ -4557,12 +4598,12 @@ pub impl Resolver { } // FIXME #4952: Merge me with resolve_name_in_module? - fn resolve_definition_of_name_in_module(containing_module: @Module, + fn resolve_definition_of_name_in_module(@mut self, + containing_module: @mut Module, name: ident, namespace: Namespace, xray: XrayFlag) -> NameDefinition { - // First, search children. match containing_module.children.find(&name) { Some(child_name_bindings) => { @@ -4619,7 +4660,7 @@ pub impl Resolver { } } - fn intern_module_part_of_path(path: @path) -> @DVec { + fn intern_module_part_of_path(@mut self, path: @path) -> @DVec { let module_path_idents = @DVec(); for path.idents.eachi |index, ident| { if index == path.idents.len() - 1 { @@ -4632,11 +4673,11 @@ pub impl Resolver { return module_path_idents; } - fn resolve_module_relative_path(path: @path, + fn resolve_module_relative_path(@mut self, + path: @path, +xray: XrayFlag, namespace: Namespace) -> Option { - let module_path_idents = self.intern_module_part_of_path(path); let mut containing_module; @@ -4676,11 +4717,11 @@ pub impl Resolver { } } - fn resolve_crate_relative_path(path: @path, + fn resolve_crate_relative_path(@mut self, + path: @path, +xray: XrayFlag, namespace: Namespace) -> Option { - let module_path_idents = self.intern_module_part_of_path(path); let root_module = self.graph_root.get_module(); @@ -4723,7 +4764,8 @@ pub impl Resolver { } } - fn resolve_identifier_in_local_ribs(ident: ident, + fn resolve_identifier_in_local_ribs(@mut self, + ident: ident, namespace: Namespace, span: span) -> Option { @@ -4754,7 +4796,8 @@ pub impl Resolver { } } - fn resolve_item_by_identifier_in_lexical_scope(ident: ident, + fn resolve_item_by_identifier_in_lexical_scope(@mut self, + ident: ident, namespace: Namespace) -> Option { // Check the items. @@ -4786,7 +4829,7 @@ pub impl Resolver { } } - fn name_exists_in_scope_struct(name: &str) -> bool { + fn name_exists_in_scope_struct(@mut self, name: &str) -> bool { let mut i = self.type_ribs.len(); while i != 0 { i -= 1; @@ -4819,7 +4862,7 @@ pub impl Resolver { return false; } - fn resolve_expr(expr: @expr, visitor: ResolveVisitor) { + fn resolve_expr(@mut self, expr: @expr, visitor: ResolveVisitor) { // First, record candidate traits for this expression if it could // result in the invocation of a method call. @@ -4928,7 +4971,7 @@ pub impl Resolver { } } - fn record_candidate_traits_for_expr_if_necessary(expr: @expr) { + fn record_candidate_traits_for_expr_if_necessary(@mut self, expr: @expr) { match expr.node { expr_field(_, ident, _) => { let traits = self.search_for_traits_containing_method(ident); @@ -5005,7 +5048,9 @@ pub impl Resolver { } } - fn search_for_traits_containing_method(name: ident) -> @DVec { + fn search_for_traits_containing_method(@mut self, + name: ident) + -> @DVec { debug!("(searching for traits containing method) looking for '%s'", *self.session.str_of(name)); @@ -5095,10 +5140,11 @@ pub impl Resolver { return found_traits; } - fn add_trait_info_if_containing_method(found_traits: @DVec, + fn add_trait_info_if_containing_method(@mut self, + found_traits: @DVec, trait_def_id: def_id, - name: ident) -> bool { - + name: ident) + -> bool { debug!("(adding trait info if containing method) trying trait %d:%d \ for method '%s'", trait_def_id.crate, @@ -5121,18 +5167,21 @@ pub impl Resolver { } } - fn add_fixed_trait_for_expr(expr_id: node_id, +trait_id: def_id) { + fn add_fixed_trait_for_expr(@mut self, + expr_id: node_id, + +trait_id: def_id) { let traits = @DVec(); traits.push(trait_id); self.trait_map.insert(expr_id, traits); } - fn record_def(node_id: node_id, def: def) { + fn record_def(@mut self, node_id: node_id, def: def) { debug!("(recording def) recording %? for %?", def, node_id); self.def_map.insert(node_id, def); } - fn enforce_default_binding_mode(pat: @pat, + fn enforce_default_binding_mode(@mut self, + pat: @pat, pat_binding_mode: binding_mode, descr: &str) { match pat_binding_mode { @@ -5157,7 +5206,7 @@ pub impl Resolver { // // be sure that there is only one main function // - fn check_duplicate_main() { + fn check_duplicate_main(@mut self) { if self.attr_main_fn.is_none() { if self.main_fns.len() >= 1u { let mut i = 1u; @@ -5183,7 +5232,7 @@ pub impl Resolver { // resolve data structures. // - fn check_for_unused_imports_if_necessary() { + fn check_for_unused_imports_if_necessary(@mut self) { if self.unused_import_lint_level == allow { return; } @@ -5192,7 +5241,8 @@ pub impl Resolver { self.check_for_unused_imports_in_module_subtree(root_module); } - fn check_for_unused_imports_in_module_subtree(module_: @Module) { + fn check_for_unused_imports_in_module_subtree(@mut self, + module_: @mut Module) { // If this isn't a local crate, then bail out. We don't need to check // for unused imports in external crates. @@ -5231,7 +5281,7 @@ pub impl Resolver { } } - fn check_for_unused_imports_in_module(module_: @Module) { + fn check_for_unused_imports_in_module(@mut self, module_: @mut Module) { for module_.import_resolutions.each_value |&import_resolution| { // Ignore dummy spans for things like automatically injected // imports for the prelude, and also don't warn about the same @@ -5268,7 +5318,7 @@ pub impl Resolver { // /// A somewhat inefficient routine to obtain the name of a module. - fn module_to_str(module_: @Module) -> ~str { + fn module_to_str(@mut self, module_: @mut Module) -> ~str { let idents = DVec(); let mut current_module = module_; loop { @@ -5293,7 +5343,7 @@ pub impl Resolver { return self.idents_to_str(vec::reversed(idents.get())); } - fn dump_module(module_: @Module) { + fn dump_module(@mut self, module_: @mut Module) { debug!("Dump of module `%s`:", self.module_to_str(module_)); debug!("Children:"); @@ -5338,11 +5388,11 @@ pub fn resolve_crate(session: Session, lang_items: LanguageItems, crate: @crate) -> CrateMap { - let resolver = @Resolver(session, lang_items, crate); - resolver.resolve(resolver); + let resolver = @mut Resolver(session, lang_items, crate); + resolver.resolve(); CrateMap { - def_map: resolver.def_map, - exp_map2: resolver.export_map2, + def_map: *resolver.def_map, + exp_map2: *resolver.export_map2, trait_map: resolver.trait_map } } From 553c27c515876990f4e3362d3f6bcab984fcd8f9 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 21 Feb 2013 11:57:20 -0800 Subject: [PATCH 2/4] librustc: De-mut some of trans --- src/librustc/middle/trans/base.rs | 72 ++++++++++++++---------- src/librustc/middle/trans/common.rs | 48 ++++++++-------- src/librustc/middle/trans/controlflow.rs | 2 +- src/libsyntax/ext/base.rs | 16 +++--- src/libsyntax/ext/tt/transcribe.rs | 12 ++-- 5 files changed, 82 insertions(+), 68 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 4eed47ebafcc9..499cbda4118ac 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -866,8 +866,8 @@ pub fn need_invoke(bcx: block) -> bool { // Walk the scopes to look for cleanups let mut cur = bcx; loop { - match cur.kind { - block_scope(ref inf) => { + match *cur.kind { + block_scope(ref mut inf) => { for vec::each((*inf).cleanups) |cleanup| { match *cleanup { clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => { @@ -898,16 +898,21 @@ pub fn have_cached_lpad(bcx: block) -> bool { return res; } -pub fn in_lpad_scope_cx(bcx: block, f: fn(scope_info)) { +pub fn in_lpad_scope_cx(bcx: block, f: fn(&mut scope_info)) { let mut bcx = bcx; loop { - match bcx.kind { - block_scope(ref inf) => { - if (*inf).cleanups.len() > 0u || bcx.parent.is_none() { - f((*inf)); return; + { + // XXX: Borrow check bug workaround. + let kind: &mut block_kind = &mut *bcx.kind; + match *kind { + block_scope(ref mut inf) => { + if inf.cleanups.len() > 0u || bcx.parent.is_none() { + f(inf); + return; + } + } + _ => () } - } - _ => () } bcx = block_parent(bcx); } @@ -1198,9 +1203,9 @@ pub fn simple_block_scope() -> block_kind { block_scope(scope_info { loop_break: None, loop_label: None, - mut cleanups: ~[], - mut cleanup_paths: ~[], - mut landing_pad: None + cleanups: ~[], + cleanup_paths: ~[], + landing_pad: None }) } @@ -1226,9 +1231,9 @@ pub fn loop_scope_block(bcx: block, return new_block(bcx.fcx, Some(bcx), block_scope(scope_info { loop_break: Some(loop_break), loop_label: loop_label, - mut cleanups: ~[], - mut cleanup_paths: ~[], - mut landing_pad: None + cleanups: ~[], + cleanup_paths: ~[], + landing_pad: None }), bcx.is_lpad, n, opt_node_info); } @@ -1301,23 +1306,30 @@ pub fn cleanup_and_leave(bcx: block, @fmt!("cleanup_and_leave(%s)", cur.to_str())); } - match cur.kind { - block_scope(ref inf) if !inf.cleanups.is_empty() => { - for vec::find((*inf).cleanup_paths, - |cp| cp.target == leave).each |cp| { - Br(bcx, cp.dest); - return; + { + // XXX: Borrow check bug workaround. + let kind: &mut block_kind = &mut *cur.kind; + match *kind { + block_scope(ref mut inf) if !inf.cleanups.is_empty() => { + for vec::find((*inf).cleanup_paths, + |cp| cp.target == leave).each |cp| { + Br(bcx, cp.dest); + return; + } + let sub_cx = sub_block(bcx, ~"cleanup"); + Br(bcx, sub_cx.llbb); + inf.cleanup_paths.push(cleanup_path { + target: leave, + dest: sub_cx.llbb + }); + bcx = trans_block_cleanups_(sub_cx, + block_cleanups(cur), + is_lpad); + } + _ => () } - let sub_cx = sub_block(bcx, ~"cleanup"); - Br(bcx, sub_cx.llbb); - (*inf).cleanup_paths.push(cleanup_path { - target: leave, - dest: sub_cx.llbb - }); - bcx = trans_block_cleanups_(sub_cx, block_cleanups(cur), is_lpad); - } - _ => () } + match upto { Some(bb) => { if cur.llbb == bb { break; } } _ => () diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 9f39cc8575d01..a69e51c666c6f 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -355,7 +355,7 @@ pub struct cleanup_path { dest: BasicBlockRef } -pub fn scope_clean_changed(scope_info: scope_info) { +pub fn scope_clean_changed(scope_info: &mut scope_info) { if scope_info.cleanup_paths.len() > 0u { scope_info.cleanup_paths = ~[]; } scope_info.landing_pad = None; } @@ -498,9 +498,9 @@ pub fn revoke_clean(cx: block, val: ValueRef) { } pub fn block_cleanups(bcx: block) -> ~[cleanup] { - match bcx.kind { + match *bcx.kind { block_non_scope => ~[], - block_scope(ref inf) => /*bad*/copy inf.cleanups + block_scope(ref mut inf) => /*bad*/copy inf.cleanups } } @@ -524,12 +524,12 @@ pub struct scope_info { // A list of functions that must be run at when leaving this // block, cleaning up any variables that were introduced in the // block. - mut cleanups: ~[cleanup], + cleanups: ~[cleanup], // Existing cleanup paths that may be reused, indexed by destination and // cleared when the set of cleanups changes. - mut cleanup_paths: ~[cleanup_path], + cleanup_paths: ~[cleanup_path], // Unwinding landing pad. Also cleared when cleanups change. - mut landing_pad: Option, + landing_pad: Option, } pub trait get_node_info { @@ -574,11 +574,11 @@ pub struct block_ { // instructions into that block by way of this block context. // The block pointing to this one in the function's digraph. llbb: BasicBlockRef, - mut terminated: bool, - mut unreachable: bool, + terminated: bool, + unreachable: bool, parent: Option, // The 'kind' of basic block this is. - kind: block_kind, + kind: @mut block_kind, // Is this block part of a landing pad? is_lpad: bool, // info about the AST node this block originated from, if any @@ -597,21 +597,19 @@ pub fn block_(llbb: BasicBlockRef, parent: Option, -kind: block_kind, terminated: false, unreachable: false, parent: parent, - kind: kind, + kind: @mut kind, is_lpad: is_lpad, node_info: node_info, fcx: fcx } } -/* This must be enum and not type, or trans goes into an infinite loop (#2572) - */ -pub enum block = @block_; +pub type block = @mut block_; pub fn mk_block(llbb: BasicBlockRef, parent: Option, -kind: block_kind, is_lpad: bool, node_info: Option, fcx: fn_ctxt) -> block { - block(@block_(llbb, parent, kind, is_lpad, node_info, fcx)) + @mut block_(llbb, parent, kind, is_lpad, node_info, fcx) } // First two args are retptr, env @@ -660,17 +658,21 @@ pub fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef { } } -pub fn in_scope_cx(cx: block, f: fn(scope_info)) { +pub fn in_scope_cx(cx: block, f: &fn(&mut scope_info)) { let mut cur = cx; loop { - match cur.kind { - block_scope(ref inf) => { - debug!("in_scope_cx: selected cur=%s (cx=%s)", - cur.to_str(), cx.to_str()); - f((*inf)); - return; - } - _ => () + { + // XXX: Borrow check bug workaround. + let kind: &mut block_kind = &mut *cur.kind; + match *kind { + block_scope(ref mut inf) => { + debug!("in_scope_cx: selected cur=%s (cx=%s)", + cur.to_str(), cx.to_str()); + f(inf); + return; + } + _ => () + } } cur = block_parent(cur); } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index b5aab1f3ac5e9..4cf12576a78ee 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -237,7 +237,7 @@ pub fn trans_break_cont(bcx: block, let mut unwind = bcx; let mut target; loop { - match unwind.kind { + match *unwind.kind { block_scope(scope_info { loop_break: Some(brk), loop_label: l, diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 38134d4321adb..eb92b23c9d7e7 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -196,7 +196,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, struct CtxtRepr { parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg, - backtrace: Option<@ExpnInfo>, + backtrace: @mut Option<@ExpnInfo>, mod_path: ~[ast::ident], trace_mac: bool } @@ -205,33 +205,33 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, fn parse_sess(@mut self) -> @mut parse::ParseSess { self.parse_sess } fn cfg(@mut self) -> ast::crate_cfg { self.cfg } fn call_site(@mut self) -> span { - match self.backtrace { + match *self.backtrace { Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs, None => self.bug(~"missing top span") } } fn print_backtrace(@mut self) { } - fn backtrace(@mut self) -> Option<@ExpnInfo> { self.backtrace } + fn backtrace(@mut self) -> Option<@ExpnInfo> { *self.backtrace } fn mod_push(@mut self, i: ast::ident) { self.mod_path.push(i); } fn mod_pop(@mut self) { self.mod_path.pop(); } fn mod_path(@mut self) -> ~[ast::ident] { return self.mod_path; } fn bt_push(@mut self, ei: codemap::ExpnInfo) { match ei { ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => { - self.backtrace = + *self.backtrace = Some(@ExpandedFrom(CallInfo { call_site: span {lo: cs.lo, hi: cs.hi, - expn_info: self.backtrace}, + expn_info: *self.backtrace}, callee: (*callee)})); } } } fn bt_pop(@mut self) { - match self.backtrace { + match *self.backtrace { Some(@ExpandedFrom(CallInfo { call_site: span {expn_info: prev, _}, _ })) => { - self.backtrace = prev + *self.backtrace = prev } _ => self.bug(~"tried to pop without a push") } @@ -280,7 +280,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, let imp: @mut CtxtRepr = @mut CtxtRepr { parse_sess: parse_sess, cfg: cfg, - backtrace: None, + backtrace: @mut None, mod_path: ~[], trace_mac: false }; diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index aa9036d295e53..3817f89b8173f 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -28,7 +28,7 @@ use std::oldmap::HashMap; `~` */ ///an unzipping of `token_tree`s struct TtFrame { - readme: ~[ast::token_tree], + readme: @mut ~[ast::token_tree], idx: uint, dotdotdoted: bool, sep: Option, @@ -60,7 +60,7 @@ pub fn new_tt_reader(sp_diag: span_handler, sp_diag: sp_diag, interner: itr, mut cur: @mut TtFrame { - readme: src, + readme: @mut src, idx: 0u, dotdotdoted: false, sep: None, @@ -82,7 +82,7 @@ pub fn new_tt_reader(sp_diag: span_handler, pure fn dup_tt_frame(f: @mut TtFrame) -> @mut TtFrame { @mut TtFrame { - readme: f.readme, + readme: @mut (copy *f.readme), idx: f.idx, dotdotdoted: f.dotdotdoted, sep: f.sep, @@ -199,9 +199,9 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan { loop { /* because it's easiest, this handles `tt_delim` not starting with a `tt_tok`, even though it won't happen */ match r.cur.readme[r.cur.idx] { - tt_delim(copy tts) => { + tt_delim(tts) => { r.cur = @mut TtFrame { - readme: tts, + readme: @mut copy tts, idx: 0u, dotdotdoted: false, sep: None, @@ -242,7 +242,7 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan { r.repeat_len.push(len); r.repeat_idx.push(0u); r.cur = @mut TtFrame { - readme: tts, + readme: @mut copy tts, idx: 0u, dotdotdoted: true, sep: sep, From 9c71249b9d97581e273938986e1fd67fd7b7b20b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 21 Feb 2013 15:30:24 -0800 Subject: [PATCH 3/4] librustc: De-mut trans. rs=demuting --- src/librustc/middle/trans/_match.rs | 6 ++--- src/librustc/middle/trans/base.rs | 34 +++++++++++++------------- src/librustc/middle/trans/common.rs | 34 +++++++++++++------------- src/librustc/middle/trans/debuginfo.rs | 4 +-- src/librustc/middle/trans/expr.rs | 4 +-- src/librustc/middle/trans/glue.rs | 4 +-- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 5e37406bdd752..df6073f9339b4 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -831,7 +831,7 @@ pub fn extract_variant_args(bcx: block, -> ExtractedBlock { let (enm, evar) = vdefs; let _icx = bcx.insn_ctxt("match::extract_variant_args"); - let ccx = bcx.fcx.ccx; + let ccx = *bcx.fcx.ccx; let enum_ty_substs = match ty::get(node_id_type(bcx, pat_id)).sty { ty::ty_enum(id, ref substs) => { assert id == enm; @@ -1272,7 +1272,7 @@ pub fn compile_submatch(bcx: block, let vals_left = vec::append(vec::slice(vals, 0u, col).to_vec(), vec::slice(vals, col + 1u, vals.len())); - let ccx = bcx.fcx.ccx; + let ccx = *bcx.fcx.ccx; let mut pat_id = 0; for vec::each(m) |br| { // Find a real id (we're adding placeholder wildcard patterns, but @@ -1710,7 +1710,7 @@ pub fn bind_irrefutable_pat(bcx: block, binding_mode: IrrefutablePatternBindingMode) -> block { let _icx = bcx.insn_ctxt("match::bind_irrefutable_pat"); - let ccx = bcx.fcx.ccx; + let ccx = *bcx.fcx.ccx; let mut bcx = bcx; // Necessary since bind_irrefutable_pat is called outside trans_match diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 499cbda4118ac..cadbe1208ad2b 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1162,7 +1162,7 @@ pub fn trans_stmt(cx: block, s: ast::stmt) -> block { } } } - ast::decl_item(i) => trans_item(cx.fcx.ccx, *i) + ast::decl_item(i) => trans_item(*cx.fcx.ccx, *i) } } ast::stmt_mac(*) => cx.tcx().sess.bug(~"unexpanded macro") @@ -1584,25 +1584,25 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext, param_substs: Option<@param_substs>, sp: Option) -> fn_ctxt { let llbbs = mk_standard_basic_blocks(llfndecl); - return @fn_ctxt_ { + return @mut fn_ctxt_ { llfn: llfndecl, llenv: unsafe { llvm::LLVMGetParam(llfndecl, 1u as c_uint) }, llretptr: unsafe { llvm::LLVMGetParam(llfndecl, 0u as c_uint) }, - mut llstaticallocas: llbbs.sa, - mut llloadenv: None, - mut llreturn: llbbs.rt, - mut llself: None, - mut personality: None, - mut loop_ret: None, - llargs: HashMap(), - lllocals: HashMap(), - llupvars: HashMap(), + llstaticallocas: llbbs.sa, + llloadenv: None, + llreturn: llbbs.rt, + llself: None, + personality: None, + loop_ret: None, + llargs: @HashMap(), + lllocals: @HashMap(), + llupvars: @HashMap(), id: id, impl_id: impl_id, param_substs: param_substs, span: sp, path: path, - ccx: ccx + ccx: @ccx }; } @@ -1792,7 +1792,7 @@ pub fn trans_closure(ccx: @CrateContext, llvm::LLVMSetGC(fcx.llfn, strategy); } } - ccx.uses_gc = true; + *ccx.uses_gc = true; } // Create the first basic block in the function and keep a handle on it to @@ -2815,7 +2815,7 @@ pub fn trap(bcx: block) { } pub fn decl_gc_metadata(ccx: @CrateContext, llmod_id: ~str) { - if !ccx.sess.opts.gc || !ccx.uses_gc { + if !ccx.sess.opts.gc || !*ccx.uses_gc { return; } @@ -3050,7 +3050,7 @@ pub fn trans_crate(sess: session::Session, discrims: HashMap(), discrim_symbols: HashMap(), tydescs: ty::new_ty_hash(), - mut finished_tydescs: false, + finished_tydescs: @mut false, external: HashMap(), monomorphized: HashMap(), monomorphizing: HashMap(), @@ -3092,9 +3092,9 @@ pub fn trans_crate(sess: session::Session, builder: BuilderRef_res(unsafe { llvm::LLVMCreateBuilder() }), shape_cx: mk_ctxt(llmod), crate_map: crate_map, - mut uses_gc: false, + uses_gc: @mut false, dbg_cx: dbg_cx, - mut do_not_commit_warning_issued: false + do_not_commit_warning_issued: @mut false }; { diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index a69e51c666c6f..8bd85be0f7082 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -175,7 +175,7 @@ pub struct CrateContext { tydescs: HashMap, // Set when running emit_tydescs to enforce that no more tydescs are // created. - mut finished_tydescs: bool, + finished_tydescs: @mut bool, // Track mapping of external ids to local items imported for inlining external: HashMap>, // Cache instances of monomorphized functions @@ -224,9 +224,9 @@ pub struct CrateContext { // Set when at least one function uses GC. Needed so that // decl_gc_metadata knows whether to link to the module metadata, which // is not emitted by LLVM's GC pass when no functions use GC. - mut uses_gc: bool, + uses_gc: @mut bool, dbg_cx: Option, - mut do_not_commit_warning_issued: bool + do_not_commit_warning_issued: @mut bool } // Types used for llself. @@ -273,34 +273,34 @@ pub struct fn_ctxt_ { // the function, due to LLVM's quirks. // A block for all the function's static allocas, so that LLVM // will coalesce them into a single alloca call. - mut llstaticallocas: BasicBlockRef, + llstaticallocas: BasicBlockRef, // A block containing code that copies incoming arguments to space // already allocated by code in one of the llallocas blocks. // (LLVM requires that arguments be copied to local allocas before // allowing most any operation to be performed on them.) - mut llloadenv: Option, - mut llreturn: BasicBlockRef, + llloadenv: Option, + llreturn: BasicBlockRef, // The 'self' value currently in use in this function, if there // is one. // // NB: This is the type of the self *variable*, not the self *type*. The // self type is set only for default methods, while the self variable is // set for all methods. - mut llself: Option, + llself: Option, // The a value alloca'd for calls to upcalls.rust_personality. Used when // outputting the resume instruction. - mut personality: Option, + personality: Option, // If this is a for-loop body that returns, this holds the pointers needed // for that (flagptr, retptr) - mut loop_ret: Option<(ValueRef, ValueRef)>, + loop_ret: Option<(ValueRef, ValueRef)>, // Maps arguments to allocas created for them in llallocas. - llargs: HashMap, + llargs: @HashMap, // Maps the def_ids for local variables to the allocas created for // them in llallocas. - lllocals: HashMap, + lllocals: @HashMap, // Same as above, but for closure upvars - llupvars: HashMap, + llupvars: @HashMap, // The node_id of the function, or -1 if it doesn't correspond to // a user-defined function. @@ -319,14 +319,14 @@ pub struct fn_ctxt_ { path: path, // This function's enclosing crate context. - ccx: @CrateContext + ccx: @@CrateContext } -pub type fn_ctxt = @fn_ctxt_; +pub type fn_ctxt = @mut fn_ctxt_; pub fn warn_not_to_commit(ccx: @CrateContext, msg: ~str) { - if !ccx.do_not_commit_warning_issued { - ccx.do_not_commit_warning_issued = true; + if !*ccx.do_not_commit_warning_issued { + *ccx.do_not_commit_warning_issued = true; ccx.sess.warn(msg + ~" -- do not commit like this!"); } } @@ -689,7 +689,7 @@ pub fn block_parent(cx: block) -> block { // Accessors pub impl block { - pure fn ccx() -> @CrateContext { self.fcx.ccx } + pure fn ccx() -> @CrateContext { *self.fcx.ccx } pure fn tcx() -> ty::ctxt { self.fcx.ccx.tcx } pure fn sess() -> Session { self.fcx.ccx.sess } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 606f7ce725939..8a28769756e6e 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -778,7 +778,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) pub fn create_arg(bcx: block, arg: ast::arg, sp: span) -> Option<@Metadata> { unsafe { - let fcx = bcx.fcx, cx = fcx.ccx; + let fcx = bcx.fcx, cx = *fcx.ccx; let cache = get_cache(cx); let tg = ArgVariableTag; match cached_metadata::<@Metadata>( @@ -845,7 +845,7 @@ pub fn update_source_pos(cx: block, s: span) { } pub fn create_function(fcx: fn_ctxt) -> @Metadata { - let cx = fcx.ccx; + let cx = *fcx.ccx; let dbg_cx = (/*bad*/copy cx.dbg_cx).get(); debug!("~~"); diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 936c8cf1ce550..ad171a44859d1 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -944,10 +944,10 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum { } } ast::def_arg(nid, _, _) => { - take_local(bcx, bcx.fcx.llargs, nid) + take_local(bcx, *bcx.fcx.llargs, nid) } ast::def_local(nid, _) | ast::def_binding(nid, _) => { - take_local(bcx, bcx.fcx.lllocals, nid) + take_local(bcx, *bcx.fcx.lllocals, nid) } ast::def_self(nid, _) => { let self_info: ValSelfData = match bcx.fcx.llself { diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 2a07e7a80e762..bbe80431c07fb 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -654,7 +654,7 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info { let _icx = ccx.insn_ctxt("declare_tydesc"); // If emit_tydescs already ran, then we shouldn't be creating any new // tydescs. - assert !ccx.finished_tydescs; + assert !*ccx.finished_tydescs; let llty = type_of(ccx, t); @@ -761,7 +761,7 @@ pub fn make_generic_glue(ccx: @CrateContext, t: ty::t, llfn: ValueRef, pub fn emit_tydescs(ccx: @CrateContext) { let _icx = ccx.insn_ctxt("emit_tydescs"); // As of this point, allow no more tydescs to be created. - ccx.finished_tydescs = true; + *ccx.finished_tydescs = true; for ccx.tydescs.each_value |&val| { let glue_fn_ty = T_ptr(T_generic_glue_fn(ccx)); let ti = val; From 91479363ccc4ee26aadfb3d2bc3b4868ba426ebd Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 21 Feb 2013 15:44:03 -0800 Subject: [PATCH 4/4] librustc: Remove all mutable fields from librustc. rs=demuting --- src/librustc/middle/ty.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 413ec9fcdf389..69c50d7d84ad6 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -230,7 +230,7 @@ pub type ctxt = @ctxt_; struct ctxt_ { diag: syntax::diagnostic::span_handler, interner: HashMap, - mut next_id: uint, + next_id: @mut uint, vecs_implicitly_copyable: bool, legacy_modes: bool, legacy_records: bool, @@ -261,7 +261,7 @@ struct ctxt_ { short_names_cache: HashMap, needs_drop_cache: HashMap, needs_unwind_cleanup_cache: HashMap, - mut tc_cache: LinearMap, + tc_cache: @mut LinearMap, ast_ty_to_ty_cache: HashMap, enum_var_cache: HashMap, trait_method_cache: HashMap, @@ -811,7 +811,7 @@ pub fn mk_ctxt(s: session::Session, @ctxt_ { diag: s.diagnostic(), interner: interner, - mut next_id: 0u, + next_id: @mut 0, vecs_implicitly_copyable: vecs_implicitly_copyable, legacy_modes: legacy_modes, legacy_records: legacy_records, @@ -831,7 +831,7 @@ pub fn mk_ctxt(s: session::Session, short_names_cache: new_ty_hash(), needs_drop_cache: new_ty_hash(), needs_unwind_cleanup_cache: new_ty_hash(), - tc_cache: LinearMap::new(), + tc_cache: @mut LinearMap::new(), ast_ty_to_ty_cache: HashMap(), enum_var_cache: HashMap(), trait_method_cache: HashMap(), @@ -920,7 +920,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option) -> t { let t = @t_box_ { sty: st, - id: cx.next_id, + id: *cx.next_id, flags: flags, o_def_id: o_def_id }; @@ -931,7 +931,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option) -> t { cx.interner.insert(key, t); - cx.next_id += 1u; + *cx.next_id += 1; unsafe { cast::reinterpret_cast(&t) } }