Skip to content

Commit ef60be3

Browse files
bump bevy api gen
1 parent 5de0fec commit ef60be3

File tree

9 files changed

+76
-74
lines changed

9 files changed

+76
-74
lines changed

crates/bevy_api_gen/Cargo.bootstrap.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ version = "0.1.0"
55
edition = "2021"
66

77
[dependencies]
8-
mlua = { version = "0.9.2", features = ["lua54", "vendored", "send", "macros"] }
9-
bevy_reflect = { version = "0.15.0-rc.3", features = [
8+
mlua = { version = "0.10", features = ["lua54", "vendored", "send", "macros"] }
9+
bevy_reflect = { version = "0.15.0", features = [
1010
"bevy",
1111
"glam",
1212
"petgraph",

crates/bevy_api_gen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ rustc_private = true
3939
[dependencies]
4040
log = "0.4"
4141
env_logger = "0.11"
42-
rustc_plugin = { git = "https://github.com/makspll/rustc_plugin", branch = "feature/rust-1.82.0" }
42+
rustc_plugin = "0.12.0-nightly-2024-12-15"
4343
indexmap = "2"
4444
tempdir = "0.3"
4545
cargo_metadata = "0.18"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
22
components = ["clippy", "rust-src", "rustc-dev", "llvm-tools"]
3-
channel = "nightly-2024-11-05"
3+
channel = "nightly-2024-12-15"

crates/bevy_api_gen/src/callback.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ impl rustc_driver::Callbacks for BevyAnalyzerCallbacks {
1919
fn after_expansion<'tcx>(
2020
&mut self,
2121
compiler: &rustc_interface::interface::Compiler,
22-
queries: &'tcx rustc_interface::Queries<'tcx>,
22+
tcx: rustc_middle::ty::TyCtxt<'tcx>,
2323
) -> rustc_driver::Compilation {
2424
trace!("After expansion callback");
25-
let Ok(mut gcx) = queries.global_ctxt() else {
26-
FatalError.raise()
27-
};
25+
2826
let sess = &compiler.sess;
2927

3028
if sess.dcx().has_errors().is_some() {
@@ -59,37 +57,36 @@ impl rustc_driver::Callbacks for BevyAnalyzerCallbacks {
5957
_ => false,
6058
};
6159

62-
gcx.enter(|tcx| {
63-
// tera environment for import processor
64-
let tera = crate::configure_tera(tcx.crate_name(LOCAL_CRATE).as_str(), &templates_dir);
60+
// tera environment for import processor
61+
let tera = crate::configure_tera(tcx.crate_name(LOCAL_CRATE).as_str(), &templates_dir);
6562

66-
let mut ctxt = crate::BevyCtxt::new(
67-
tcx,
68-
&meta_dirs,
69-
WorkspaceMeta::from_env(),
70-
include_private,
71-
Some(Box::new(move |import_path| {
72-
let mut ctxt = Context::new();
73-
ctxt.insert("import", import_path);
74-
tera.render(&TemplateKind::ImportProcessor.to_string(), &ctxt)
75-
.unwrap()
76-
})),
77-
);
63+
let mut ctxt = crate::BevyCtxt::new(
64+
tcx,
65+
&meta_dirs,
66+
WorkspaceMeta::from_env(),
67+
include_private,
68+
Some(Box::new(move |import_path| {
69+
let mut ctxt = Context::new();
70+
ctxt.insert("import", import_path);
71+
tera.render(&TemplateKind::ImportProcessor.to_string(), &ctxt)
72+
.unwrap()
73+
})),
74+
);
7875

79-
trace!("Running all passes");
80-
for p in ALL_PASSES {
81-
info!(
82-
"{}, in crate: {}",
83-
p.description,
84-
tcx.crate_name(LOCAL_CRATE),
85-
);
86-
let continue_ = tcx.sess.time(p.name, || (p.cb)(&mut ctxt, &self.args));
87-
if !continue_ {
88-
break;
89-
}
90-
trace!("Finished pass, continuing");
76+
trace!("Running all passes");
77+
for p in ALL_PASSES {
78+
info!(
79+
"{}, in crate: {}",
80+
p.description,
81+
tcx.crate_name(LOCAL_CRATE),
82+
);
83+
let continue_ = tcx.sess.time(p.name, || (p.cb)(&mut ctxt, &self.args));
84+
if !continue_ {
85+
break;
9186
}
92-
});
87+
trace!("Finished pass, continuing");
88+
}
89+
9390
rustc_driver::Compilation::Continue
9491
}
9592
}

crates/bevy_api_gen/src/passes/find_methods_and_fields.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::{
77
};
88
use rustc_infer::infer::TyCtxtInferExt;
99
use rustc_middle::ty::{
10-
AdtKind, AssocKind, FieldDef, FnSig, ParamEnv, Ty, TyCtxt, TyKind, TypingMode,
10+
AdtKind, AssocKind, FieldDef, FnSig, ParamEnv, Ty, TyCtxt, TyKind, TypingEnv, TypingMode,
1111
};
1212
use rustc_span::Symbol;
1313
use rustc_trait_selection::infer::InferCtxtExt;
@@ -36,8 +36,8 @@ pub(crate) fn find_methods_and_fields(ctxt: &mut BevyCtxt<'_>, _args: &Args) ->
3636
info!("ignoring enum variant: {}::{} due to 'reflect(ignore)' attribute", ctxt.tcx.item_name(def_id), variant.name);
3737
todo!();
3838
}
39-
40-
process_fields(ctxt.tcx, &ctxt.meta_loader, &ctxt.reflect_types, &ctxt.cached_traits, variant.fields.iter(), ctxt.tcx.param_env(variant.def_id))
39+
let param_env = TypingEnv::non_body_analysis(ctxt.tcx, variant.def_id);
40+
process_fields(ctxt.tcx, &ctxt.meta_loader, &ctxt.reflect_types, &ctxt.cached_traits, variant.fields.iter(), param_env)
4141
}).collect::<Vec<_>>();
4242

4343
strats.iter().for_each(|(f_did, strat)| match strat {
@@ -52,7 +52,8 @@ pub(crate) fn find_methods_and_fields(ctxt: &mut BevyCtxt<'_>, _args: &Args) ->
5252

5353
},
5454
AdtKind::Struct => {
55-
let fields = process_fields(ctxt.tcx, &ctxt.meta_loader, &ctxt.reflect_types,&ctxt.cached_traits, adt_def.all_fields(), ctxt.tcx.param_env(def_id));
55+
let param_env = TypingEnv::non_body_analysis(ctxt.tcx, def_id);
56+
let fields = process_fields(ctxt.tcx, &ctxt.meta_loader, &ctxt.reflect_types,&ctxt.cached_traits, adt_def.all_fields(), param_env);
5657
fields.iter().for_each(|(f_did, strat)| match strat {
5758
ReflectionStrategy::Reflection => report_field_not_supported(ctxt.tcx, *f_did, def_id, None, "type is neither a proxy nor a type expressible as lua primitive"),
5859
ReflectionStrategy::Filtered => report_field_not_supported(ctxt.tcx, *f_did, def_id, None, "field has a 'reflect(ignore)' attribute"),
@@ -118,7 +119,8 @@ pub(crate) fn find_methods_and_fields(ctxt: &mut BevyCtxt<'_>, _args: &Args) ->
118119
ctxt.tcx.item_name(def_id)
119120
);
120121

121-
let param_env = ctxt.tcx.param_env(fn_did);
122+
// let param_env = ctxt.tcx.param_env(fn_did);
123+
let param_env = TypingEnv::non_body_analysis(ctxt.tcx, def_id);
122124
let sig: FnSig = ctxt.tcx.normalize_erasing_late_bound_regions(
123125
param_env,
124126
ctxt.tcx.fn_sig(fn_did).instantiate_identity(),
@@ -238,10 +240,9 @@ fn report_field_not_supported(
238240
variant_did: Option<DefId>,
239241
reason: &'static str,
240242
) {
241-
let normalised_ty = tcx.normalize_erasing_regions(
242-
tcx.param_env(type_did),
243-
tcx.type_of(f_did).instantiate_identity(),
244-
);
243+
let param_env = TypingEnv::non_body_analysis(tcx, type_did);
244+
let normalised_ty =
245+
tcx.normalize_erasing_regions(param_env, tcx.type_of(f_did).instantiate_identity());
245246
info!(
246247
"Ignoring field: `{}:{}` on type: `{}` in variant: `{}` as it is not supported: `{}`",
247248
tcx.item_name(f_did),
@@ -259,7 +260,7 @@ fn process_fields<'tcx, 'f, I: Iterator<Item = &'f FieldDef>>(
259260
reflect_types: &IndexMap<DefId, ReflectType<'tcx>>,
260261
cached_traits: &CachedTraits,
261262
fields: I,
262-
param_env: ParamEnv<'tcx>,
263+
param_env: TypingEnv<'tcx>,
263264
) -> Vec<(DefId, ReflectionStrategy)> {
264265
fields
265266
.map(move |f| {
@@ -364,7 +365,7 @@ fn type_is_adt_and_reflectable<'tcx>(
364365
/// Checks if the type can be used directly as a lua function argument, by checking if it implements the FromLua trait
365366
fn type_is_supported_as_non_proxy_arg<'tcx>(
366367
tcx: TyCtxt<'tcx>,
367-
param_env: ParamEnv<'tcx>,
368+
param_env: TypingEnv<'tcx>,
368369
cached_traits: &CachedTraits,
369370
ty: Ty<'tcx>,
370371
) -> bool {
@@ -380,7 +381,7 @@ fn type_is_supported_as_non_proxy_arg<'tcx>(
380381
/// Checks if the type can be used directly as a lua function output
381382
fn type_is_supported_as_non_proxy_return_val<'tcx>(
382383
tcx: TyCtxt<'tcx>,
383-
param_env: ParamEnv<'tcx>,
384+
param_env: TypingEnv<'tcx>,
384385
cached_traits: &CachedTraits,
385386
ty: Ty<'tcx>,
386387
) -> bool {
@@ -401,12 +402,12 @@ fn type_is_supported_as_non_proxy_return_val<'tcx>(
401402

402403
pub(crate) fn impls_trait<'tcx>(
403404
tcx: TyCtxt<'tcx>,
404-
param_env: ParamEnv<'tcx>,
405+
param_env: TypingEnv<'tcx>,
405406
ty: Ty<'tcx>,
406407
trait_did: DefId,
407408
) -> bool {
408409
tcx.infer_ctxt()
409-
.build(TypingMode::non_body_analysis())
410-
.type_implements_trait(trait_did, [ty], param_env)
410+
.build(param_env.typing_mode)
411+
.type_implements_trait(trait_did, [ty], param_env.param_env)
411412
.must_apply_modulo_regions()
412413
}

crates/bevy_api_gen/src/passes/find_trait_impls.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use rustc_infer::{
66
infer::{InferCtxt, TyCtxtInferExt},
77
traits::{Obligation, ObligationCause},
88
};
9-
use rustc_middle::ty::{Ty, TypingMode};
9+
use rustc_middle::ty::{Ty, TypingEnv, TypingMode};
1010
use rustc_span::DUMMY_SP;
11-
use rustc_trait_selection::traits::ObligationCtxt;
11+
use rustc_trait_selection::{regions::InferCtxtRegionExt, traits::ObligationCtxt};
1212

1313
use crate::{Args, BevyCtxt};
1414

@@ -134,7 +134,10 @@ fn impl_matches<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>, impl_def_id: DefId)
134134

135135
let impl_may_apply = |impl_def_id| {
136136
let ocx = ObligationCtxt::new(infcx);
137-
let param_env = tcx.param_env_reveal_all_normalized(impl_def_id);
137+
// let param_env = infcx.resolve_regions(impl_def_id);
138+
// let param_env = tcx.param_env_reveal_all_normalized(impl_def_id);
139+
let typing_env = TypingEnv::non_body_analysis(tcx, impl_def_id);
140+
let param_env = typing_env.with_post_analysis_normalized(tcx).param_env;
138141
let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id);
139142

140143
let impl_trait_ref = tcx

crates/bevy_api_gen/src/passes/populate_template_data.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::Attribute;
55
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
66
use rustc_middle::ty::{
77
print::Print, AdtDef, FieldDef, GenericArg, GenericParamDefKind, ParamTy, TraitRef, Ty, TyKind,
8-
TypeFoldable,
8+
TypeFoldable, TypingEnv,
99
};
1010
use rustc_span::Symbol;
1111

@@ -148,9 +148,10 @@ pub(crate) fn process_functions(ctxt: &BevyCtxt, fns: &[FunctionContext]) -> Vec
148148
.zip(fn_sig.inputs())
149149
.enumerate()
150150
.map(|(idx, (ident, ty))| {
151-
let normalized_ty = ctxt
152-
.tcx
153-
.normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), *ty);
151+
let normalized_ty = ctxt.tcx.normalize_erasing_regions(
152+
TypingEnv::non_body_analysis(ctxt.tcx, fn_ctxt.def_id),
153+
*ty,
154+
);
154155
Arg {
155156
ident: ident.to_string(),
156157
ty: ty_to_string(ctxt, normalized_ty, false),
@@ -160,9 +161,10 @@ pub(crate) fn process_functions(ctxt: &BevyCtxt, fns: &[FunctionContext]) -> Vec
160161
})
161162
.collect();
162163

163-
let out_ty = ctxt
164-
.tcx
165-
.normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), fn_sig.output());
164+
let out_ty = ctxt.tcx.normalize_erasing_regions(
165+
TypingEnv::non_body_analysis(ctxt.tcx, fn_ctxt.def_id),
166+
fn_sig.output(),
167+
);
166168

167169
let output = Output {
168170
ty: ty_to_string(ctxt, out_ty, false),
@@ -288,16 +290,14 @@ pub(crate) enum ProxyType {
288290
Ref,
289291
RefMut,
290292
Val,
291-
NonReflectVal,
292293
}
293294

294295
impl ProxyType {
295296
pub fn to_ident_str(self) -> &'static str {
296297
match self {
297-
ProxyType::Ref => "LuaReflectRefProxy",
298-
ProxyType::RefMut => "LuaReflectRefMutProxy",
299-
ProxyType::Val => "LuaReflectValProxy",
300-
ProxyType::NonReflectVal => "LuaValProxy",
298+
ProxyType::Ref => "Ref",
299+
ProxyType::RefMut => "Mut",
300+
ProxyType::Val => "Val",
301301
}
302302
}
303303
}

crates/bevy_api_gen/src/plugin.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use std::env;
2+
13
use clap::Parser;
24
use log::debug;
35
use rustc_plugin::{CrateFilter, RustcPlugin, RustcPluginArgs, Utf8Path};
46

5-
use std::env;
6-
77
use crate::{modifying_file_loader::ModifyingFileLoader, BevyAnalyzerCallbacks, WorkspaceMeta};
88

99
pub struct BevyAnalyzer;
@@ -47,15 +47,16 @@ impl RustcPlugin for BevyAnalyzer {
4747

4848
struct DefaultCallbacks;
4949
impl rustc_driver::Callbacks for DefaultCallbacks {}
50-
return rustc_driver::RunCompiler::new(&compiler_args, &mut DefaultCallbacks).run();
50+
rustc_driver::RunCompiler::new(&compiler_args, &mut DefaultCallbacks).run();
51+
return Ok(());
5152
}
5253
}
5354
let mut callbacks = BevyAnalyzerCallbacks::new(plugin_args);
5455
let mut compiler = rustc_driver::RunCompiler::new(&compiler_args, &mut callbacks);
5556
compiler.set_file_loader(Some(Box::new(ModifyingFileLoader)));
5657
let out = compiler.run();
5758
log::trace!("Finished compiling with plugin");
58-
out
59+
Ok(())
5960
}
6061

6162
fn modify_cargo(&self, cmd: &mut std::process::Command, args: &Self::Args) {

makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ PACKAGE=bevy_mod_scripting
2121
TEST_NAME=
2222
# # valgrind outputs a callgrind.out.<pid>. We can analyze this with kcachegrind
2323
# kcachegrind
24-
NIGHTLY_VERSION=nightly-2024-11-05
24+
NIGHTLY_VERSION=nightly-2024-12-15
2525
BEVY_VERSION=0.15.0
2626
GLAM_VERSION=0.29.0
2727
CODEGEN_PATH=${PWD}/target/codegen
2828
BEVY_PATH=${CODEGEN_PATH}/bevy
2929
GLAM_PATH=${CODEGEN_PATH}/glam
3030
OUTPUT_PATH=${CODEGEN_PATH}/output
31-
GENERATED_SRC_PATH=./crates/languages/bevy_mod_scripting_lua/src/bindings/providers
31+
GENERATED_SRC_PATH=./crates/bevy_mod_scripting_functions/src/bevy/
3232
GEN_BEVY_FEATURES=bevy_asset,bevy_animation,bevy_core_pipeline,bevy_ui,bevy_pbr,bevy_render,bevy_text,bevy_sprite,file_watcher,multi_threaded
3333

3434
build_test_in_package:
3535
@RUSTFLAGS=-g cargo test --no-run --all-targets --features ${TEST_FEATURES} --package ${PACKAGE} $(TEST_NAME) --message-format=json | jq -r 'first(select(.executable != null and .target.kind == ["test"])) | .executable' | xargs -I@ ln -fs @ ./target/debug/test_binary
3636

3737
run_lua_tests:
38-
cargo test --features=lua54 --package bevy_mod_scripting_lua --test lua_tests
38+
cargo test --features=lua54 --package bevy_mod_scripting_lua --test lua_tests -- $(TEST_NAME)
3939

4040

4141
comp_benches:
@@ -63,7 +63,7 @@ clean_bevy:
6363
cd ${BEVY_PATH} && cargo clean
6464

6565
generate_bevy:
66-
cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen generate --output ${OUTPUT_PATH} --template-args '{ "self_is_bms_lua": true}' --features ${GEN_BEVY_FEATURES}
66+
cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen generate --output ${OUTPUT_PATH} --template-args '{ "self_is_bms_lua": true}' --features ${GEN_BEVY_FEATURES} -vv
6767

6868
collect_bevy:
6969
cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen collect --output ${OUTPUT_PATH} --template-args '{ "self_is_bms_lua": true}'

0 commit comments

Comments
 (0)