Skip to content

Commit b1a01d8

Browse files
committed
More consteval fixes
1 parent 6d75002 commit b1a01d8

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/compiler.pr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9559,10 +9559,12 @@ export def predeclare_functions(module: &toolchain::Module) {
95599559
}
95609560
}
95619561

9562-
def generate_vtable_function(function: &Function, fdef: typechecking::FunctionDef, state: &State) {
9562+
export def generate_vtable_function(function: &Function, fdef: typechecking::FunctionDef, state: &State) {
95639563
let ftpe = fdef.to_type().resolve()
95649564
let first_param = ftpe.parameter_t(0).tpe
95659565

9566+
debug::trace("Generating vtable function for ", fdef.name)
9567+
95669568
function.block = make_block()
95679569
function.forward_declare = false
95689570
let previous_block = state.current_block

src/consteval.pr

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,16 @@ export def compile_queued_functions {
878878

879879
for var fdef in @function_queue.keys() {
880880
let entry = function_queue(fdef)
881+
882+
if not entry.node {
883+
// Create dyn dispatch
884+
let function = compiler::predeclare_function(fdef, const_module)
885+
compiler::generate_vtable_function(function, fdef, compiler_state)
886+
const_module.result.functions(function.name) = function
887+
continue
888+
}
889+
890+
// Compile function
881891
let function = compiler::create_function(entry.node, fdef, entry.node.value.def_.body, entry.node.inner_scope, null, compiler_state, params = entry.node.value.def_.params)
882892

883893
if function and function.defer_functions {
@@ -915,11 +925,9 @@ export def compile_function(value: &scope::Value, context: &scope::Scope, argume
915925
var node = value.node
916926
var module = value.module
917927

918-
if not node {
919-
// Sneak in a call here so that it gets triggered for functions that don't have a node (i.e generated functions)
920-
compiler::create_dyn_dispatch(module.dyn_dispatch_consteval, module.compiler_state)
921-
922-
return value
928+
if not node {
929+
queue_function(null, value.fdef)
930+
return value
923931
}
924932

925933
/*var is_repurposed = false // When There's no node and we find a new function we don't need to typecheck anymore
@@ -988,7 +996,6 @@ export def compile_function(value: &scope::Value, context: &scope::Scope, argume
988996

989997
//print("Creating function ", function.name, "\n")
990998

991-
// This is a bit ugly but what can we do
992999
queue_function(node, function.fdef)
9931000

9941001
compiler::create_dyn_dispatch(state.module.dyn_dispatch_consteval, state.module.compiler_state)

src/scope.pr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,10 @@ export def trigger_impl(scope: &Scope, tpe: &typechecking::Type) {
21992199
if fun.fdef.return_t.length != member.return_t.length {
22002200
res = false
22012201
} else {
2202+
if consteval::is_static {
2203+
consteval::compile_function(fun, scope)
2204+
}
2205+
22022206
let ftpe = fun.fdef.to_type().resolve()
22032207
if not ftpe {
22042208
print_fdef(fun.fdef)
@@ -2241,7 +2245,7 @@ export def trigger_impl(scope: &Scope, tpe: &typechecking::Type) {
22412245
}
22422246
right.implementors(tpe.id) = functions
22432247

2244-
//print(tpe !*, " ", debug::type_to_str(tpe), " ", tpe.id, " implements ", debug::type_to_str(right), "\n")
2248+
debug::trace("trigger_impl: ", debug::type_to_str(tpe), " implements ", debug::type_to_str(right))
22452249
tpe.implements.add(right.id)
22462250
}
22472251
}

0 commit comments

Comments
 (0)