Skip to content

Commit 81f4c6f

Browse files
authored
fix demo (#108)
Update demo to use new crate name `rustc_pulbic`
1 parent 2f3f59d commit 81f4c6f

File tree

7 files changed

+102
-30
lines changed

7 files changed

+102
-30
lines changed

.github/workflows/demo.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Run a job to ensure formatting is OK
1+
# Run a job to ensure that we can run the demo successfully.
22
name: Run demo
33
on:
44
pull_request:
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1818

1919
- name: Run Demo
2020
run: ./demo/run_demo.sh

demo/Cargo.lock

Lines changed: 0 additions & 7 deletions
This file was deleted.

demo/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
2-
name = "smir-demo"
3-
description = "A little demo tool on how to use StableMIR to analyze crates"
2+
name = "rpub-demo"
3+
description = "A little demo tool on how to use rustc_public to analyze crates"
44
version = "0.0.0"
55
edition = "2021"
66

demo/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn main() {
99
.iter()
1010
.collect();
1111
println!(
12-
"cargo:rustc-link-arg-bin=smir-demo=-Wl,-rpath,{}",
12+
"cargo:rustc-link-arg-bin=rpub-demo=-Wl,-rpath,{}",
1313
rustc_lib.display()
1414
);
1515
}

demo/example/methods.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#![feature(box_into_inner)]
2+
3+
use std::pin::Pin;
4+
use std::rc::Rc;
5+
use std::sync::Arc;
6+
7+
#[derive(Default, Debug)]
8+
struct Example {
9+
inner: String,
10+
}
11+
12+
type Alias = Example;
13+
trait Trait {
14+
type Output;
15+
}
16+
impl Trait for Example {
17+
type Output = Example;
18+
}
19+
20+
#[allow(unused)]
21+
impl Example {
22+
pub fn by_value(self: Self) {
23+
self.by_ref("by_val");
24+
}
25+
26+
pub fn by_ref(self: &Self, source: &str) {
27+
println!("{source}: {}", self.inner);
28+
}
29+
30+
pub fn by_ref_mut(self: &mut Self) {
31+
self.inner = "by_ref_mut".to_string();
32+
self.by_ref("mut");
33+
}
34+
35+
pub fn by_box(self: Box<Self>) {
36+
self.by_ref("by_box");
37+
Box::into_inner(self).by_value();
38+
}
39+
40+
pub fn by_rc(self: Rc<Self>) {
41+
self.by_ref("by_rc");
42+
}
43+
44+
pub fn by_arc(self: Arc<Self>) {
45+
self.by_ref("by_arc");
46+
}
47+
48+
pub fn by_pin(self: Pin<&Self>) {
49+
self.by_ref("by_pin");
50+
}
51+
52+
pub fn explicit_type(self: Arc<Example>) {
53+
self.by_ref("explicit");
54+
}
55+
56+
pub fn with_lifetime<'a>(self: &'a Self) {
57+
self.by_ref("lifetime");
58+
}
59+
60+
pub fn nested<'a>(self: &mut &'a Arc<Rc<Box<Alias>>>) {
61+
self.by_ref("nested");
62+
}
63+
64+
pub fn via_projection(self: <Example as Trait>::Output) {
65+
self.by_ref("via_projection");
66+
}
67+
68+
pub fn from(name: String) -> Self {
69+
Example { inner: name }
70+
}
71+
}
72+
73+
fn main() {
74+
let example = Example::from("Hello".to_string());
75+
example.by_value();
76+
77+
let boxed = Box::new(Example::default());
78+
boxed.by_box();
79+
80+
Example::default().by_ref_mut();
81+
Example::default().with_lifetime();
82+
}

demo/run_demo.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env bash
2-
# Builds and run the demo driver against itself.
3-
# I.e.: This bootstrap itself.
2+
# Builds and run the demo driver against an example.
43

54
REPO_DIR=$(git rev-parse --show-toplevel)
65
DEMO_DIR="${REPO_DIR}/demo"
76

87
cd "${DEMO_DIR}"
9-
cargo run -- src/main.rs --crate-name demo --edition 2021 -C panic=abort
10-
8+
cargo run -- example/methods.rs --crate-name exp --edition 2021 -C panic=abort

demo/src/main.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,41 @@
55

66
extern crate rustc_driver;
77
extern crate rustc_interface;
8-
#[macro_use]
9-
extern crate rustc_smir;
10-
extern crate stable_mir;
8+
extern crate rustc_middle;
9+
extern crate rustc_public;
1110

1211
use std::collections::HashSet;
1312
use std::io::stdout;
14-
use rustc_smir::{run, rustc_internal};
15-
use stable_mir::{CompilerError, CrateDef};
13+
use rustc_public::run;
14+
use rustc_public::{CompilerError, CrateDef};
1615
use std::ops::ControlFlow;
1716
use std::process::ExitCode;
18-
use stable_mir::mir::{LocalDecl, MirVisitor, Terminator, TerminatorKind};
19-
use stable_mir::mir::mono::Instance;
20-
use stable_mir::mir::visit::Location;
21-
use stable_mir::ty::{RigidTy, Ty, TyKind};
17+
use rustc_public::mir::{LocalDecl, MirVisitor, Terminator, TerminatorKind};
18+
use rustc_public::mir::mono::Instance;
19+
use rustc_public::mir::visit::Location;
20+
use rustc_public::ty::{RigidTy, Ty, TyKind};
2221

2322

2423
/// This is a wrapper that can be used to replace rustc.
2524
fn main() -> ExitCode {
26-
let rustc_args = std::env::args().into_iter().collect();
27-
let result = run!(rustc_args, start_demo);
25+
let rustc_args: Vec<String> = std::env::args().collect();
26+
let result = run!(&rustc_args, start_demo);
2827
match result {
2928
Ok(_) | Err(CompilerError::Skipped | CompilerError::Interrupted(_)) => ExitCode::SUCCESS,
3029
_ => ExitCode::FAILURE,
3130
}
3231
}
3332

3433
fn start_demo() -> ControlFlow<()> {
35-
let crate_name = stable_mir::local_crate().name;
34+
let crate_name = rustc_public::local_crate().name;
3635
eprintln!("--- Analyzing crate: {crate_name}");
3736

38-
let crate_items = stable_mir::all_local_items();
37+
let crate_items = rustc_public::all_local_items();
3938
for item in crate_items {
4039
eprintln!(" - {} @{:?}", item.name(), item.span())
4140
}
4241

43-
let entry_fn = stable_mir::entry_fn().unwrap();
42+
let entry_fn = rustc_public::entry_fn().unwrap();
4443
let entry_instance = Instance::try_from(entry_fn).unwrap();
4544
analyze_instance(entry_instance);
4645
ControlFlow::Break(())

0 commit comments

Comments
 (0)