

Fix ICE for functions with more than 65535 arguments by Noble-Mushtak · Pull Req...
source link: https://github.com/rust-lang/rust/pull/88733
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

New issue
Fix ICE for functions with more than 65535 arguments #88733
Conversation
This pull request fixes #88577 by changing the param_idx
field in the Param
variant of WellFormedLoc
from u16
to u32
, thus allowing for more than 65,535 arguments in a function. Note that I also added a regression test, but needed to add // ignore-tidy-filelength
because the test is more than 8000 lines long.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon.
Please see the contribution instructions for more information.
While on one hand this fixes the stated issue in sense, it would be nice if the compiler could recognize when a function overflowed the maximum number of parameters, so it would never ICE even on [insert arbitrarily large number here]
That makes sense. The error in the issue comes from trying to convert a usize
with value 65536 to a u16
, so if we wanted to, we could use usize
instead of u32
for parameter indices. Then we wouldn't need to do .try_into().unwrap()
to convert the usize
to a u32
, which would get rid of the possibility of this panic entirely. I used u32
instead of usize
in my pull request because I was not sure if the memory used by a 32-bit integer vs a 64-bit integer was a concern in this part of the compiler.
See this comment
for a more reasonably sized test case. In order to avoid unnecessary deleted big files in git, I'd suggest you also do a rebase / amend and force-push in order to remove your huge test file.
.. it would be nice if the compiler could recognize when a function overflowed the maximum number of parameters, so it would never ICE even on [insert arbitrarily large number here]
Good idea, but changing parameter index type to type which range will not be used in 99,99..% of real cases isn't looking good.
C++ have limit about ~256 (+-, different values in different compilers).
What's the point of having so many arguments?
I would prefer to go with @CraftSpider's approach: catch an overflowing number of args earlier in the process, emit an error and recover (by maybe clamping the param_idx
to u16::MAX
), although in this case I think it is reasonable to use an unrecoverable error (you need to call FatalError.raise()
, I think), as this will be an incredibly uncommon case and making people change their approach and not give them later errors seems reasonable (to avoid complicating later stages: you'd have to account for the return type when reducing the number, everywhere that deals with arg counts or arg type checking would need to know about this, etc.).
I would prefer to go with @CraftSpider's approach: catch an overflowing number of args earlier in the process, emit an error and recover (by maybe clamping the
param_idx
tou16::MAX
)
If so, should I change param_idx
back to u16
, and then throw an error in check_fn_or_method
if there are more than 65535 arguments? (check_fn_or_method
is the place where the ICE from the issue occurred, since that is where the usize
is being converted to a u16
.) My concern about this approach is it means functions with more than 65535 arguments which compile without error in the current stable version of Rust (1.54.0) will now result in a compiler error. However, since functions with this many arguments are impractical anyways, maybe breaking old Rust code with functions with that many arguments is fine.
@rustbot label: +T-lang
I would change it back, yes. We can do a crater run to check if any open source project has code exploiting this and I would expect that the only change would be that what was formerly an ICE would be a proper error and no other difference in user visible behavior for valid code.
changed the title Use u32 instead of u16 for parameter indices
Fix ICE for functions with more than 65535 arguments
@bors r+
Commit 804ccfa has been approved by
estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
No reviews
None yet
Successfully merging this pull request may close these issues.
Recommend
-
75
README.md vac-hooks Hook WinAPI functions used by Valve Anti-Cheat. Log calls and intercept arguments & return values. DLL written in C.
-
5
Rendering data structures passed to functions as arguments26-Jan-2010: Rendering data structures passed to functions as arguments First fact: Oracle RDBMS use its own memory manager. There're a lot of functions on several la...
-
4
Can virtual functions have default arguments? January 27, 2021 Yes, they can, but you should not rely on them, as you might not get what you’d expect. If you wonder how this topic came up, the an...
-
9
Values, Functions and Objects as Arguments By Ryan Palmer Posted: January 15, 2021 Categorised:
-
2
Using Python Optional Arguments When Defining Functions – Real PythonCreating Functions in Python for Reusing Code You can think of a function as a mini-program that runs within another program or within another function. The main pr...
-
7
Arrow functions don’t have access to the arguments object as regular functions While with a normal function you can use the arguments implicit object to see the given params: function myFunction() { conso...
-
6
Java 中 String 字符串可以有多长?65535? 发表于...
-
4
Upgrading One of My Functions to Use an arguments Block and String Arrays » Stuart’s MATLAB Videos I’ve upgraded a function that I often use with some features introduced in recent releases of MATLAB. This includes an argume...
-
3
Defining Python Functions With Optional Arguments Defining your own functions is an essential skill for writing clean and effective code. In this tutorial, you’ll explore the techniques you have available for defining Python functio...
-
5
Copy link Member ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK