Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread 'main' panicked at 'index out of bounds when trying to load Logtalk #1233

Closed
pmoura opened this issue Jan 18, 2022 · 17 comments
Closed

Comments

@pmoura
Copy link
Contributor

pmoura commented Jan 18, 2022

$ RUST_BACKTRACE=full scryerlgt
thread 'main' panicked at 'index out of bounds: the len is 4403647 but the index is 4404631', src/machine/machine_state_impl.rs:1830:33
stack backtrace:
   0:        0x10afd61aa - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd57d5f395e142f2f
   1:        0x10b0057fb - core::fmt::write::h62f25c3166239022
   2:        0x10afc71aa - std::io::Write::write_fmt::h6b320bfaefb5ccfe
   3:        0x10afcc675 - std::panicking::default_hook::{{closure}}::hcde769587fa1eba6
   4:        0x10afcc34d - std::panicking::default_hook::h80880e43d2e08d0c
   5:        0x10afccc7a - std::panicking::rust_panic_with_hook::hd17d2d97b717740f
   6:        0x10afd6b5e - std::panicking::begin_panic_handler::{{closure}}::h0963fa0c208996ec
   7:        0x10afd6307 - std::sys_common::backtrace::__rust_end_short_backtrace::hecb44d618e954dd2
   8:        0x10afcc763 - _rust_begin_unwind
   9:        0x10b019d3f - core::panicking::panic_fmt::hf3797581d3393863
  10:        0x10b019d06 - core::panicking::panic_bounds_check::h4c207279c321710b
  11:        0x10ab3dd77 - <usize as core::slice::index::SliceIndex<[T]>>::index::hb94052bc52567a71
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.0-src/library/core/src/slice/index.rs:184:10
  12:        0x10ab3dd77 - core::slice::index::<impl core::ops::index::Index<I> for [T]>::index::h7bcce19299e70edf
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.0-src/library/core/src/slice/index.rs:15:9
  13:        0x10ab3dd77 - <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index::h62427fac5f7e76be
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.0-src/library/alloc/src/vec/mod.rs:2528:9
  14:        0x10ab3dd77 - scryer_prolog::machine::machine_state_impl::<impl scryer_prolog::machine::machine_state::MachineState>::increment_s_ptr::ha9fe99c785b90633
                               at /Users/pmoura/scryer-prolog/src/machine/machine_state_impl.rs:1830:33
  15:        0x10abef564 - scryer_prolog::machine::dispatch::<impl scryer_prolog::machine::Machine>::dispatch_loop::hd3b09472678969e1
  16:        0x10abef564 - scryer_prolog::machine::Machine::run_module_predicate::h115c853584adea51
                               at /Users/pmoura/scryer-prolog/src/machine/mod.rs:188:24
  17:        0x10ac21567 - scryer_prolog::machine::Machine::run_top_level::h92d56436ece7d272
                               at /Users/pmoura/scryer-prolog/src/machine/mod.rs:282:9
  18:        0x10ab0e34f - scryer_prolog::main::h820e5736c2cb3524
                               at /Users/pmoura/scryer-prolog/src/bin/scryer-prolog.rs:10:5
  19:        0x10ab0d006 - core::ops::function::FnOnce::call_once::h47c1d21e68a2d524
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.0-src/library/core/src/ops/function.rs:227:5
  20:        0x10ab0d006 - std::sys_common::backtrace::__rust_begin_short_backtrace::h513fcaa007a9c680
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.0-src/library/std/src/sys_common/backtrace.rs:123:18
  21:        0x10ab0c24c - std::rt::lang_start::{{closure}}::hd48c130187db70f1
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.0-src/library/std/src/rt.rs:145:18
  22:        0x10afbfec5 - std::rt::lang_start_internal::h0008b9a91a2ef2e8
  23:        0x10ab0e439 - <unknown>
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.0-src/library/core/src/result.rs:1295:23
✘-101 ~ 
@pmoura
Copy link
Contributor Author

pmoura commented Jan 26, 2022

Logtalk starts fine now. Thanks for the bug fixes. But trying to run some simple tests trigger a read error followed by a crash:

