From ed4d22e22414a561e5b5af0064a3a47fc8db1645 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 8 Nov 2021 16:23:09 -0800 Subject: Effects.h: Fix RefAs (#4312) We marked that as only trapping if the input as nullable. But ref.as_func will trap if it isn't a func, for example. We could in theory try to check if a trap is possible, like checking if the input is already non-nullable or already a function, etc., but we have optimization passes to get rid of RefAs when they are not needed anyhow, so there is no point to duplicate that here. --- src/ir/effects.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ir/effects.h b/src/ir/effects.h index f24f0ac3f..ced8e63cb 100644 --- a/src/ir/effects.h +++ b/src/ir/effects.h @@ -725,9 +725,15 @@ private: } void visitRefAs(RefAs* curr) { // traps when the arg is not valid - if (curr->value->type.isNullable()) { - parent.implicitTrap = true; - } + parent.implicitTrap = true; + // Note: We could be more precise here and report the lack of a possible + // trap if the input is non-nullable (and also of the right kind for + // RefAsFunc etc.). However, we have optimization passes that will + // remove a RefAs in such a case (in OptimizeInstructions, and also + // Vacuum in trapsNeverHappen mode), so duplicating that code here would + // only help until the next time those optimizations run. As a tradeoff, + // we keep the code here simpler, but it does mean another optimization + // cycle may be needed in some cases. } }; -- cgit v1.2.3