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

Improve use of unsafe Rust in arena.rs (#2391) #2393

Merged
merged 5 commits into from
Apr 29, 2024
Merged

Conversation

mthom
Copy link
Owner

@mthom mthom commented Apr 25, 2024

The use of unsafe Rust is revised in arena.rs to answer some of the criticisms made in #2391, particularly regarding the misaligned allocation of some stream types. Explicit use of alloc is removed in favor of Box. TypedAllocSlab<Payload> is a type parameterized template over AllocSlab used to allow rustc to get value allocation right. As well, some new macros (like mem::offset_of!) are used to calculate byte offsets into structs. This requires bumping the Rust version in Cargo.toml to 1.77.

@triska
Copy link
Contributor

triska commented Apr 25, 2024

Several new style check warnings:

warning: this `if` statement can be collapsed
   --> src/machine/system_calls.rs:431:17
    |
431 | /                 if heap[h].get_tag() == HeapCellValueTag::PStrOffset {
432 | |                     if heap[h_offset].get_tag() == HeapCellValueTag::CStr {
433 | |                         return if pstr_chars < max_steps {
434 | |                             CycleSearchResult::ProperList(pstr_chars + 1)
...   |
439 | |                     }
440 | |                 }
    | |_________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
    = note: `#[warn(clippy::collapsible_if)]` on by default
help: collapse nested if block
    |
431 ~                 if heap[h].get_tag() == HeapCellValueTag::PStrOffset && heap[h_offset].get_tag() == HeapCellValueTag::CStr {
432 +                     return if pstr_chars < max_steps {
433 +                         CycleSearchResult::ProperList(pstr_chars + 1)
434 +                     } else {
435 +                         let offset = max_steps as usize + n;
436 +                         CycleSearchResult::PStrLocation(max_steps, h_offset, offset)
437 +                     }
438 +                 }
    |

error: read amount is not handled
   --> src/parser/char_reader.rs:332:13
    |
332 |             (&self.buf[self.pos..]).read_vectored(bufs)?
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount
    = note: `#[deny(clippy::unused_io_amount)]` on by default

warning: match expression looks like `matches!` macro
   --> src/machine/machine_indices.rs:301:56
    |
301 |                       meta_specs.iter().find(|meta_spec| match meta_spec {
    |  ________________________________________________________^
302 | |                         MetaSpec::Colon | MetaSpec::RequiresExpansionWithArgument(_) => true,
303 | |                         _ => false,
304 | |                     })
    | |_____________________^ help: try: `matches!(meta_spec, MetaSpec::Colon | MetaSpec::RequiresExpansionWithArgument(_))`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
    = note: `#[warn(clippy::match_like_matches_macro)]` on by default

warning: casting to the same type is unnecessary (`usize` -> `usize`)
   --> src/machine/system_calls.rs:436:42
    |
436 | ...                   let offset = max_steps as usize + n;
    |                                    ^^^^^^^^^^^^^^^^^^ help: try: `max_steps`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
    = note: `#[warn(clippy::unnecessary_cast)]` on by default

@triska
Copy link
Contributor

triska commented Apr 26, 2024

The test build for ubuntu-22.04 with Rust 1.70 now fails, I think this target should now be removed since Rust 1.77 is required?

Run cargo build --all-targets --target x86_64-unknown-linux-gnu  --verbose
error: package `scryer-prolog v0.9.4 (/home/runner/work/scryer-prolog/scryer-prolog)` cannot be built because it requires rustc 1.77 or newer, while the currently active rustc version is 1.70.0

@mthom mthom merged commit 42a0d68 into master Apr 29, 2024
14 checks passed
@@ -47,7 +47,6 @@ jobs:
# FIXME(issue #2138): run wasm tests, failing to run since https://github.com/mthom/scryer-prolog/pull/2137 removed wasm-pack
- { os: ubuntu-22.04, rust-version: nightly, target: 'wasm32-unknown-unknown', publish: true, args: '--no-default-features' , test-args: '--no-run --no-default-features' }
# rust versions
- { os: ubuntu-22.04, rust-version: "1.70", target: 'x86_64-unknown-linux-gnu'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this job should have been changed to use 1.77 instead of being removed. This job is here to test that the version declared in the Cargo.toml still works, which I think is what to # rust version comment directly above it tried to convey.

Skgland added a commit to Skgland/scryer-prolog that referenced this pull request May 28, 2024
Skgland added a commit to Skgland/scryer-prolog that referenced this pull request May 28, 2024
@bakaq bakaq mentioned this pull request Jul 5, 2024
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

Successfully merging this pull request may close these issues.

4 participants