Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTA error: assignment to $_ alised to Array says value is immutable instead of suggesting list assignment #2310

Open
zoffixznet opened this issue Sep 22, 2018 · 1 comment
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@zoffixznet
Copy link
Contributor

zoffixznet commented Sep 22, 2018

Feels like a case that should Do The Right Thing.

18:34 | Zoffix | m: my @a = <a b c d f b g e>; $_ = 42 with @a;
-- | -- | --
18:34 | camelia | rakudo-moar b22edce40: OUTPUT: «Cannot assign to an immutable value␤ in block <unit> at <tmp> line 1␤␤»
18:34 | Zoffix | Was kinda expecting it to DWIM and .STORE into that array

This works tho:

18:36 | Zoffix | m: my @a = <a b c d f b g e>; .[] = 42 with @a; dd @a
18:36 | camelia | rakudo-moar b22edce40: OUTPUT: «Array @a = [42]␤»

If fixing this, check how much performance is affected for assigning stuff to $_ in such cases (regardless whether it contains an Array or not). If there's a noticeable impact, we should defer the change until a later time IMO, as assigning to aliased $_ is a very common case, while doing the same when it's an array ain't.

@zoffixznet zoffixznet added the LTA Less Than Awesome; typically an error message that could be better label Sep 22, 2018
@zoffixznet
Copy link
Contributor Author

zoffixznet commented Sep 22, 2018

http://colabti.org/irclogger/irclogger_log/perl6-dev?date=2018-09-22#l134

nm on assignment not working. It's fine and the same is the case in other instances. However, the error is LTA as the user should instead be told to use list assignment:

18:41 | TimToady | in any case, it's not exactly an immutable value, so the error message is LTA
-- | -- | --
18:42 | TimToady | m: my @a = <a b c d f b g e>; @$_ = 42 with @a;
18:42 | camelia | rakudo-moar b22edce40: ( no output )
18:42 | TimToady | in the design, the scalar vs list assignment is determined statically, so maybe the error should just point them at @$_
18:43 | Zoffix | m: use nqp; my @a = <a b c d f b g e>; nqp::p6store($_,42) with @a; dd @a
18:43 | camelia | rakudo-moar b22edce40: OUTPUT: «Array @a = [42]␤»
18:43 | TimToady | we could make it failover, but too many failovers is a design smell
18:43 | Zoffix | It could use that op, no? Tho I feer it'll impact perf
18:44 | TimToady | well, probably only if it prevents inlining
18:44 | Zoffix | m: my $a := [<a b c d f b g e>]; $a = 42; dd $a
18:44 | camelia | rakudo-moar b22edce40: OUTPUT: «Cannot assign to an immutable value␤ in block <unit> at <tmp> line 1␤␤»
18:45 | Zoffix | hm...
18:45 | TimToady | and it's not like the callsite is gonna be megamorphic
18:45 |   | Zoffix decides to leave the boat unrocked and closes the ticket

18:45 | TimToady | well, it's still LTA
-- | -- | --
18:45 |   | Zoffix renames the ticket instead
18:46 | TimToady | we wanna be able to optimize the heck out of scalar assignment, fershure
18:47 | TimToady | but if we've already gotta check for immutability, a further check in the error handling for list-assignability is probably not going to do much more than spread out cache hits from a longer goto
18:48 | TimToady | and perhaps multiple scalar assignments can share the same checking code out-of-line


@zoffixznet zoffixznet changed the title LTA assignment to $_ alised to Array does not .STORE LTA error: assignment to $_ alised to Array says value is immutable instead of suggesting list assignment Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

1 participant