From: Ulya Trofimovich Date: Mon, 28 Sep 2015 21:34:06 +0000 (+0100) Subject: Split skeleton arc count limits for permutations, cover and default paths. X-Git-Tag: 0.15~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=078bf6844536b2fb9e549d38fe71142bc089c284;p=re2c Split skeleton arc count limits for permutations, cover and default paths. --- diff --git a/re2c/src/codegen/skeleton/control_flow.cc b/re2c/src/codegen/skeleton/control_flow.cc index e6f74674..629e238a 100644 --- a/re2c/src/codegen/skeleton/control_flow.cc +++ b/re2c/src/codegen/skeleton/control_flow.cc @@ -6,21 +6,21 @@ namespace re2c // see note [estimating total size of paths in skeleton] // We don't need all patterns that cause undefined behaviour. // We only need some examples, the shorter the better. -arccount_t Node::naked_ways (const way_t & prefix, std::vector & ways) +Node::nakeds_t Node::naked_ways (const way_t & prefix, std::vector & ways) { if (!rule.is_none ()) { - return arccount_t (0u); + return nakeds_t (0u); } else if (end ()) { ways.push_back (prefix); - return arccount_t (prefix.size ()); + return nakeds_t (prefix.size ()); } else if (loop < 2) { local_inc _ (loop); - arccount_t size (0u); + nakeds_t size (0u); for (arcsets_t::iterator i = arcsets.begin (); i != arcsets.end (); ++i) { way_t w = prefix; @@ -28,14 +28,14 @@ arccount_t Node::naked_ways (const way_t & prefix, std::vector & ways) size = size + i->first->naked_ways (w, ways); if (size.overflow ()) { - return arccount_t::limit (); + return nakeds_t::limit (); } } return size; } else { - return arccount_t (0u); + return nakeds_t (0u); } } diff --git a/re2c/src/codegen/skeleton/generate_data.cc b/re2c/src/codegen/skeleton/generate_data.cc index 8369265c..a2b716cd 100644 --- a/re2c/src/codegen/skeleton/generate_data.cc +++ b/re2c/src/codegen/skeleton/generate_data.cc @@ -11,7 +11,7 @@ namespace re2c template static void permutate_one (FILE * input, FILE * keys, const multipath_t & path); template - static arccount_t cover_one (FILE * input, FILE * keys, const multipath_t & prefix, const path_t & suffix); + static Node::covers_t cover_one (FILE * input, FILE * keys, const multipath_t & prefix, const path_t & suffix); /* * note [estimating total size of paths in skeleton] @@ -49,7 +49,7 @@ template * does overflow, an error is reported and re2c aborts. * */ -arccount_t Node::sizeof_permutate (arccount_t wid, arccount_t len) +Node::permuts_t Node::sizeof_permutate (permuts_t wid, permuts_t len) { if (end ()) { @@ -58,26 +58,26 @@ arccount_t Node::sizeof_permutate (arccount_t wid, arccount_t len) else if (loop < 2) { local_inc _ (loop); - arccount_t size (0u); - const arccount_t new_len = len + arccount_t (1u); + permuts_t size (0u); + const permuts_t new_len = len + permuts_t (1u); for (arcs_t::iterator i = arcs.begin (); i != arcs.end (); ++i) { - const arccount_t new_wid = wid * arccount_t (i->second.size ()); + const permuts_t new_wid = wid * permuts_t (i->second.size ()); if (new_wid.overflow ()) { - return arccount_t::limit (); + return permuts_t::limit (); } size = size + i->first->sizeof_permutate (new_wid, new_len); if (size.overflow ()) { - return arccount_t::limit (); + return permuts_t::limit (); } } return size; } else { - return arccount_t (0u); + return permuts_t (0u); } } @@ -143,9 +143,9 @@ template * */ template - arccount_t Node::cover (const multipath_t & prefix, FILE * input, FILE * keys) + Node::covers_t Node::cover (const multipath_t & prefix, FILE * input, FILE * keys) { - arccount_t size (0u); + covers_t size (0u); if (suffix != NULL) { size = cover_one (input, keys, prefix, *suffix); @@ -164,7 +164,7 @@ template size = size + i->first->cover (new_prefix, input, keys); if (size.overflow ()) { - return arccount_t::limit (); + return covers_t::limit (); } if (i->first->suffix != NULL && suffix == NULL) { @@ -180,7 +180,7 @@ template void Skeleton::generate_paths_cunit_key (FILE * input, FILE * keys) { multipath_t prefix (nodes->rule); - if (nodes->sizeof_permutate (arccount_t (1u), arccount_t (0u)).overflow ()) + if (nodes->sizeof_permutate (Node::permuts_t (1u), Node::permuts_t (0u)).overflow ()) { if (nodes->cover (prefix, input, keys).overflow ()) { @@ -295,7 +295,7 @@ template } template - static arccount_t cover_one (FILE * input, FILE * keys, const multipath_t & prefix, const path_t & suffix) + static Node::covers_t cover_one (FILE * input, FILE * keys, const multipath_t & prefix, const path_t & suffix) { const size_t prefix_len = prefix.len (); const size_t suffix_len = suffix.len (); @@ -307,7 +307,7 @@ template count = std::max (count, prefix[i]->size ()); } - const arccount_t size = arccount_t (len) * arccount_t (count); + const Node::covers_t size = Node::covers_t (len) * Node::covers_t (count); if (!size.overflow ()) { // input diff --git a/re2c/src/codegen/skeleton/skeleton.h b/re2c/src/codegen/skeleton/skeleton.h index 85835486..2c8ecc5a 100644 --- a/re2c/src/codegen/skeleton/skeleton.h +++ b/re2c/src/codegen/skeleton/skeleton.h @@ -14,11 +14,24 @@ namespace re2c { -static const uint32_t ARC_LIMIT = 1024 * 1024 * 1024; // ~1Gb -typedef u32lim_t arccount_t; - struct Node { + // Types for counting arcs in path permutations and path cover. + // Paths are dumped to file as soon as generated and don't eat + // heap space. Path permutations grow exponentially and are likely + // to exceed limit, so their limit should be low. Path cover grows + // linearly and is unlikely to exceed limit, so its limit may be + // high. + typedef u32lim_t<1024 * 1024 * 32> permuts_t; // ~32Mb + typedef u32lim_t<1024 * 1024 * 1024> covers_t; // ~1Gb + + // Type for counting arcs in paths that cause undefined behaviour. + // These paths are stored on heap, so the limit should be low. + // Most real-world cases have only a few paths. We don't need all + // paths anyway, just some examples. But we want short examples. + // Some synthetized tests can't find short paths with lower limit. + typedef u32lim_t<1024 * 1024 * 64> nakeds_t; // ~64Mb + typedef std::map s2n_map; typedef std::map arcs_t; typedef std::map arcsets_t; @@ -48,12 +61,12 @@ struct Node ~Node (); bool end () const; void calc_dist (); - arccount_t sizeof_permutate (arccount_t inarcs, arccount_t len); + permuts_t sizeof_permutate (permuts_t inarcs, permuts_t len); template void permutate (const multipath_t & prefix, FILE * input, FILE * keys); template - arccount_t cover (const multipath_t & prefix, FILE * input, FILE * keys); - arccount_t naked_ways (const way_t & prefix, std::vector & ways); + covers_t cover (const multipath_t & prefix, FILE * input, FILE * keys); + nakeds_t naked_ways (const way_t & prefix, std::vector & ways); FORBID_COPY (Node); };