Skip to content

rename Memory::get methods to get_raw to indicate their unchecked nature#66043

Merged
bors merged 1 commit intorust-lang:masterfrom
RalfJung:memory-get-raw
Nov 8, 2019
Merged

rename Memory::get methods to get_raw to indicate their unchecked nature#66043
bors merged 1 commit intorust-lang:masterfrom
RalfJung:memory-get-raw

Conversation

@RalfJung
Copy link
Copy Markdown
Member

@RalfJung RalfJung commented Nov 2, 2019

Some recent Miri PRs started using these methods when they should not; this should discourage their use.

In fact we could make these methods private to the interp module as far as Miri is concerned -- with the exception of the uninit intrinsic which will hopefully go away soon. @bjorn3 @oli-obk does priroda need these methods? It would be great to be able to seal them away.

@rust-highfive
Copy link
Copy Markdown
Contributor

r? @cramertj

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 2, 2019
@cramertj
Copy link
Copy Markdown
Member

cramertj commented Nov 4, 2019

@bors r+

@bors
Copy link
Copy Markdown
Collaborator

bors commented Nov 4, 2019

📌 Commit 0aee0dd has been approved by cramertj

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 4, 2019
@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Nov 4, 2019

does priroda need these methods?

Yes, it needs get to print an allocation: https://github.com/oli-obk/priroda/blob/c6a4126b2bf721716bf5336dd0d848f6780d4d53/src/render/locals.rs#L350

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented Nov 4, 2019

@bjorn3 okay, so we should likely still allow immutable access. But we can shut down mutable access eventually.

@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Nov 4, 2019

I have actually been thinking about allowing the user to mutate state (including allocations) instead of just observing it. However I havent worked on priroda anymore for 5 months according to github.

@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Nov 4, 2019

Maybe renaming the functions to _get_raw and _get_raw_mut will discourage usage even more. This is already used for _intern_substs and several other interners which get wrapped by the function without _ as prefix.

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented Nov 4, 2019

For now I don't think things are bad enough that we need to resort to leading underscores...

Centril added a commit to Centril/rust that referenced this pull request Nov 5, 2019
rename Memory::get methods to get_raw to indicate their unchecked nature

Some recent Miri PRs started using these methods when they should not; this should discourage their use.

In fact we could make these methods private to the `interp` module as far as Miri is concerned -- with the exception of the `uninit` intrinsic which will hopefully go away soon. @bjorn3 @oli-obk does priroda need these methods? It would be great to be able to seal them away.
@Centril
Copy link
Copy Markdown
Contributor

Centril commented Nov 6, 2019

Toolstate failure in #66138 (comment), @bors rollup=never p=-1

Please revert ^-- in a bit.

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented Nov 6, 2019

A Miri failure shouldn't be a problem even during the beta week...?

@Centril
Copy link
Copy Markdown
Contributor

Centril commented Nov 6, 2019

🤷‍♂ -- beats me; it seems to have caused a failure tho... but I think toolstate blockage is finally over.

@bors p=0 rollup=maybe

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented Nov 6, 2019

Ah, clippy-driver also got broken in that rollup. Whether that was this PR or another one I don't know. I guess we'll see.^^

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented Nov 6, 2019

Looks like clippy was affected by another PR in the rollup: #66150

@bors
Copy link
Copy Markdown
Collaborator

bors commented Nov 7, 2019

