From 50e66800dc28d67ea1cc88172f459df1ca96507d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 11 Nov 2021 11:24:44 -0800 Subject: DeadArgumentElimination argument subtyping: Add fixups if the param is used (#4319) Before, if we saw a param is written, that prevented us from subtyping it: function foo(x : oldType) { .. x = someValue; .. } Even if all calls to foo send some specific struct type that we'd like to subtype to, seeing that write stopped us. To handle such a write we need to do some extra handling for the case in which it is written a less-specific type (that is, if someValue is of type oldType, something like this: function foo(x : newType) { var x_old : oldType; x_old = x; // copy the param to x_old, and use x_old everywhere .. x_old = someValue; .. } That is, still refine the param type, but inside the function use a new local that has the old type, and is guaranteed to validate. This PR implements that logic so that we can optimize more cases. To allow that, this PR avoids trying to both refine a type and remove a param as being unused - that has annoying corner cases. If it is unused, we can simply remove it anyhow. --- src/support/sorted_vector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/support') diff --git a/src/support/sorted_vector.h b/src/support/sorted_vector.h index 5c1d9a731..234d4da7e 100644 --- a/src/support/sorted_vector.h +++ b/src/support/sorted_vector.h @@ -82,7 +82,7 @@ struct SortedVector : public std::vector { return false; } - bool has(Index x) { + bool has(Index x) const { auto it = std::lower_bound(begin(), end(), x); return it != end() && *it == x; } -- cgit v1.2.3