?- {aliases(tester)}.
caught: error(syntax_error(incomplete_reduction),read_term/3:25)
!     Unexpected failure while loading the code generated for the file:
!       /Users/pmoura/logtalk/library/types/number.lgt
!     Likely bug in the backend Prolog compiler. Please file a bug report.
Warning: initialization/1 failed for: user: '$lgt_logtalk_load'([types(termp),types(term),types(atomic),types(atom),types(number),types(float),types(integer),types(compound),types(listp),types(list),types(type)],[optimize(on)],'/Users/pmoura/logtalk/library/basic_types/',c(user,user,r(user,user,[],[])))
caught: error(syntax_error(incomplete_reduction),read_term/3:25)
!     Unexpected failure while loading the code generated for the file:
!       /Users/pmoura/logtalk/library/types/number.lgt
!     Likely bug in the backend Prolog compiler. Please file a bug report.
Warning: initialization/1 failed for: user: '$lgt_logtalk_load'([types(termp),types(term),types(atomic),types(atom),types(number),types(float),types(integer),types(compound),types(listp),types(list),types(type)],[optimize(on)],'/Users/pmoura/logtalk/library/basic_types/',c(user,user,r(user,user,[],[])))
caught: error(syntax_error(incomplete_reduction),read_term/3:25)
!     Unexpected failure while loading the code generated for the file:
!       /Users/pmoura/logtalk/library/types/number.lgt
!     Likely bug in the backend Prolog compiler. Please file a bug report.
Warning: initialization/1 failed for: user: '$lgt_logtalk_load'([types(termp),types(term),types(atomic),types(atom),types(number),types(float),types(integer),types(compound),types(listp),types(list),types(type)],[optimize(on)],'/Users/pmoura/logtalk/library/basic_types/',c(user,user,r(user,user,[],[])))
*     Reference to unknown object: list
*       while compiling object os
*       in file /Users/pmoura/logtalk/library/os/os.lgt between lines 2292-2336
*     
thread 'main' panicked at 'byte index 161 is out of bounds of `:-('$os#0.expand_path_chars#2'(_7374963,_7374964,_7374965),','(atom_chars(_7374963,_7374973),','(path_segments(_7374973,'.'(_7374987,_7374988)),','(;(->(=('.'($`', src/heap_print.rs:379:10
stack backtrace:
   0:        0x10afb84ba - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd4fa0e5fd1b0bae0
   1:        0x10afe758b - core::fmt::write::hd6db5571778cce6c
   2:        0x10afa845a - std::io::Write::write_fmt::hf56449a28d15bb2b
   3:        0x10afae805 - std::panicking::default_hook::{{closure}}::h2d0f2e1e91f96447
   4:        0x10afae3de - std::panicking::default_hook::hf6353a5dd2595e53
   5:        0x10afaee0a - std::panicking::rust_panic_with_hook::h916e420d7d249caa
   6:        0x10afb8dde - std::panicking::begin_panic_handler::{{closure}}::hc926ed443b77e590
   7:        0x10afb8617 - std::sys_common::backtrace::__rust_end_short_backtrace::hf8832c1005df0617
   8:        0x10afae8f3 - _rust_begin_unwind
   9:        0x10affba2f - core::panicking::panic_fmt::hedd127944bd71c57
  10:        0x10affbc4d - core::str::slice_error_fail::hfaf65b4c7b4168e8
  11:        0x10ab6cd8f - core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::RangeFrom<usize>>::index::h51569a88cbbbb36b
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/core/src/str/traits.rs:364:21
  12:        0x10ab6cd8f - core::str::traits::<impl core::ops::index::Index<I> for str>::index::h875189113eef7522
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/core/src/str/traits.rs:64:9
  13:        0x10ab6cd8f - <scryer_prolog::heap_print::PrinterOutputter as scryer_prolog::heap_print::HCValueOutputter>::range_from::h779951e815fc30b1
                               at /Users/pmoura/scryer-prolog/src/heap_print.rs:379:10
  14:        0x10ab6cd8f - scryer_prolog::heap_print::HCPrinter<Outputter>::ambiguity_check::h64bb7e64607eebbb
                               at /Users/pmoura/scryer-prolog/src/heap_print.rs:542:20
  15:        0x10ab6cd8f - scryer_prolog::heap_print::HCPrinter<Outputter>::handle_heap_term::h1e4f5fd11ef08616
                               at /Users/pmoura/scryer-prolog/src/heap_print.rs:1450:21
  16:        0x10ab6ea65 - scryer_prolog::heap_print::HCPrinter<Outputter>::print::hd93e415169da4ab6
                               at /Users/pmoura/scryer-prolog/src/heap_print.rs:1510:25
  17:        0x10abd8f2b - scryer_prolog::machine::system_calls::<impl scryer_prolog::machine::Machine>::write_term::h34cb85bf714baf5f
                               at /Users/pmoura/scryer-prolog/src/machine/system_calls.rs:4900:22
  18:        0x10abd8f2b - scryer_prolog::machine::dispatch::<impl scryer_prolog::machine::Machine>::dispatch_loop::ha980dc60645d6aca
                               at /Users/pmoura/scryer-prolog/src/machine/dispatch.rs:4338:52
  19:        0x10abd8f2b - scryer_prolog::machine::Machine::run_module_predicate::hbec72e701763ef83
                               at /Users/pmoura/scryer-prolog/src/machine/mod.rs:188:24
  20:        0x10abfe807 - scryer_prolog::machine::Machine::run_top_level::h926d89ad9e4c82a6
                               at /Users/pmoura/scryer-prolog/src/machine/mod.rs:282:9
  21:        0x10aadd33f - scryer_prolog::main::hcc0438faf361ffec
                               at /Users/pmoura/scryer-prolog/src/bin/scryer-prolog.rs:10:5
  22:        0x10aade046 - core::ops::function::FnOnce::call_once::h7186c7639690107a
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/core/src/ops/function.rs:227:5
  23:        0x10aade046 - std::sys_common::backtrace::__rust_begin_short_backtrace::h239a271907c8db3d
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/std/src/sys_common/backtrace.rs:123:18
  24:        0x10aadd43c - std::rt::lang_start::{{closure}}::hce6a7b59d9b7dbbb
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/std/src/rt.rs:145:18
  25:        0x10afa1ad5 - std::rt::lang_start_internal::he7843d316f67a515
  26:        0x10aadd429 - <unknown>
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/core/src/result.rs:1295:23
✘-101 ~ 

