Skip to content

Commit a23c3e3

Browse files
committed
Generator go brrr
1 parent 77652b9 commit a23c3e3

File tree

14 files changed

+169
-18
lines changed

14 files changed

+169
-18
lines changed

Cargo.lock

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,9 +2949,8 @@ dependencies = [
29492949

29502950
[[package]]
29512951
name = "psm"
2952-
version = "0.1.16"
2953-
source = "registry+https://github.com/rust-lang/crates.io-index"
2954-
checksum = "cd136ff4382c4753fc061cb9e4712ab2af263376b95bbd5bd8cd50c020b78e69"
2952+
version = "0.1.18"
2953+
source = "git+https://github.com/nbdd0121/stacker.git#eae7e163f2286071b4abb3c2ba85ad6632df848d"
29552954
dependencies = [
29562955
"cc",
29572956
]
@@ -4496,6 +4495,7 @@ dependencies = [
44964495
"rustc_trait_selection",
44974496
"rustc_ty_utils",
44984497
"smallvec",
4498+
"stackful",
44994499
"tracing",
45004500
]
45014501

@@ -4896,8 +4896,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
48964896
[[package]]
48974897
name = "stacker"
48984898
version = "0.1.14"
4899-
source = "registry+https://github.com/rust-lang/crates.io-index"
4900-
checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4"
4899+
source = "git+https://github.com/nbdd0121/stacker.git#eae7e163f2286071b4abb3c2ba85ad6632df848d"
49014900
dependencies = [
49024901
"cc",
49034902
"cfg-if 1.0.0",
@@ -4906,6 +4905,16 @@ dependencies = [
49064905
"winapi",
49074906
]
49084907

4908+
[[package]]
4909+
name = "stackful"
4910+
version = "0.1.3"
4911+
source = "git+https://github.com/nbdd0121/stackful.git?branch=dev#5fedf72a244f7581bb10d063ae89919636b86ea1"
4912+
dependencies = [
4913+
"cc",
4914+
"libc",
4915+
"stacker",
4916+
]
4917+
49094918
[[package]]
49104919
name = "static_assertions"
49114920
version = "1.1.0"

compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rustc_index = { path = "../rustc_index", package = "rustc_index" }
2525
bitflags = "1.2.1"
2626
measureme = "10.0.0"
2727
libc = "0.2"
28-
stacker = "0.1.14"
28+
stacker = { git = "https://github.com/nbdd0121/stacker.git" }
2929
tempfile = "3.2"
3030

3131
[dependencies.parking_lot]

compiler/rustc_middle/src/arena.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ macro_rules! arena_types {
102102
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
103103

104104
[] dep_kind: rustc_middle::dep_graph::DepKindStruct,
105+
106+
[] steal_typeck_generator: rustc_data_structures::steal::Steal<rustc_middle::ty::TypeckResultGenerator<'tcx>>,
105107
]);
106108
)
107109
}

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#![feature(decl_macro)]
6060
#![feature(drain_filter)]
6161
#![feature(intra_doc_pointers)]
62+
#![feature(generator_trait)]
6263
#![recursion_limit = "512"]
6364
#![allow(rustc::potential_query_instability)]
6465

compiler/rustc_middle/src/query/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,14 @@ rustc_queries! {
808808
desc { "type-checking all item bodies" }
809809
}
810810

811+
query typeck_generator(key: (LocalDefId, u32)) -> (
812+
&'tcx Steal<ty::TypeckResultGenerator<'tcx>>,
813+
std::ops::GeneratorState<(LocalDefId, DefId), &'tcx ty::TypeckResults<'tcx>>,
814+
) {
815+
no_hash
816+
desc { |tcx| "type-checking `{}`, step {}", tcx.def_path_str(key.0.to_def_id()), key.1 }
817+
}
818+
811819
query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
812820
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
813821
cache_on_disk_if { true }

compiler/rustc_middle/src/ty/context.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,25 @@ pub struct GeneratorDiagnosticData<'tcx> {
377377
pub adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>,
378378
}
379379

380+
pub struct TypeckResultGenerator<'tcx>(
381+
pub std::mem::ManuallyDrop<
382+
std::pin::Pin<
383+
Box<
384+
dyn std::ops::Generator<
385+
Yield = (LocalDefId, DefId),
386+
Return = &'tcx TypeckResults<'tcx>,
387+
> + 'tcx,
388+
>,
389+
>,
390+
>,
391+
);
392+
393+
impl fmt::Debug for TypeckResultGenerator<'_> {
394+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
395+
f.debug_tuple("TypeckResultGenerator").finish()
396+
}
397+
}
398+
380399
#[derive(TyEncodable, TyDecodable, Debug, HashStable)]
381400
pub struct TypeckResults<'tcx> {
382401
/// The `HirId::owner` all `ItemLocalId`s in this table are relative to.

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub use self::consts::{
6868
pub use self::context::{
6969
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
7070
CtxtInterners, DelaySpanBugEmitted, FreeRegionInfo, GeneratorDiagnosticData,
71-
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TypeckResults, UserType,
72-
UserTypeAnnotationIndex,
71+
GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TypeckResultGenerator,
72+
TypeckResults, UserType, UserTypeAnnotationIndex,
7373
};
7474
pub use self::instance::{Instance, InstanceDef};
7575
pub use self::list::List;

compiler/rustc_query_impl/src/keys.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,3 +513,16 @@ impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) {
513513
DUMMY_SP
514514
}
515515
}
516+
517+
impl Key for (LocalDefId, u32) {
518+
#[inline(always)]
519+
fn query_crate_is_local(&self) -> bool {
520+
true
521+
}
522+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
523+
self.0.to_def_id().default_span(tcx)
524+
}
525+
fn key_as_def_id(&self) -> Option<DefId> {
526+
Some(self.0.to_def_id())
527+
}
528+
}

compiler/rustc_typeck/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
2929
rustc_ty_utils = { path = "../rustc_ty_utils" }
3030
rustc_lint = { path = "../rustc_lint" }
3131
rustc_serialize = { path = "../rustc_serialize" }
32+
stackful = { git = "https://github.com/nbdd0121/stackful.git", branch = "dev", default-features = false, features = ["nightly"] }

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
537537
did: self.tcx.hir().local_def_id(ast_c.hir_id),
538538
const_param_did: Some(param_def_id),
539539
};
540+
541+
if let Some(y) = self.yield_handle {
542+
y.yeet((const_def.did, param_def_id));
543+
}
544+
540545
let c = ty::Const::from_opt_const_arg_anon_const(self.tcx, const_def);
541546
self.register_wf_obligation(
542547
c.into(),

0 commit comments

Comments
 (0)