Comments (11)
my goal is to desguar the async/await syntax to understand whats behind
from cargo-inspect.
Warning: it's very low-level, but the async fns get desugared.
yeah, i saw, "a little hard"
to understand
thanks a lot for your time!
from cargo-inspect.
This crate was superseded by cargo-expand, which added support for all the features that were missing when we started to work on cargo-inspect. Can you try with cargo-expand?
from cargo-inspect.
i've tried. it doesnt desugar the async fn
and await
.
do i have to run it with special arguments or ... ?
from cargo-inspect.
command:
cargo expand --example simple > examples/simple.expanded.rs
out
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
extern crate tokio;
use tokio::runtime::{Runtime, Builder as RuntimeBuilder};
use tokio::time::sleep as asleep;
use tokio::join as ajoin;
use std::time::Duration;
async fn task_function(task_name: &str) -> usize {
let mut sum = 0usize;
{
::std::io::_print(::core::fmt::Arguments::new_v1(&["start!\n"], &[]));
};
for index in 0..10 {
asleep(Duration::from_secs_f32(0.5)).await;
{
::std::io::_print(::core::fmt::Arguments::new_v1(
&["", ": ", "\n"],
&[
::core::fmt::ArgumentV1::new_display(&task_name),
::core::fmt::ArgumentV1::new_display(&index),
],
));
};
sum += index;
}
{
::std::io::_print(::core::fmt::Arguments::new_v1(&["stop!\n"], &[]));
};
sum
}
async fn async_main() {
let task1 = task_function("task-1");
let task2 = task_function("task-2");
let (r1, r2) = {
use ::tokio::macros::support::{maybe_done, poll_fn, Future, Pin};
use ::tokio::macros::support::Poll::{Ready, Pending};
let mut futures = (maybe_done(task1), maybe_done(task2));
let mut skip_next_time: u32 = 0;
poll_fn(move |cx| {
const COUNT: u32 = 0 + 1 + 1;
let mut is_pending = false;
let mut to_run = COUNT;
let mut skip = skip_next_time;
skip_next_time = if skip + 1 == COUNT { 0 } else { skip + 1 };
loop {
if skip == 0 {
if to_run == 0 {
break;
}
to_run -= 1;
let (fut, ..) = &mut futures;
let mut fut = unsafe { Pin::new_unchecked(fut) };
if fut.poll(cx).is_pending() {
is_pending = true;
}
} else {
skip -= 1;
}
if skip == 0 {
if to_run == 0 {
break;
}
to_run -= 1;
let (_, fut, ..) = &mut futures;
let mut fut = unsafe { Pin::new_unchecked(fut) };
if fut.poll(cx).is_pending() {
is_pending = true;
}
} else {
skip -= 1;
}
}
if is_pending {
Pending
} else {
Ready((
{
let (fut, ..) = &mut futures;
let mut fut = unsafe { Pin::new_unchecked(fut) };
fut.take_output().expect("expected completed future")
},
{
let (_, fut, ..) = &mut futures;
let mut fut = unsafe { Pin::new_unchecked(fut) };
fut.take_output().expect("expected completed future")
},
))
}
})
.await
};
}
fn main() {
let rt = RuntimeBuilder::new_multi_thread()
.enable_time()
.worker_threads(1)
.thread_name("main-workter")
.thread_stack_size(3 * 1024 * 1024)
.build()
.unwrap();
rt.block_on(async_main());
}
from cargo-inspect.
Oof I don't know if you can do that to be honest. At least I don't know of a way but keep me posted if you figure out how to do it. 😕
from cargo-inspect.
cargo-inspect and cargo-expand are just thin wrappers around what the compiler spits out, so if anything it must be a compiler flag. Probably something around rustc -Z
as we do here:
Lines 42 to 49 in 80cbb58
from cargo-inspect.
cargo-inspect and cargo-expand are just thin wrappers around what the compiler spits out
yeah, but how comes that macros
are spitted out (in the most high detail) and async/await syntax is not?
i guess there is a stage at compilation to desugar stuff like async/await
, if let
.. etc (after the macro expansion)
expansion != desugaring
correct me if im wrong
from cargo-inspect.
expansion != desugaring
That's correct.
Expansion is used for macro expansion, but desugaring goes beyond that and is what you want.
You can try
cargo +nightly rustc -- -Zunpretty=mir
Warning: it's very low-level, but the async fns get desugared.
All options here:
rust-lang/rust#36473 (comment)
from cargo-inspect.
Yeah it's tough.
You can limit the output to a few functions like main
. Instructions here: https://github.com/rust-lang/rustc-dev-guide/blob/master/src/mir/debugging.md
Project idea: a MIR prettifier. Although it would probably a task that takes a lifetime to complete. 😆
from cargo-inspect.
Project idea: a MIR prettifier. Although it would probably a task that takes a lifetime to complete. laughing
yep, no thanks 😆
from cargo-inspect.
Related Issues (20)
- Support line ranges HOT 3
- Add support for diffing two programs HOT 1
- Use a random spinner while compiling HOT 6
- Write an IntelliJ plugin for cargo-inspect HOT 4
- Add flag for changing colorscheme
- Add flag to change colorscheme
- Cargo inspect fails on 2018 edition use syntax HOT 3
- Add `verbose` flag
- Make `diff` output work with prettyprint HOT 1
- Add travis setup
- Support graphviz/dot files HOT 3
- Make rustfmt more robust on crates HOT 1
- Fix issue with structopt HOT 3
- Const Function Evaluation HOT 3
- Installation fails while building a dep `onig_sys v69.5.0` HOT 11
- Show memory dropping HOT 3
- Is this tool working? HOT 3
- Add support for not expanding macros HOT 1
- Beautiful error messages HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cargo-inspect.