I will try to isolate the read error. But meanwhile I hope the crash stack trace would be useful.

@mthom
Copy link
Owner

mthom commented Feb 1, 2022

Made some progress but now the logtalk os module load is failing.

@pmoura
Copy link
Contributor Author

pmoura commented Feb 1, 2022

Just compiled the latest git version (37e34c5) of the rebis-dev branch. The puzzling exception is still there:

caught: error(syntax_error(incomplete_reduction),read_term/3:25)

It can be reproduced in a more simpler way:

?- {types(number)}.
caught: error(syntax_error(incomplete_reduction),read_term/3:25)
!     Unexpected failure while loading the code generated for the file:
!       /Users/pmoura/logtalk/library/types/number.lgt
!     Likely bug in the backend Prolog compiler. Please file a bug report.
false.

Instrumenting the Scryer adapter file, the number.lgt file is read fine up to included the end_of_file term. Further debugging shows that write_canonical/2 is writing a clause that the parser cannot read back:

?- read(T).
:-('$number#0.=~=#2'(_5654689,_5654690,_5654691),;(->(','('$number#0.epsilon#1'(_5654717,_5654691),<(abs(-(_5654689,_5654690)),*(100,_5654717))),true),<(abs(-(_5654689,_5654690)),*(1e-5,max(abs(_5654689),abs(_5654690)))))).
caught: error(syntax_error(incomplete_reduction),read/2:2)
?- read(T).
1e-5.
caught: error(syntax_error(incomplete_reduction),read/2:2)
?- write(1.0e-5), nl.
1e-5
   true.

@triska
Copy link
Contributor

triska commented Feb 1, 2022

Related: #1258.

@triska
Copy link
Contributor

triska commented Feb 1, 2022

On OSX, I get:

?- write(1.0e-5), nl.
0.00001
   true.

@pmoura
Copy link
Contributor Author

pmoura commented Feb 1, 2022

Interesting. I'm also on macOS (12.1) and I get (with 37e34c5):

$ rustc --version
rustc 1.58.1
$ cargo run --release
   Compiling scryer-prolog v0.9.0 (/Users/pmoura/scryer-prolog)
    Finished release [optimized + debuginfo] target(s) in 1m 54s
     Running `target/release/scryer-prolog`
?- write(1.0e-5), nl.
1e-5
   true.

Could it be a locale issue?

@mthom
Copy link
Owner

mthom commented Feb 1, 2022

On Linux I get 1.000000...

I'm surprised by the difference between platforms. Rust is usually quite good about harmonizing these things.

@triska
Copy link
Contributor

triska commented Feb 1, 2022

When I type $ env, the only environment variable that seems could influence this is:

LC_CTYPE=UTF-8

I tried several different values, and always get the same result. Maybe this is worth filing as an issue for Rust?

@aarroyoc
Copy link
Contributor

aarroyoc commented Feb 1, 2022

On Arch Linux, updated today, it says:

?- write(1.0e-5),nl.
1e-5
   true.
?- 

I don't have LC_CTYPE defined. Just LANG=es_ES.UTF-8

@Skgland
Copy link
Contributor

Skgland commented Feb 2, 2022

Is

format!("{0:<20?}", n)
relevant here?
Then the change in float formatting behaviour could be rust-lang/rust#86479 changing the Debug formatting for floats in 1.58.0

@UWN
Copy link

UWN commented Feb 2, 2022

g1:/opt/gupu/scryer-prolog> target/release/scryer-prolog -f
?- writeq(1e-5).
caught: error(syntax_error(incomplete_reduction),read_term/3:1)
?- writeq(1.0e-5).
0.00001   true.
?- 
g1:/opt/gupu/scryer-prolog> rustc --version
rustc 1.57.0 (f1edd0429 2021-11-29)

And then after rustupping:

g1:/opt/gupu/scryer-prolog> rustc --version
rustc 1.58.1 (db9d1b20b 2022-01-20)
g1:/opt/gupu/scryer-prolog> target/release/scryer-prolog -f
?- writeq(1.0e-5).
1e-5   true.
?- 

@triska
Copy link
Contributor

triska commented Feb 2, 2022

@Skgland: This seems to affect not only Debug, but also when used with --release.

@Skgland
Copy link
Contributor

Skgland commented Feb 2, 2022

Yes, I ment Debug as in std::fmt::Debug with corresponding std::fmt::Display not as in debug vs. release build.

mthom added a commit that referenced this issue Feb 4, 2022
@pmoura
Copy link
Contributor Author

pmoura commented Feb 5, 2022

Next bug, using 2b09cb4:

?- write_canonical([a| _]), nl.
'.'(a _5521893)
   true.

mthom added a commit that referenced this issue Feb 6, 2022
mthom added a commit that referenced this issue Feb 6, 2022
@pmoura
Copy link
Contributor Author

pmoura commented Feb 7, 2022

Thanks for the latest fixes. With e4ea547, I now get:

?- {aliases(tester)}.
Killed: 9

No idea how to debug it this time.

@pmoura
Copy link
Contributor Author

pmoura commented Feb 16, 2022

With 5b82963:

$ RUST_BACKTRACE=full scryerlgt
''-[]
Logtalk 3.54.0-b01
Copyright (c) 1998-2022 Paulo Moura

