Commit Graph

4173 Commits

Author SHA1 Message Date
Emilie Burgun
949d316773 Fix realiased streams causing close/1 to leave a dangling stream 2025-02-06 23:00:00 +01:00
Emilie Burgun
0cf46d3ec4 Encapsulate accesses to IndexStore::streams and ::stream_aliases
These two fields are able to hold `Stream` instances, which predicates like `close/1`
expect to be managed properly for their correctness. To ensure that this is the case,
I have removed direct accesses to those two fields, so that they can be properly managed
in one place.
2025-02-06 23:00:00 +01:00
Emilie Burgun
e68ac8347f Document run_module_predicate and handle critical failure in toplevel.pl 2025-02-06 13:36:23 +01:00
Emilie Burgun
d4bf52e82c Disable test_run_module_predicate_throw under miri and support rustc < 1.83 2025-02-06 10:37:54 +01:00
Emilie Burgun
22538a05be Fix backtracking on the topmost predicate triggering UB in run_module_predicate
Fixes #2815, see that issue for my investigation.

This is a one-line fix that I'm quite proud of :)

If the topmost query for `run_module_predicate` needs to backtrack,
then before this commit, one of the following two things may happen:
- A dangling OrFrame is read at stack offset 0
- An AndFrame was at stack offset 0 would be read as an OrFrame

This can be seen by either calling `run_module_predicate` with a
throwing predicate (encountering the second scenario) or a failing
predicate (encountering the first scenario), or by running the following
in the REPL, which triggers a `throw/1` within the error handler, propagating
it all the way up (and encountering the second scenario):

```prolog
?- current_output(S), open(stream(S), write, S0, [type(binary)]).
```

Currently, `Stack` is not equipped with tools to detect this incorrect
behavior, so it would instead try to read an OrFrame at offset 0, which
triggers UB, since transmuting between AndFramePrelude and OrFramePrelude
isn't legal.

In practice, since `AndFramePrelude` is smaller, the later fields of
`OrFramePrelude` would read from the cells following the `AndFramePrelude`,
and would contain nonsensical data, triggering the panic that led to
my investigation in #2815 and that is fairly reliable to witness.

Surprisingly, this wouldn't happen with `run_query`, which led me to
look at how they operate differently. It turns out that `run_query`
inserts an OrFrame at offset 0, which covers both problematic scenarios.

The fix is thus to simply add a call to `Machine::allocate_stub_choice_point`
in `run_module_predicate` :)
2025-02-06 00:43:01 +01:00
bakaq
6d80c843e6 Scan entire predicate in InstallVerifyAttr 2025-02-05 11:40:05 -03:00
bakaq
b8ccebbf24 Fix bug in finding arity for verify attributes 2025-02-04 04:11:11 -03:00
Emilie Burgun
7108e87e92 Make Stream::Null behave like /dev/null 2025-02-03 00:12:03 +01:00
Emilie Burgun
fdc35f8b40 Fix UB caused by interactions with null streams 2025-02-03 00:08:37 +01:00
Emilie Burgun
2fe7b55343 Fix close/1 messing up stream_aliases when user_input or user_output aren't set to Stdin and Stdout 2025-02-03 00:07:39 +01:00
David Farrell
f509d3d66f Line numbers start at 1
Bumps the line number for the singleton warning. When the singleton
occurs on the same line at the term starts, the line number is correct:

    foo(X).

However it stills mis-reports this line number as 1 instead of 5:

    foo(1) :-
        true,
        true,
        true,
        Y.

