From 9400ddfc949025abddb04344624fba3945562d33 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 7 Mar 2019 14:30:28 +0200 Subject: Move bunch of root scope-only data members to root_extra --- build2/b.cxx | 9 ++++--- build2/bin/init.cxx | 2 +- build2/c/init.cxx | 4 +-- build2/cc/compile-rule.cxx | 2 +- build2/config/init.cxx | 4 +-- build2/config/operation.cxx | 14 ++++++----- build2/config/utility.cxx | 4 +-- build2/cxx/init.cxx | 4 +-- build2/dist/init.cxx | 4 +-- build2/dist/operation.cxx | 16 ++++++------ build2/file.cxx | 61 +++++++++++++++++++++------------------------ build2/install/init.cxx | 10 ++++---- build2/module.cxx | 4 +-- build2/operation.cxx | 4 +-- build2/scope.cxx | 8 +++++- build2/scope.hxx | 59 +++++++++++++++++++++++++++++-------------- build2/test/init.cxx | 4 +-- build2/version/init.cxx | 2 +- build2/version/rule.cxx | 4 +-- 19 files changed, 124 insertions(+), 95 deletions(-) diff --git a/build2/b.cxx b/build2/b.cxx index a7207b9..789bbc2 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -1076,7 +1076,7 @@ main (int argc, char* argv[]) if (first) { mid = m; - mif = rs.meta_operations[m]; + mif = rs.root_extra->meta_operations[m]; if (mif == nullptr) fail (l) << "target " << tn << " does not support meta-" @@ -1088,7 +1088,8 @@ main (int argc, char* argv[]) // else { - const meta_operation_info* mi (rs.meta_operations[mid]); + const meta_operation_info* mi ( + rs.root_extra->meta_operations[mid]); if (mi == nullptr) fail (l) << "target " << tn << " does not support meta-" @@ -1132,7 +1133,7 @@ main (int argc, char* argv[]) auto lookup = [&rs, &l, &tn] (operation_id o) -> const operation_info* { - const operation_info* r (rs.operations[o]); + const operation_info* r (rs.root_extra->operations[o]); if (r == nullptr) fail (l) << "target " << tn << " does not support " @@ -1209,7 +1210,7 @@ main (int argc, char* argv[]) auto check = [&rs, &l, &tn] (operation_id o, const operation_info* i) { - const operation_info* r (rs.operations[o]); + const operation_info* r (rs.root_extra->operations[o]); if (r == nullptr) fail (l) << "target " << tn << " does not support " diff --git a/build2/bin/init.cxx b/build2/bin/init.cxx index 6cfb3f8..52197d2 100644 --- a/build2/bin/init.cxx +++ b/build2/bin/init.cxx @@ -492,7 +492,7 @@ namespace build2 r.insert (perform_uninstall_id, "bin.lib", gr); } - if (const test::module* m = rs.modules.lookup ("test")) + if (const test::module* m = rs.lookup_module ("test")) { r.insert (perform_test_id, "bin.lib", m->group_rule ()); } diff --git a/build2/c/init.cxx b/build2/c/init.cxx index ef4e72d..08deb54 100644 --- a/build2/c/init.cxx +++ b/build2/c/init.cxx @@ -267,7 +267,7 @@ namespace build2 if (!cast_false (rs["c.guess.loaded"])) load_module (rs, rs, "c.guess", loc, false, hints); - config_module& cm (*rs.modules.lookup ("c.guess")); + config_module& cm (*rs.lookup_module ("c.guess")); cm.init (rs, loc, hints); return true; } @@ -307,7 +307,7 @@ namespace build2 if (!cast_false (rs["c.config.loaded"])) load_module (rs, rs, "c.config", loc, false, hints); - config_module& cm (*rs.modules.lookup ("c.guess")); + config_module& cm (*rs.lookup_module ("c.guess")); cc::data d { cm, diff --git a/build2/cc/compile-rule.cxx b/build2/cc/compile-rule.cxx index e0faf7f..4d6068d 100644 --- a/build2/cc/compile-rule.cxx +++ b/build2/cc/compile-rule.cxx @@ -3981,7 +3981,7 @@ namespace build2 // #ifndef NDEBUG assert (ps->root ()); - const module* m (ps->modules.lookup (x)); + const module* m (ps->lookup_module (x)); assert (m != nullptr && m->modules); #endif } diff --git a/build2/config/init.cxx b/build2/config/init.cxx index 9dc3a3c..9c50335 100644 --- a/build2/config/init.cxx +++ b/build2/config/init.cxx @@ -52,8 +52,8 @@ namespace build2 // Register meta-operations. Note that we don't register create_id // since it will be pre-processed into configure. // - rs.meta_operations.insert (configure_id, mo_configure); - rs.meta_operations.insert (disfigure_id, mo_disfigure); + rs.insert_meta_operation (configure_id, mo_configure); + rs.insert_meta_operation (disfigure_id, mo_disfigure); return true; // Initialize first (load config.build). } diff --git a/build2/config/operation.cxx b/build2/config/operation.cxx index 1064ebb..724b92d 100644 --- a/build2/config/operation.cxx +++ b/build2/config/operation.cxx @@ -95,7 +95,7 @@ namespace build2 if (verb) text << (verb >= 2 ? "cat >" : "save ") << f; - const module& mod (*root.modules.lookup (module::name)); + const module& mod (*root.lookup_module (module::name)); try { @@ -169,7 +169,7 @@ namespace build2 { // Find the config module. // - if (auto* m = r->modules.lookup (module::name)) + if (auto* m = r->lookup_module (module::name)) { // Find the corresponding saved module. // @@ -539,11 +539,13 @@ namespace build2 if (rs == nullptr) fail << "out of project target " << t; - for (operation_id id (default_id + 1); // Skip default_id - id < rs->operations.size (); + const operations& ops (rs->root_extra->operations); + + for (operation_id id (default_id + 1); // Skip default_id. + id < ops.size (); ++id) { - if (const operation_info* oif = rs->operations[id]) + if (const operation_info* oif = ops[id]) { // Skip aliases (e.g., update-for-install). // @@ -846,7 +848,7 @@ namespace build2 // scope& gs (*scope::global_); scope& rs (load_project (gs, d, d, false /* fwd */, false /* load */)); - module& m (*rs.modules.lookup (module::name)); + module& m (*rs.lookup_module (module::name)); // Save all the global config.import.* variables. // diff --git a/build2/config/utility.cxx b/build2/config/utility.cxx index d2e8699..cc89d2f 100644 --- a/build2/config/utility.cxx +++ b/build2/config/utility.cxx @@ -141,7 +141,7 @@ namespace build2 // The project might not be using the config module. But then how // could we be configuring it? Good question. // - if (module* m = r.modules.lookup (module::name)) + if (module* m = r.lookup_module (module::name)) m->save_variable (var, flags); } @@ -151,7 +151,7 @@ namespace build2 if (current_mif->id != configure_id) return; - if (module* m = r.modules.lookup (module::name)) + if (module* m = r.lookup_module (module::name)) m->save_module (name, prio); } diff --git a/build2/cxx/init.cxx b/build2/cxx/init.cxx index c42f483..0326d22 100644 --- a/build2/cxx/init.cxx +++ b/build2/cxx/init.cxx @@ -482,7 +482,7 @@ namespace build2 if (!cast_false (rs["cxx.guess.loaded"])) load_module (rs, rs, "cxx.guess", loc, false, hints); - config_module& cm (*rs.modules.lookup ("cxx.guess")); + config_module& cm (*rs.lookup_module ("cxx.guess")); cm.init (rs, loc, hints); return true; } @@ -531,7 +531,7 @@ namespace build2 if (!cast_false (rs["cxx.config.loaded"])) load_module (rs, rs, "cxx.config", loc, false, hints); - config_module& cm (*rs.modules.lookup ("cxx.guess")); + config_module& cm (*rs.lookup_module ("cxx.guess")); auto& vp (var_pool.rw (rs)); diff --git a/build2/dist/init.cxx b/build2/dist/init.cxx index b51930b..dabaf45 100644 --- a/build2/dist/init.cxx +++ b/build2/dist/init.cxx @@ -30,9 +30,9 @@ namespace build2 l5 ([&]{trace << "for " << rs.out_path ();}); - // Register meta-operation. + // Register the meta-operation. // - rs.meta_operations.insert (dist_id, mo_dist); + rs.insert_meta_operation (dist_id, mo_dist); // Enter module variables. Do it during boot in case they get assigned // in bootstrap.build (which is customary for, e.g., dist.package). diff --git a/build2/dist/operation.cxx b/build2/dist/operation.cxx index b227bbd..5d46b6e 100644 --- a/build2/dist/operation.cxx +++ b/build2/dist/operation.cxx @@ -143,11 +143,13 @@ namespace build2 const path locf (""); const location loc (&locf); // Dummy location. - for (operations::size_type id (default_id + 1); - id < rs->operations.size (); + const operations& ops (rs->root_extra->operations); + + for (operations::size_type id (default_id + 1); // Skip default_id. + id < ops.size (); ++id) { - if (const operation_info* oif = rs->operations[id]) + if (const operation_info* oif = ops[id]) { // Skip aliases (e.g., update-for-install). In fact, one can argue // the default update should be sufficient since it is assumed to @@ -164,7 +166,7 @@ namespace build2 { if (operation_id pid = oif->pre (params, dist_id, loc)) { - const operation_info* poif (rs->operations[pid]); + const operation_info* poif (ops[pid]); set_current_oif (*poif, oif, false /* diag_noise */); action a (dist_id, poif->id, oif->id); match (params, a, ts, @@ -183,7 +185,7 @@ namespace build2 { if (operation_id pid = oif->post (params, dist_id)) { - const operation_info* poif (rs->operations[pid]); + const operation_info* poif (ops[pid]); set_current_oif (*poif, oif, false /* diag_noise */); action a (dist_id, poif->id, oif->id); match (params, a, ts, @@ -340,7 +342,7 @@ namespace build2 // Copy over all the files. Apply post-processing callbacks. // - module& mod (*rs->modules.lookup (module::name)); + module& mod (*rs->lookup_module (module::name)); prog = prog && show_progress (1 /* max_verb */); size_t prog_percent (0); @@ -374,7 +376,7 @@ namespace build2 { srs = &scopes.find (out_root / pd); - if (auto* m = srs->modules.lookup (module::name)) + if (auto* m = srs->lookup_module (module::name)) cbs = &m->callbacks_; else fail << "dist module not loaded in subproject " << pd; diff --git a/build2/file.cxx b/build2/file.cxx index e205f27..b12d39c 100644 --- a/build2/file.cxx +++ b/build2/file.cxx @@ -278,25 +278,6 @@ namespace build2 rs.out_path_ = &i->first; } - // First time create_root() is called on this scope. - // - bool first (rs.meta_operations.empty ()); - - // Enter built-in meta-operation and operation names. Loading of - // modules (via the src bootstrap; see below) can result in - // additional meta/operations being added. - // - if (first) - { - rs.meta_operations.insert (noop_id, mo_noop); - rs.meta_operations.insert (perform_id, mo_perform); - rs.meta_operations.insert (info_id, mo_info); - - rs.operations.insert (default_id, op_default); - rs.operations.insert (update_id, op_update); - rs.operations.insert (clean_id, op_clean); - } - // If this is already a root scope, verify that things are consistent. // { @@ -474,7 +455,23 @@ namespace build2 a ? alt_root_file : std_root_file, a ? alt_export_file : std_export_file, a ? alt_src_root_file : std_src_root_file, - a ? alt_out_root_file : std_out_root_file}); + a ? alt_out_root_file : std_out_root_file, + {}, /* meta_operations */ + {}, /* operations */ + {}, /* modules */ + {} /* override_cache */}); + + // Enter built-in meta-operation and operation names. Loading of + // modules (via the src bootstrap; see below) can result in + // additional meta/operations being added. + // + root.insert_meta_operation (noop_id, mo_noop); + root.insert_meta_operation (perform_id, mo_perform); + root.insert_meta_operation (info_id, mo_info); + + root.insert_operation (default_id, op_default); + root.insert_operation (update_id, op_update); + root.insert_operation (clean_id, op_clean); } void @@ -723,6 +720,16 @@ namespace build2 { path f (exists (src_root, std_bootstrap_file, alt_bootstrap_file, altn)); + if (root.root_extra == nullptr) + { + // If nothing so far has indicated the naming, assume standard. + // + if (!altn) + altn = false; + + setup_root_extra (root, altn); + } + if (!f.empty ()) { // We assume that bootstrap out cannot load this file explicitly. It @@ -739,16 +746,6 @@ namespace build2 } } - if (root.root_extra == nullptr) - { - // If nothing so far has indicated the naming, assume standard. - // - if (!altn) - altn = false; - - setup_root_extra (root, altn); - } - // See if we are a part of an amalgamation. There are two key players: the // outer root scope which may already be present (i.e., we were loaded as // part of an amalgamation) and the amalgamation variable that may or may @@ -1176,7 +1173,7 @@ namespace build2 // Finish off loading bootstrapped modules. // - for (auto& p: root.modules) + for (auto& p: root.root_extra->modules) { module_state& s (p.second); @@ -1184,7 +1181,7 @@ namespace build2 load_module (root, root, p.first, s.loc); } - for (auto& p: root.modules) + for (auto& p: root.root_extra->modules) { module_state& s (p.second); diff --git a/build2/install/init.cxx b/build2/install/init.cxx index 27f9e9e..3c2b0d1 100644 --- a/build2/install/init.cxx +++ b/build2/install/init.cxx @@ -129,10 +129,10 @@ namespace build2 functions (); // functions.cxx bool - boot (scope& r, const location&, unique_ptr&) + boot (scope& rs, const location&, unique_ptr&) { tracer trace ("install::boot"); - l5 ([&]{trace << "for " << r.out_path ();}); + l5 ([&]{trace << "for " << rs.out_path ();}); // Register install function family if this is the first instance of the // install modules. @@ -142,9 +142,9 @@ namespace build2 // Register our operations. // - r.operations.insert (install_id, op_install); - r.operations.insert (uninstall_id, op_uninstall); - r.operations.insert (update_for_install_id, op_update_for_install); + rs.insert_operation (install_id, op_install); + rs.insert_operation (uninstall_id, op_uninstall); + rs.insert_operation (update_for_install_id, op_update_for_install); return false; } diff --git a/build2/module.cxx b/build2/module.cxx index 9561376..a4a0341 100644 --- a/build2/module.cxx +++ b/build2/module.cxx @@ -19,7 +19,7 @@ namespace build2 { // First see if this modules has already been loaded for this project. // - loaded_module_map& lm (rs.modules); + loaded_module_map& lm (rs.root_extra->modules); auto i (lm.find (name)); if (i != lm.end ()) @@ -62,7 +62,7 @@ namespace build2 { // First see if this modules has already been loaded for this project. // - loaded_module_map& lm (rs.modules); + loaded_module_map& lm (rs.root_extra->modules); auto i (lm.find (name)); bool f (i == lm.end ()); diff --git a/build2/operation.cxx b/build2/operation.cxx index facd1fc..74db2f3 100644 --- a/build2/operation.cxx +++ b/build2/operation.cxx @@ -524,8 +524,8 @@ namespace build2 << "out_root: " << cast (rs[var_out_root]) << endl << "amalgamation: " << cast_empty (rs[var_amalgamation]) << endl << "subprojects: " << cast_empty (rs[var_subprojects]) << endl - << "operations:"; print_ops (rs.operations, operation_table); cout << endl - << "meta-operations:"; print_ops (rs.meta_operations, meta_operation_table); cout << endl; + << "operations:"; print_ops (rs.root_extra->operations, operation_table); cout << endl + << "meta-operations:"; print_ops (rs.root_extra->meta_operations, meta_operation_table); cout << endl; } } diff --git a/build2/scope.cxx b/build2/scope.cxx index ce6945e..bae9818 100644 --- a/build2/scope.cxx +++ b/build2/scope.cxx @@ -424,8 +424,13 @@ namespace build2 // Check the cache. // + variable_override_cache& cache ( + inner_proj == global_scope + ? global_override_cache + : inner_proj->root_extra->override_cache); + pair entry ( - inner_proj->override_cache.insert ( + cache.insert ( make_pair (&var, inner_vars), stem, 0, // Overrides are immutable. @@ -792,6 +797,7 @@ namespace build2 } scope* scope::global_; + scope::variable_override_cache scope::global_override_cache; // scope_map // diff --git a/build2/scope.hxx b/build2/scope.hxx index fe7b0b6..6e48de3 100644 --- a/build2/scope.hxx +++ b/build2/scope.hxx @@ -183,7 +183,8 @@ namespace build2 // variable_type_map target_vars; - // Variable override cache (project root and global scope only). + // Variable override caches. Only on project roots (in root_extra) plus a + // global one for the global scope. // // The key is the variable plus the innermost (scope-wise) variable map to // which this override applies. See find_override() for details. @@ -191,24 +192,17 @@ namespace build2 // Note: since it can be modified on any lookup (including during the // execute phase), the cache is protected by its own mutex shard. // - mutable - variable_cache> - override_cache; + using variable_override_cache = variable_cache>; - // Meta/operations supported by this project (set on the root - // scope only). - // - public: - build2::meta_operations meta_operations; - build2::operations operations; - - using path_type = build2::path; + static variable_override_cache global_override_cache; // Set of buildfiles already loaded for this scope. The included // buildfiles are checked against the project's root scope while // imported -- against the global scope (global_scope). // - std::unordered_set buildfiles; + public: + std::unordered_set buildfiles; // Target types. // @@ -274,11 +268,6 @@ namespace build2 operation_callback_map operation_callbacks; - // Modules. - // - public: - loaded_module_map modules; // Only on root scope. - // Extra root scope-only data. // public: @@ -300,10 +289,42 @@ namespace build2 const path& export_file; // build[2]/export.build[2] const path& src_root_file; // build[2]/bootstrap/src-root.build[2] const path& out_root_file; // build[2]/bootstrap/src-root.build[2] + + // Meta/operations supported by this project. + // + build2::meta_operations meta_operations; + build2::operations operations; + + // Modules. + // + loaded_module_map modules; + + // Variable override cache (see above). + // + mutable variable_override_cache override_cache; }; unique_ptr root_extra; + void + insert_operation (operation_id id, const operation_info& in) + { + root_extra->operations.insert (id, in); + } + + void + insert_meta_operation (meta_operation_id id, const meta_operation_info& in) + { + root_extra->meta_operations.insert (id, in); + } + + template + T* + lookup_module (const string& name) const + { + return root_extra->modules.lookup (name); + } + public: // RW access. // @@ -337,7 +358,7 @@ namespace build2 scope* parent_; scope* root_; - scope* strong_ = nullptr; // Only set on root sopes. + scope* strong_ = nullptr; // Only set on root scopes. // NULL means no strong amalgamtion. }; diff --git a/build2/test/init.cxx b/build2/test/init.cxx index 9f63781..aa2533a 100644 --- a/build2/test/init.cxx +++ b/build2/test/init.cxx @@ -31,8 +31,8 @@ namespace build2 // Register our operations. // - rs.operations.insert (test_id, op_test); - rs.operations.insert (update_for_test_id, op_update_for_test); + rs.insert_operation (test_id, op_test); + rs.insert_operation (update_for_test_id, op_update_for_test); // Enter module variables. Do it during boot in case they get assigned // in bootstrap.build. diff --git a/build2/version/init.cxx b/build2/version/init.cxx index 2c80cec..7e8f0ff 100644 --- a/build2/version/init.cxx +++ b/build2/version/init.cxx @@ -284,7 +284,7 @@ namespace build2 // If the dist module is used, set its dist.package and register the // post-processing callback. // - if (auto* dm = rs.modules.lookup (dist::module::name)) + if (auto* dm = rs.lookup_module (dist::module::name)) { // Make sure dist is init'ed, not just boot'ed. // diff --git a/build2/version/rule.cxx b/build2/version/rule.cxx index 1ff5b41..83f402f 100644 --- a/build2/version/rule.cxx +++ b/build2/version/rule.cxx @@ -80,7 +80,7 @@ namespace build2 // If we match, lookup and cache the module for the update operation. // if (r && a == perform_update_id) - t.data (rs.modules.lookup (module::name)); + t.data (rs.lookup_module (module::name)); return r; } @@ -314,7 +314,7 @@ namespace build2 const path& p (t.path ()); const scope& rs (t.root_scope ()); - const module& m (*rs.modules.lookup (module::name)); + const module& m (*rs.lookup_module (module::name)); if (!m.rewritten) return auto_rmfile (p, false /* active */); -- cgit v1.1