Skip to content

Commit b294625

Browse files
authored
Merge pull request #771 from TitanNano/jovan/required_virtuals
Required virtual methods should be required at compile-time
2 parents 558b29f + 367a928 commit b294625

File tree

20 files changed

+515
-99
lines changed

20 files changed

+515
-99
lines changed

.github/composite/godot-itest/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ runs:
142142
targetArgs="--target $TARGET"
143143
fi
144144
145-
cargo build -p itest ${{ inputs.rust-extra-args }} $targetArgs
145+
cargo build -p itest --no-default-features ${{ inputs.rust-extra-args }} $targetArgs
146146
147147
# Instead of modifying .gdextension, rename the output directory
148148
if [[ -n "$TARGET" ]]; then

.github/workflows/full-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,15 @@ jobs:
310310
os: ubuntu-20.04
311311
artifact-name: linux-nightly
312312
godot-binary: godot.linuxbsd.editor.dev.x86_64
313-
rust-extra-args: --features godot/__codegen-full
313+
rust-extra-args: --features itest/codegen-full
314314
with-hot-reload: true
315315

316316
# Combines now a lot of features, but should be OK. lazy-function-tables doesn't work with experimental-threads.
317317
- name: linux-double-lazy
318318
os: ubuntu-20.04
319319
artifact-name: linux-double-nightly
320320
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
321-
rust-extra-args: --features godot/api-custom,godot/double-precision,godot/__codegen-full,godot/lazy-function-tables
321+
rust-extra-args: --features godot/api-custom,godot/double-precision,itest/codegen-full,godot/lazy-function-tables
322322

323323
- name: linux-features-experimental
324324
os: ubuntu-20.04

.github/workflows/minimal-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ jobs:
157157
os: ubuntu-20.04
158158
artifact-name: linux-nightly
159159
godot-binary: godot.linuxbsd.editor.dev.x86_64
160-
rust-extra-args: --features godot/__codegen-full
160+
rust-extra-args: --features itest/codegen-full
161161
with-hot-reload: true
162162

163163
- name: linux-features-experimental

godot-codegen/src/generator/builtins.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ fn make_builtin_method_definition(
250250
receiver,
251251
varcall_invocation,
252252
ptrcall_invocation,
253+
is_virtual_required: false,
253254
},
254255
safety_doc,
255256
&TokenStream::new(),

godot-codegen/src/generator/classes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ fn make_class_method_definition(
535535
receiver,
536536
varcall_invocation,
537537
ptrcall_invocation,
538+
is_virtual_required: false,
538539
},
539540
None,
540541
cfg_attributes,

godot-codegen/src/generator/functions_common.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct FnCode {
3737
pub receiver: FnReceiver,
3838
pub varcall_invocation: TokenStream,
3939
pub ptrcall_invocation: TokenStream,
40+
pub is_virtual_required: bool,
4041
}
4142

4243
pub struct FnDefinition {
@@ -150,6 +151,11 @@ pub fn make_function_definition(
150151
};
151152

152153
let return_decl = &sig.return_value().decl;
154+
let fn_body = if code.is_virtual_required {
155+
quote! { ; }
156+
} else {
157+
quote! { { unimplemented!() } }
158+
};
153159

154160
let receiver_param = &code.receiver.param;
155161
let primary_function = if sig.is_virtual() {
@@ -160,9 +166,7 @@ pub fn make_function_definition(
160166
#maybe_unsafe fn #primary_fn_name(
161167
#receiver_param
162168
#( #params, )*
163-
) #return_decl {
164-
unimplemented!()
165-
}
169+
) #return_decl #fn_body
166170
}
167171
} else if sig.is_vararg() {
168172
// Varargs (usually varcall, but not necessarily -- utilities use ptrcall)

godot-codegen/src/generator/utility_functions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub(crate) fn make_utility_function_definition(function: &UtilityFunction) -> To
7070
receiver: FnReceiver::global_function(),
7171
varcall_invocation,
7272
ptrcall_invocation,
73+
is_virtual_required: false,
7374
},
7475
None,
7576
&TokenStream::new(),

godot-codegen/src/generator/virtual_traits.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ fn make_virtual_method(method: &ClassMethod) -> Option<TokenStream> {
154154
// make_return() requests following args, but they are not used for virtual methods. We can provide empty streams.
155155
varcall_invocation: TokenStream::new(),
156156
ptrcall_invocation: TokenStream::new(),
157+
is_virtual_required: method.is_virtual_required(),
157158
},
158159
None,
159160
&TokenStream::new(),

godot-codegen/src/models/domain.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ pub struct FunctionCommon {
280280
pub return_value: FnReturn,
281281
pub is_vararg: bool,
282282
pub is_private: bool,
283+
pub is_virtual_required: bool,
283284
pub direction: FnDirection,
284285
}
285286

@@ -314,6 +315,10 @@ pub trait Function: fmt::Display {
314315
fn direction(&self) -> FnDirection {
315316
self.common().direction
316317
}
318+
319+
fn is_virtual_required(&self) -> bool {
320+
self.common().is_virtual_required
321+
}
317322
}
318323

319324
// ----------------------------------------------------------------------------------------------------------------------------------------------

godot-codegen/src/models/domain_mapping.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ impl BuiltinMethod {
358358
return_value: FnReturn::new(&return_value, ctx),
359359
is_vararg: method.is_vararg,
360360
is_private: special_cases::is_method_private(builtin_name, &method.name),
361+
is_virtual_required: false,
361362
direction: FnDirection::Outbound {
362363
hash: method.hash.expect("hash absent for builtin method"),
363364
},
@@ -463,6 +464,10 @@ impl ClassMethod {
463464
return_value: FnReturn::new(&method.return_value, ctx),
464465
is_vararg: method.is_vararg,
465466
is_private,
467+
is_virtual_required: special_cases::is_virtual_method_required(
468+
&class_name.rust_ty.to_string(),
469+
rust_method_name,
470+
),
466471
direction,
467472
},
468473
qualifier,
@@ -511,6 +516,7 @@ impl UtilityFunction {
511516
return_value: FnReturn::new(&return_value, ctx),
512517
is_vararg: function.is_vararg,
513518
is_private: false,
519+
is_virtual_required: false,
514520
direction: FnDirection::Outbound {
515521
hash: function.hash,
516522
},

0 commit comments

Comments
 (0)