See issue #1356.
2025-02-02 08:16:05 -05:00
Emilie Burgun
079a69396a Add debug asserts to UntypedArenaPtr::build_with, ::get_tag and raw_ptr_as_cell!
These two functions are pretty unsafe, but having these assertions makes
it easier to catch UB in testing.
2025-01-31 15:15:52 +01:00
Mark Thom
c548b14f50 Merge pull request #2798 from bakaq/clippy_warnings
Fix clippy warnings
2025-01-28 23:24:17 -07:00
bakaq
590d0daa24 Fix clippy warnings 2025-01-28 16:49:41 -03:00
Bennet Bleßmann
7a5a5bb795 fix spelling and grammar errors found by mthom
https://github.com/mthom/scryer-prolog/pull/2791#discussion_r1930025598
2025-01-27 20:40:12 +01:00
Mark Thom
5a869e8b48 Merge pull request #2777 from adri326/fix-2772-rnd_i-clipping
Fix invalid casts in is/2
2025-01-26 23:14:57 -07:00
Mark Thom
28678e708b Merge pull request #2738 from adri326/fix-2275-dcgs-call-module
Fix dcgs using call(M:Pred) when M was left unassigned
2025-01-26 23:14:30 -07:00
Mark Thom
f69c58c6b6 Merge pull request #2793 from Skgland/fix-ci
fix ci and update all used actions
2025-01-26 23:02:23 -07:00
Emilie Burgun
0cde8f9a43 Add integration tests for arithmetic operators
This extensively tests the behavior of is/2, both when compiled and in metacalls.
2025-01-27 00:10:56 +01:00
Emilie Burgun
20735ea34c Fix integer overflow in >>/2 and <</2 2025-01-27 00:10:47 +01:00
Emilie Burgun
f3a92c6551 Fix min/2 and max/2 returning the cast version of its arguments
It now behaves the same way as SWI-Prolog.
2025-01-27 00:06:06 +01:00
Emilie Burgun
e2d1a2b6bc Fix X is gcd(1, 2 ^ 64) triggering a panic
The implementation for gcd/2 would cast the second argument to an isize.
2025-01-27 00:06:06 +01:00
Emilie Burgun
d3361c16d8 Fix round() losing precision on bigints
The original issue can be reproduced with `X is round(2 ^ 54 + 1) - 2 ^ 54, X = 1.`
2025-01-27 00:05:30 +01:00
Emilie Burgun
9420c7e41e Fix rnd_i clipping floats that don't fit in Fixnum
Fixes #2772.

The current implementation of `rnd_i` incorrectly casts `f` (an `f64`)
into an `i64`, before casting it into an `Integer`.

This fixes that issue by using `Integer::try_from(f)` instead,
and failing if `f` is infinite or NaN.

A fixme is left for a future PR to properly handle the resulting errors
in floor/1 and friends (right now they can only be triggered through FFI).
2025-01-27 00:02:04 +01:00
Bennet Bleßmann
a7598184bf fix typo 2025-01-24 18:47:42 +01:00
Markus Triska
bc0f614bf9 FIXED: instantiation and type check for string arguments
This addresses #2790.

The issue first appeared in an example reported by @ak-1 in #2788, and
was successfully analyzed by @flexoron. Many thanks!
2025-01-23 20:18:55 +01:00
Bennet Bleßmann
b1e66f686b Update README.md
fix ambiguity regarding the install location for the cargo install method, also include the binary name
2025-01-23 20:04:43 +01:00
Bennet Bleßmann
b74c8139d1 fix ci and update all used actions 2025-01-23 19:53:59 +01:00
Bennet Bleßmann
75d499bf8a update install link 2025-01-23 19:20:19 +01:00
Bennet Bleßmann
f1100271e2 Update README.md 2025-01-23 19:18:15 +01:00
Bennet Bleßmann
143430dd9c Update README.md 2025-01-23 19:11:08 +01:00
Mark Thom
00e6e323f8 Merge pull request #2768 from robstolarz/RSTO-nix-macos-fix
fix: compile under Nix flake on macOS
2025-01-13 22:15:11 -07:00
Emilie Burgun
b76bdd75e4 Fix #2725 by calling load_context/1 in the unspecified branch of strip_module/3
This fixes #2725, by making it so that `strip_module(Pred, M, P), call(M:P)`
doesn't throw an `instanciation_error` when `Pred` isn't in the form `module:predicate`.

Now, `strip_module(hello, M, P)` will call `load_context(M)`, which unifies `M`
with the topmost module (or `user`).

Two new test cases are added: issue2725.pl, which tests the minimal case id(X) --> X.
and the strip_module(P, M, _), call(M:P) scenario, and module_resolution,
which tests the behavior of strip_module in a few scenarios.
2025-01-12 14:08:28 +01:00
Mark Thom
1ed4fe6555 Merge pull request #2756 from adri326/fix-load-context-unreachable
Fix load_context_module triggering unreachable!()
2025-01-11 21:27:32 -07:00
Rob Stolarz
894405149b fix: compile under Nix flake on macOS 2025-01-11 13:00:46 -08:00
Emilie Burgun
eff094cc29 Add tests for PR #2756 2025-01-08 17:57:40 +01:00
Emilie Burgun
6cedbc33c0 Fix load_context_module triggering unreachable code in unify_atom 2025-01-08 17:57:40 +01:00
Mark Thom
2856cc4371 Merge pull request #2742 from triska/clpb
Revert "FIXED: CLP(B): Delay BDD restriction until after the instantiation"
2025-01-04 13:26:08 -07:00
Mark Thom
a683d3e363 Merge pull request #2728 from aarroyoc/lets-play-brisca
Add tutorial: Let's play Brisca
2025-01-04 13:24:35 -07:00
Mark Thom
2257503951 Merge pull request #2743 from triska/crypto
atom --> string
2025-01-04 13:23:59 -07:00
Mark Thom
531d482ba7 Merge pull request #2744 from triska/files
state when the predicates are true
2025-01-04 13:23:44 -07:00
Markus Triska
28c386422b state when the predicates are true
"returns" is not used in this way in logic programming. "return"
suggests that something went away and is now coming back, but this is
never the case in these situations. The arguments may be variables or
also fully known at the time of the call in most cases.
2025-01-02 18:54:27 +01:00
Markus Triska
edaba024b2 atom --> string 2025-01-02 18:30:29 +01:00
Markus Triska
333d6740ae Revert "FIXED: CLP(B): Delay BDD restriction until after the instantiation."
This reverts commit e185b626bd.

This change is now no longer needed, and the underlying issue is
apparently somewhere else entirely. See the description at:

    https://github.com/mthom/scryer-prolog/issues/2732

Current master behaves differently from Scryer as it was at
099d9aaca6 (i.e., preceding
the commit that is now being reverted), even on the same file.

For an example, see:

    dd41176b97

Scryer now works as expected, and compatibly with SICStus. We still
need to find out what fixed the root cause of this issue.
2025-01-02 18:02:38 +01:00
Adrián Arroyo Calle
56cb27f71c Add tutorial: Let's play Brisca 2024-12-30 23:21:05 +01:00
Mark Thom
d57f871a12 Merge pull request #2681 from hurufu/remove-dcgs-that-have-failed-to-expand
Remove DCGs that have thrown an exception during term expansion
2024-12-25 14:29:38 -07:00
Mark Thom
afc7b74bbd qualify module quantification errors better (#2685) 2024-12-25 12:25:01 -08:00
Mark Thom
d287095e61 style corrections 2024-12-25 12:25:01 -08:00
Aleksy Grabowski
a599a11169 Remove DCGs that have thrown an exception during term expansion
Some DCG constructs aren't supported and can't be expanded, here we
remove offending DCG rule and don't compile it at all – in a similar
fashion to what we do when incorrect goal was found – whole predicate
isn't getting compiled.

Fixes #2675
2024-12-22 10:37:32 +01:00
Mark Thom
b7943837a0 Merge pull request #2714 from triska/graphic_token
prevent accidental amalgamation of graphic token chars in output
2024-12-20 18:42:09 -07:00