% Default lint compilation flags: 
%   unknown_predicates: warning, undefined_predicates: warning
%   unknown_entities: warning, steadfastness: silent, naming: silent
%   missing_directives: warning, duplicated_directives: warning
%   duplicated_clauses: silent, portability: silent, deprecated: warning
%   redefined_built_ins: silent, redefined_operators: warning
%   trivial_goal_fails: warning, always_true_or_false_goals: warning
%   lambda_variables: warning, suspicious_calls: warning
%   disjunctions: warning, catchall_catch: silent, tail_recursive: silent
%   singleton_variables: warning, underscore_variables: dont_care
% Default optional features compiler flags:
%   complements: deny, dynamic_declarations: deny
%   context_switching_calls: allow, events: deny
% Other default compilation flags:
%   report: on, scratch_directory: ./.lgt_tmp/
%   source_data: on, code_prefix: $, hook: n/d
%   optimize: off, debug: off, clean: on, reload: changed
% Backend Prolog compiler file compilation and loading flags:
%   prolog_compiler: []
%   prolog_loader:   []
% Read-only compilation flags (backend Prolog compiler features):
%   prolog_dialect: scryer, modules: unsupported, threads: unsupported
%   engines: unsupported, tabling: unsupported, coinduction: unsupported
%   unicode: unsupported, encoding_directive: unsupported
% 
% No settings file found in startup, Logtalk user, home, or config directories.
% Using default flag values set in the backend Prolog compiler adapter file.
% 
% For Logtalk help on libraries, entities, and built-in features, use:
% ?- {help(loader)}. or ?- logtalk_load(help(loader)).
% 
% For Logtalk compiler warnings/errors explanations and fix suggestions, use:
% ?- {tutor(loader)}. or ?- logtalk_load(tutor(loader)).
% 
?- {aliases(tester)}.
thread 'main' panicked at 'index out of bounds: the len is 1024 but the index is 1024', src/machine/dispatch.rs:977:45
stack backtrace:
   0:        0x10e3974ba - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd4fa0e5fd1b0bae0
   1:        0x10e3c69db - core::fmt::write::hd6db5571778cce6c
   2:        0x10e38745a - std::io::Write::write_fmt::hf56449a28d15bb2b
   3:        0x10e38d805 - std::panicking::default_hook::{{closure}}::h2d0f2e1e91f96447
   4:        0x10e38d3de - std::panicking::default_hook::hf6353a5dd2595e53
   5:        0x10e38de0a - std::panicking::rust_panic_with_hook::h916e420d7d249caa
   6:        0x10e397dde - std::panicking::begin_panic_handler::{{closure}}::hc926ed443b77e590
   7:        0x10e397617 - std::sys_common::backtrace::__rust_end_short_backtrace::hf8832c1005df0617
   8:        0x10e38d8f3 - _rust_begin_unwind
   9:        0x10e3dae7f - core::panicking::panic_fmt::hedd127944bd71c57
  10:        0x10e3dae46 - core::panicking::panic_bounds_check::h2b62eb1f35838c2d
  11:        0x10dfd2843 - scryer_prolog::machine::dispatch::<impl scryer_prolog::machine::Machine>::dispatch_loop::ha980dc60645d6aca
                               at /Users/pmoura/scryer-prolog/src/machine/dispatch.rs:977:45
  12:        0x10dfd2843 - scryer_prolog::machine::Machine::run_module_predicate::hbec72e701763ef83
                               at /Users/pmoura/scryer-prolog/src/machine/mod.rs:188:24
  13:        0x10dfdebe7 - scryer_prolog::machine::Machine::run_top_level::h926d89ad9e4c82a6
                               at /Users/pmoura/scryer-prolog/src/machine/mod.rs:282:9
  14:        0x10debc33f - scryer_prolog::main::hcc0438faf361ffec
                               at /Users/pmoura/scryer-prolog/src/bin/scryer-prolog.rs:10:5
  15:        0x10debd046 - core::ops::function::FnOnce::call_once::h7186c7639690107a
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/core/src/ops/function.rs:227:5
  16:        0x10debd046 - std::sys_common::backtrace::__rust_begin_short_backtrace::h239a271907c8db3d
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/std/src/sys_common/backtrace.rs:123:18
  17:        0x10debc43c - std::rt::lang_start::{{closure}}::hce6a7b59d9b7dbbb
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/std/src/rt.rs:145:18
  18:        0x10e380ad5 - std::rt::lang_start_internal::he7843d316f67a515
  19:        0x10debc429 - <unknown>
                               at /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_rust/rust/work/rustc-1.58.1-src/library/core/src/result.rs:1295:23
✘-101 ~ 

@pmoura
Copy link
Contributor Author

pmoura commented Feb 19, 2022

Problem issue in c893247. Thanks! Notably, I'm able to run Logtalk's standards compliance suite again.

@pmoura pmoura closed this as completed Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants