Circular rlm_completion <-> rlm_direct import silently drops rlm_completion's local text_string/2 (and its completion_fault clause) when the host user module defines text_string/2 #302
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/prolog-rlm#302
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
rlm_completionandrlm_directnow import from each other (introduced bya89175b, "feat: run typed-plan model steps through native provider sessions"):prolog/rlm_completion.pl:66—:- use_module(rlm_direct, [rlm_direct_model_step/10]).prolog/rlm_direct.pl:13—:- use_module(rlm_completion, [... text_string/2 ...]).When a host's
usermodule already definestext_string/2(any init-file-style host can legitimately do this), SWI-Prolog resolvesrlm_direct's import of the not-yet-definedrlm_completion:text_string/2againstuser. The import is then registered inrlm_completionas imported from user, andrlm_completion's own definition at lines 2634-2636 is rejected:Consequences
rlm_completion:text_string/2becomesimported_from(user)instead of the module-local definition.6957c30): with the collision present,rlm_completion:text_string(foo(1), _)fails without exception instead of raisingcompletion_fault(expected_text(foo(1))). Callers that rely on the fault envelope see a plain failure instead.Reproducer (SWI-Prolog 10.0.2, main @
6957c30)The same repro fires through a
user-module init-file host even without the explicituser:text_string/2above when the host defines its own same-named helper (our worker defined one).Suggested fix
Break the import cycle for the shared text helpers: move
text_string/2(and any other helpers rlm_direct needs) into a leaf module (e.g. a smallrlm_text/rlm_util) that bothrlm_completionandrlm_directimport, or duplicate the three-clause helper locally inrlm_direct. Either way, a runtime module should not import validation helpers from a module that (transitively) imports it back; module resolution then becomes load-order and host-context dependent.Fix in #331 (fresh-process hostile-host regression across three load orders; load-order cycle boundary plus rlm_text leaf module).
Completed by #331 (merged as
eed1639): rlm_text leaf module + load-order cycle boundary; fresh-process hostile-host regression across three load orders is in the deterministic corpus.