☔ The latest upstream changes (presumably #66175) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 7, 2019
@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented Nov 8, 2019

Rebased.

@bors r=cramertj

@bors
Copy link
Copy Markdown
Collaborator

bors commented Nov 8, 2019

📌 Commit 15ec8f7 has been approved by cramertj

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 8, 2019
@bors
Copy link
Copy Markdown
Collaborator

bors commented Nov 8, 2019

⌛ Testing commit 15ec8f7 with merge b21093f8fcb2591907a739fd7a05cd8500727521...

Centril added a commit to Centril/rust that referenced this pull request Nov 8, 2019
rename Memory::get methods to get_raw to indicate their unchecked nature

Some recent Miri PRs started using these methods when they should not; this should discourage their use.

In fact we could make these methods private to the `interp` module as far as Miri is concerned -- with the exception of the `uninit` intrinsic which will hopefully go away soon. @bjorn3 @oli-obk does priroda need these methods? It would be great to be able to seal them away.
@Centril
Copy link
Copy Markdown
Contributor

Centril commented Nov 8, 2019

@bors retry rolled up.

Centril added a commit to Centril/rust that referenced this pull request Nov 8, 2019
rename Memory::get methods to get_raw to indicate their unchecked nature

Some recent Miri PRs started using these methods when they should not; this should discourage their use.

In fact we could make these methods private to the `interp` module as far as Miri is concerned -- with the exception of the `uninit` intrinsic which will hopefully go away soon. @bjorn3 @oli-obk does priroda need these methods? It would be great to be able to seal them away.
bors added a commit that referenced this pull request Nov 8, 2019
Rollup of 5 pull requests

Successful merges:

 - #65785 (Transition future compat lints to {ERROR, DENY} - Take 2)
 - #66007 (Remove "here" from "expected one of X here")
 - #66043 (rename Memory::get methods to get_raw to indicate their unchecked nature)
 - #66154 (miri: Rename to_{u,i}size to to_machine_{u,i}size)
 - #66188 (`MethodSig` -> `FnSig` & Use it in `ItemKind::Fn`)

Failed merges:

r? @ghost
@bors bors merged commit 15ec8f7 into rust-lang:master Nov 8, 2019
@RalfJung RalfJung deleted the memory-get-raw branch November 9, 2019 10:11
darmie added a commit to project-blinc/Blinc that referenced this pull request Apr 9, 2026
…n + codegen tool

Scales Phase 1's `web_mobile_demo` proof-of-concept into a zero-
migration pipeline: every example in `crates/blinc_app/examples/*.rs`
that follows a simple convention is automatically buildable for both
desktop and wasm32, no per-example registration needed. New examples
drop a single `.rs` file and are picked up on the next CI run.

The convention (documented in `docs/book/src/contributing/examples.md`
in a follow-up PR):

    //! Example Title
    //!
    //! …description…

    pub fn build_ui(ctx: &mut WindowedContext) -> impl ElementBuilder {
        // the actual demo
    }

    #[cfg(not(target_arch = "wasm32"))]
    fn main() -> Result<()> {
        tracing_subscriber::fmt().init();
        let config = WindowConfig { /* … */ };
        blinc_app::windowed::WindowedApp::run(config, build_ui)
    }

Opt-out: any `//! no-web:` line in the top doc comment makes the
codegen tool skip the file. Three examples opted out: `css_parser_demo`
(CLI diagnostic), `fuchsia_hello` (Fuchsia-only), `multi_window_demo`
(no multi-window on web).

Three landing pieces:

1. **`WebApp` runner type-erasure** (`crates/blinc_app/src/web.rs`).
   `WebApp::run` / `run_with_setup` / `run_with_async_setup` /
   `set_ui_builder` are now generic over `FnMut(&mut WindowedContext) -> E`
   for any `E: ElementBuilder`, matching the desktop runner's
   `WindowedApp::run` signature shape. A new object-safe `UiBuilderFn`
   trait with two methods (`build_from_scratch`, `build_and_update`)
   does the work directly so the concrete element type never has to
   leave the closure. Blanket `impl<F, E> UiBuilderFn for F` covers
   every valid user function.

   Previously the runner stored `Box<dyn FnMut(&mut WindowedContext) -> Div>`,
   which forced every example to return concrete `Div` — broke
   `emoji_demo` (returns `Scroll`), `notch_demo` (returns `Stateful<T>`),
   `text_widgets` (returns `Scroll`), and would have broken any future
   example with a non-`Div` root.

2. **Codegen tool `tools/build-web-examples/`**. Walks
   `crates/blinc_app/examples/*.rs`, parses each file with `syn`,
   detects the convention via AST walk for top-level `pub fn build_ui`,
   and emits one wrapper crate per match under `examples/_generated/<name>/`.

   Each wrapper is a small cdylib that:
     - `build.rs` pre-processes the upstream source to strip `//!`
       inner doc comments and `#![…]` inner attributes (both illegal
       mid-module when `include!`'d due to rust-lang/rust#66043),
       preserving line numbers via blank-line replacement.
     - `src/lib.rs` puts the cleaned example inside a private
       `mod example { include!(…$OUT_DIR/example.rs) }`, imports the
       resulting `build_ui`, and calls `WebApp::run_with_setup` from
       a `#[wasm_bindgen(start)]` shim.
     - `Cargo.toml` has inferred deps (the tool greps for
       `blinc_cn::` / `blinc_icons::` / etc. prefixes in the source).
     - `index.html` + `serve.sh` complete the shipping surface.

   The tool is idempotent, prunes stale wrappers when examples are
   removed, and is NOT in `default-members` — it runs explicitly via
   `cargo run -p blinc-build-web-examples`.

3. **Mass migration** — **36 examples refactored to the convention**
   in a single scripted pass (plus the 5 already-refactored Phase 1
   examples). Every `fn build_ui(ctx: &WindowedContext) -> impl ElementBuilder`
   was rewritten to `pub fn build_ui(ctx: &mut WindowedContext) -> impl ElementBuilder`,
   `fn main` was cfg-gated with `#[cfg(not(target_arch = "wasm32"))]`,
   and `WindowedApp::run(config, |ctx| build_ui(ctx))` became
   `blinc_app::windowed::WindowedApp::run(config, build_ui)`. Zero
   desktop behavior change — `cargo check -p blinc_app --examples
   --features windowed` is clean.

Workspace layout additions:

- `examples/_generated/` with `.gitignore` + `.gitkeep` markers.
  Everything else in the directory is gitignored — generated
  wrappers live in the working tree but never in the commit.
- `Cargo.toml` workspace members gains `examples/_generated/*`
  (empty-match-tolerant glob) and `tools/build-web-examples`.

Verification matrix:
- `cargo check -p blinc_app --examples --features windowed`: clean
- `cargo run -p blinc-build-web-examples`: 41/41 wrappers emitted
- `cargo check --target wasm32-unknown-unknown -p <all 41>`: clean
- `cargo clippy --target wasm32-unknown-unknown -p <all 41> -- -D warnings`: clean
- `RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --all-features`: clean
- `wasm-pack build --target web --release` on 6 representative wrappers
  (including previously-failing `Scroll` and `Stateful<T>` root cases): clean

Remaining work, tracked in follow-up PRs:
- Phase 4: CI workflow to invoke the codegen tool, run wasm-pack on
  every wrapper, stage outputs under `target/book/examples/`, and
  publish via the existing GitHub Pages deploy.
- mdBook gallery page with lazy-loaded iframes per example.
- `docs/book/src/contributing/examples.md` codifying the convention
  for future example authors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants