diff --git a/src/rose/block.c b/src/rose/block.c index b3833d4b..3d1eb9e3 100644 --- a/src/rose/block.c +++ b/src/rose/block.c @@ -141,7 +141,6 @@ void init_for_block(const struct RoseEngine *t, struct hs_scratch *scratch, struct RoseContext *tctxt = &scratch->tctxt; tctxt->t = t; - tctxt->depth = 1; tctxt->groups = t->initialGroups; tctxt->lit_offset_adjust = 1; // index after last byte tctxt->delayLastEndOffset = 0; diff --git a/src/rose/eod.c b/src/rose/eod.c index a6524f96..ef987388 100644 --- a/src/rose/eod.c +++ b/src/rose/eod.c @@ -36,10 +36,8 @@ static really_inline void initContext(const struct RoseEngine *t, u8 *state, u64a offset, struct hs_scratch *scratch, RoseCallback callback, RoseCallbackSom som_callback, void *ctx) { - struct RoseRuntimeState *rstate = getRuntimeState(state); struct RoseContext *tctxt = &scratch->tctxt; tctxt->t = t; - tctxt->depth = rstate->stored_depth; tctxt->groups = loadGroups(t, state); /* TODO: diff groups for eod */ tctxt->lit_offset_adjust = scratch->core_info.buf_offset - scratch->core_info.hlen diff --git a/src/rose/init.c b/src/rose/init.c index d2f85f2c..1cb26821 100644 --- a/src/rose/init.c +++ b/src/rose/init.c @@ -43,11 +43,9 @@ static really_inline void init_rstate(const struct RoseEngine *t, u8 *state) { - // Set runtime state: initial depth is 1 and we take our initial groups - // from the RoseEngine. + // Set runtime state: we take our initial groups from the RoseEngine. DEBUG_PRINTF("setting initial groups to 0x%016llx\n", t->initialGroups); struct RoseRuntimeState *rstate = getRuntimeState(state); - rstate->stored_depth = 1; storeGroups(t, state, t->initialGroups); rstate->flags = 0; rstate->broken = NOT_BROKEN; diff --git a/src/rose/match.c b/src/rose/match.c index 1c688aab..89f0674e 100644 --- a/src/rose/match.c +++ b/src/rose/match.c @@ -205,8 +205,7 @@ hwlmcb_rv_t roseDelayRebuildCallback(size_t start, size_t end, u32 id, printf("\n"); #endif - DEBUG_PRINTF("STATE depth=%u, groups=0x%016llx\n", tctx->depth, - tctx->groups); + DEBUG_PRINTF("STATE groups=0x%016llx\n", tctx->groups); if (isLiteralDR(id)) { return tctx->groups; @@ -224,7 +223,7 @@ hwlmcb_rv_t roseDelayRebuildCallback(size_t start, size_t end, u32 id, pushDelayedMatches(tl, real_end, tctx); - /* we are just repopulating the delay queue, groups and depths should be + /* we are just repopulating the delay queue, groups should be * already set from the original scan. */ return tctx->groups; @@ -425,8 +424,7 @@ int roseAnchoredCallback(u64a end, u32 id, void *ctx) { u64a real_end = ci->buf_offset + end; // index after last byte DEBUG_PRINTF("MATCH id=%u offsets=[???,%llu]\n", id, real_end); - DEBUG_PRINTF("STATE depth=%u, groups=0x%016llx\n", tctxt->depth, - tctxt->groups); + DEBUG_PRINTF("STATE groups=0x%016llx\n", tctxt->groups); if (can_stop_matching(tctxtToScratch(tctxt))) { DEBUG_PRINTF("received a match when we're already dead!\n"); @@ -492,8 +490,7 @@ int roseAnchoredCallback(u64a end, u32 id, void *ctx) { roseSquashGroup(tctxt, tl); } - DEBUG_PRINTF("DONE depth=%u, groups=0x%016llx\n", tctxt->depth, - tctxt->groups); + DEBUG_PRINTF("DONE groups=0x%016llx\n", tctxt->groups); if (real_end > t->floatingMinLiteralMatchOffset) { recordAnchoredLiteralMatch(tctxt, id, real_end); @@ -623,8 +620,7 @@ hwlmcb_rv_t playDelaySlot(struct RoseContext *tctxt, const u8 *delaySlotBase, DEBUG_PRINTF("DELAYED MATCH id=%u offset=%llu\n", literal_id, offset); hwlmcb_rv_t rv = roseProcessDelayedMatch(tctxt->t, offset, literal_id, tctxt); - DEBUG_PRINTF("DONE depth=%u, groups=0x%016llx\n", tctxt->depth, - tctxt->groups); + DEBUG_PRINTF("DONE groups=0x%016llx\n", tctxt->groups); /* delayed literals can't safely set groups. * However we may be setting groups that successors already have @@ -656,8 +652,7 @@ hwlmcb_rv_t flushAnchoredLiteralAtLoc(struct RoseContext *tctxt, u32 curr_loc) { curr_loc); hwlmcb_rv_t rv = roseProcessDelayedAnchoredMatch(tctxt->t, curr_loc, literal_id, tctxt); - DEBUG_PRINTF("DONE depth=%u, groups=0x%016llx\n", tctxt->depth, - tctxt->groups); + DEBUG_PRINTF("DONE groups=0x%016llx\n", tctxt->groups); /* anchored literals can't safely set groups. * However we may be setting groups that successors already @@ -837,8 +832,7 @@ hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctxt) { #endif DEBUG_PRINTF("last end %llu\n", tctx->lastEndOffset); - DEBUG_PRINTF("STATE depth=%u, groups=0x%016llx\n", tctx->depth, - tctx->groups); + DEBUG_PRINTF("STATE groups=0x%016llx\n", tctx->groups); if (can_stop_matching(tctxtToScratch(tctx))) { DEBUG_PRINTF("received a match when we're already dead!\n"); @@ -864,8 +858,7 @@ hwlmcb_rv_t roseCallback(size_t start, size_t end, u32 id, void *ctxt) { rv = roseProcessMainMatch(tctx->t, real_end, id, tctx); - DEBUG_PRINTF("DONE depth=%hhu, groups=0x%016llx\n", tctx->depth, - tctx->groups); + DEBUG_PRINTF("DONE groups=0x%016llx\n", tctx->groups); if (rv != HWLM_TERMINATE_MATCHING) { return tctx->groups; diff --git a/src/rose/match.h b/src/rose/match.h index 59d83a42..cab17267 100644 --- a/src/rose/match.h +++ b/src/rose/match.h @@ -260,14 +260,6 @@ hwlmcb_rv_t cleanUpDelayed(size_t length, u64a offset, struct RoseContext *tctxt return HWLM_CONTINUE_MATCHING; } -static really_inline -void update_depth(struct RoseContext *tctxt, u8 depth) { - u8 d = MAX(tctxt->depth, depth + 1); - assert(d >= tctxt->depth); - DEBUG_PRINTF("depth now %hhu was %hhu\n", d, tctxt->depth); - tctxt->depth = d; -} - static rose_inline void roseFlushLastByteHistory(const struct RoseEngine *t, u8 *state, u64a currEnd, struct RoseContext *tctxt) { diff --git a/src/rose/program_runtime.h b/src/rose/program_runtime.h index cc345e28..6ba86ca6 100644 --- a/src/rose/program_runtime.h +++ b/src/rose/program_runtime.h @@ -387,14 +387,6 @@ char roseTestLeftfix(const struct RoseEngine *t, u32 qi, u32 leftfixLag, } } -static rose_inline -void roseSetRole(const struct RoseEngine *t, u8 *state, - struct RoseContext *tctxt, u32 stateIndex, u8 depth) { - DEBUG_PRINTF("state idx=%u, depth=%u\n", stateIndex, depth); - mmbit_set(getRoleState(state), t->rolesWithStateCount, stateIndex); - update_depth(tctxt, depth); -} - static rose_inline void roseTriggerInfix(const struct RoseEngine *t, u64a start, u64a end, u32 qi, u32 topEvent, u8 cancel, struct RoseContext *tctxt) { @@ -819,7 +811,6 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t, u32 programOffset, PROGRAM_CASE(ANCHORED_DELAY) { if (in_anchored && end > t->floatingMinLiteralMatchOffset) { DEBUG_PRINTF("delay until playback\n"); - update_depth(tctxt, ri->depth); tctxt->groups |= ri->groups; *work_done = 1; assert(ri->done_jump); // must progress @@ -971,7 +962,9 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t, u32 programOffset, PROGRAM_NEXT_INSTRUCTION PROGRAM_CASE(SET_STATE) { - roseSetRole(t, tctxt->state, tctxt, ri->index, ri->depth); + DEBUG_PRINTF("set state index %u\n", ri->index); + mmbit_set(getRoleState(tctxt->state), t->rolesWithStateCount, + ri->index); *work_done = 1; } PROGRAM_NEXT_INSTRUCTION diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index 985efef5..5c56f2d5 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -2941,7 +2941,7 @@ void makeRoleCheckLeftfix(RoseBuildImpl &build, build_context &bc, RoseVertex v, } static -void makeRoleAnchoredDelay(RoseBuildImpl &build, build_context &bc, +void makeRoleAnchoredDelay(RoseBuildImpl &build, UNUSED build_context &bc, RoseVertex v, vector &program) { // Only relevant for roles that can be triggered by the anchored table. if (!build.isAnchored(v)) { @@ -2952,7 +2952,6 @@ void makeRoleAnchoredDelay(RoseBuildImpl &build, build_context &bc, // floatingMinLiteralMatchOffset. auto ri = RoseInstruction(ROSE_INSTR_ANCHORED_DELAY); - ri.u.anchoredDelay.depth = (u8)min(254U, bc.depths.at(v)); ri.u.anchoredDelay.groups = build.g[v].groups; program.push_back(ri); } @@ -3107,7 +3106,6 @@ void makeRoleSetState(const build_context &bc, RoseVertex v, u32 idx = it->second; auto ri = RoseInstruction(ROSE_INSTR_SET_STATE); ri.u.setState.index = idx; - ri.u.setState.depth = (u8)min(254U, bc.depths.at(v)); program.push_back(ri); } @@ -3785,7 +3783,6 @@ aligned_unique_ptr RoseBuildImpl::buildFinalEngine(u32 minWidth) { aligned_unique_ptr sbtable = buildSmallBlockMatcher(*this, &sbsize); build_context bc; - bc.depths = findDepths(*this); // Build NFAs set no_retrigger_queues; diff --git a/src/rose/rose_build_dump.cpp b/src/rose/rose_build_dump.cpp index 96ff7734..e73d81c3 100644 --- a/src/rose/rose_build_dump.cpp +++ b/src/rose/rose_build_dump.cpp @@ -316,8 +316,6 @@ void dumpRoseLiterals(const RoseBuildImpl &build, const char *filename) { os << "ROSE LITERALS: a total of " << build.literals.right.size() << " literals and " << num_vertices(g) << " roles." << endl << endl; - const auto depths = findDepths(build); - for (const auto &e : build.literals.right) { u32 id = e.first; const ue2_literal &s = e.second.s; @@ -387,9 +385,8 @@ void dumpRoseLiterals(const RoseBuildImpl &build, const char *filename) { for (RoseVertex v : verts) { // role info - os << " Index " << g[v].idx << ": depth=" << depths.at(v) - << ", groups=0x" << hex << setw(16) << setfill('0') - << g[v].groups << dec; + os << " Index " << g[v].idx << ": groups=0x" << hex << setw(16) + << setfill('0') << g[v].groups << dec; if (g[v].reports.empty()) { os << ", report=NONE"; diff --git a/src/rose/rose_build_impl.h b/src/rose/rose_build_impl.h index b2604ff0..a7f2e2f7 100644 --- a/src/rose/rose_build_impl.h +++ b/src/rose/rose_build_impl.h @@ -562,10 +562,6 @@ void normaliseLiteralMask(const ue2_literal &s, std::vector &msk, void fillHamsterLiteralList(const RoseBuildImpl &tbi, rose_literal_table table, std::vector *hl); -// Find the minimum depth in hops of each role. Note that a role may be -// accessible from both the root and the anchored root. -std::map findDepths(const RoseBuildImpl &build); - #ifndef NDEBUG bool canImplementGraphs(const RoseBuildImpl &tbi); #endif diff --git a/src/rose/rose_build_misc.cpp b/src/rose/rose_build_misc.cpp index 9ec26d4c..044a4208 100644 --- a/src/rose/rose_build_misc.cpp +++ b/src/rose/rose_build_misc.cpp @@ -1108,39 +1108,6 @@ LeftEngInfo::operator bool() const { return graph || castle || dfa || haig; } -// Find the minimum depth in hops of each role. Note that a role may be -// accessible from both the root and the anchored root. -map findDepths(const RoseBuildImpl &build) { - const RoseGraph &g = build.g; - map depths; - - depths[build.root] = 0; - depths[build.anchored_root] = 0; - - // BFS from root first. - breadth_first_search(g, build.root, visitor(make_bfs_visitor( - record_distances(boost::make_assoc_property_map(depths), - boost::on_tree_edge()))). - vertex_index_map(get(&RoseVertexProps::idx, g))); - - // BFS from anchored root, updating depths in the graph when they get - // smaller. - map depthsAnch; - breadth_first_search(g, build.anchored_root, visitor(make_bfs_visitor( - record_distances(boost::make_assoc_property_map(depthsAnch), - boost::on_tree_edge()))). - vertex_index_map(get(&RoseVertexProps::idx, g))); - for (const auto &e : depthsAnch) { - if (contains(depths, e.first)) { - LIMIT_TO_AT_MOST(&depths[e.first], e.second); - } else { - depths.insert(e); - } - } - - return depths; -} - u32 roseQuality(const RoseEngine *t) { /* Rose is low quality if the atable is a Mcclellan 16 or has multiple DFAs */ diff --git a/src/rose/rose_dump.cpp b/src/rose/rose_dump.cpp index 484fde5f..6210d102 100644 --- a/src/rose/rose_dump.cpp +++ b/src/rose/rose_dump.cpp @@ -196,7 +196,6 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { assert(code <= ROSE_INSTR_END); switch (code) { PROGRAM_CASE(ANCHORED_DELAY) { - os << " depth " << u32{ri->depth} << endl; os << " groups 0x" << std::hex << ri->groups << std::dec << endl; os << " done_jump +" << ri->done_jump << endl; @@ -292,7 +291,6 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { PROGRAM_NEXT_INSTRUCTION PROGRAM_CASE(SET_STATE) { - os << " depth " << u32{ri->depth} << endl; os << " index " << ri->index << endl; } PROGRAM_NEXT_INSTRUCTION diff --git a/src/rose/rose_internal.h b/src/rose/rose_internal.h index 1f927a2c..92a67ae1 100644 --- a/src/rose/rose_internal.h +++ b/src/rose/rose_internal.h @@ -512,7 +512,6 @@ struct lit_benefits { #endif // Rose runtime state struct RoseRuntimeState { - u8 stored_depth; /* depth at stream boundary */ u8 flags; /* high bit true if delay rebuild needed */ u8 broken; /* user has requested that we stop matching */ #if defined(_WIN32) diff --git a/src/rose/rose_program.h b/src/rose/rose_program.h index a2329073..3f59ba15 100644 --- a/src/rose/rose_program.h +++ b/src/rose/rose_program.h @@ -66,7 +66,6 @@ enum RoseInstructionCode { struct ROSE_STRUCT_ANCHORED_DELAY { u8 code; //!< From enum RoseInstructionCode. - u8 depth; //!< Depth for this state. rose_group groups; //!< Bitmask. u32 done_jump; //!< Jump forward this many bytes if successful. }; @@ -160,7 +159,6 @@ struct ROSE_STRUCT_REPORT_SOM_KNOWN { struct ROSE_STRUCT_SET_STATE { u8 code; //!< From enum RoseInstructionCode. - u8 depth; //!< Depth for this state. u32 index; //!< State index in multibit. }; diff --git a/src/rose/stream.c b/src/rose/stream.c index ae119bcf..0bbab851 100644 --- a/src/rose/stream.c +++ b/src/rose/stream.c @@ -409,7 +409,6 @@ void ensureStreamNeatAndTidy(const struct RoseEngine *t, u8 *state, tctxt->lastEndOffset = offset + length; storeGroups(t, state, tctxt->groups); struct RoseRuntimeState *rstate = getRuntimeState(state); - rstate->stored_depth = tctxt->depth; rstate->flags = delay_rb_status; } @@ -454,7 +453,6 @@ void roseStreamExec(const struct RoseEngine *t, u8 *state, struct RoseContext *tctxt = &scratch->tctxt; tctxt->t = t; - tctxt->depth = rstate->stored_depth; tctxt->mpv_inactive = 0; tctxt->groups = loadGroups(t, state); tctxt->lit_offset_adjust = offset + 1; // index after last byte diff --git a/src/scratch.h b/src/scratch.h index a1efe6d9..1faf60f7 100644 --- a/src/scratch.h +++ b/src/scratch.h @@ -106,7 +106,6 @@ struct core_info { struct RoseContext { const struct RoseEngine *t; u8 *state; /**< base pointer to the full state */ - u8 depth; u8 mpv_inactive; u64a groups; u64a lit_offset_adjust; /**< offset to add to matches coming from hwlm */