-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
change tuple indexing #4186
change tuple indexing #4186
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial feedback. I'll look again once these are addressed.
toolchain/check/member_access.cpp
Outdated
CARBON_DIAGNOSTIC( | ||
TupleWrongIndexSyntax, Error, | ||
"Type `{0}` does not support array indexing. Did you mean tuple.0?", | ||
SemIR::TypeId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add a test that verifies that this diagnostic is being produced correctly. Also, isn't this the opposite case, where you are using tuple indexing on a non-tuple value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, isn't this the opposite case, where you are using tuple indexing on a non-tuple value?
My bad, for some reason I was thinking of tuple[0]
. Should we add a note telling the user the right way to index a tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great, but I wouldn't say it is required.
I think everything should be resolved by now, except the parts wherein I am confused on what to do. |
Also, apologies if I'm unnecessarily pinging you by re-requesting a review even if you said that you'd review this once everything gets resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks really good! Josh had asked me to take a look, and I think the logic looks correct. I did see some spots though where I think it may be helpful to adjust API use, just subtle toolchain things.
// CHECK:STDERR: fail_non_tuple_index.carbon:[[@LINE+3]]:20: ERROR: Type `[i32; 1]` does not support tuple indexing. Only tuples can be indexed that way. | ||
// CHECK:STDERR: var first: i32 = non_tuple.0; | ||
// CHECK:STDERR: ^~~~~~~~~~~ | ||
var first: i32 = non_tuple.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the other tuple indexing tests are under testdata/index
. Might that be a better place for this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't notice that there was a similar test named toolchain/check/testdata/fail_non_tuple_access
. I think I'll just merge this with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had you meant to remove this?
toolchain/parse/testdata/basics/fail_invalid_designators.carbon
Outdated
Show resolved
Hide resolved
As a sidenote (not something I'm requesting for this PR), I'm thinking we may want to split up the This is partly because I feel odd seeing so many files with either |
I'll happily do this in a separate PR, as I do not want to clutter this PR by syncing to trunk (to have #4200). |
On a related note, do you think we should rename tuple index with tuple access across the repo? That would mean renaming a lot of things ( |
Asking for thoughts on discord. Maybe best to split out any rename. |
Per discussion, we'll want to consolidate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the changes! Basically looks good, but I think you might've missed deleting the fail_non_tuple_index.carbon. Since there's fail_non_tuple_access (as you observed), can you delete that and I'll merge?
// CHECK:STDERR: fail_non_tuple_index.carbon:[[@LINE+3]]:20: ERROR: Type `[i32; 1]` does not support tuple indexing. Only tuples can be indexed that way. | ||
// CHECK:STDERR: var first: i32 = non_tuple.0; | ||
// CHECK:STDERR: ^~~~~~~~~~~ | ||
var first: i32 = non_tuple.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had you meant to remove this?
// TIP: To dump output, run: | ||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/tuple/index.carbon | ||
|
||
let tuple: (i32, i32) = (5, 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let tuple: (i32, i32) = (5, 5); |
This is really small (I'm mainly mentioning it because of fail_non_tuple_index.carbon), but I think it's helpful to both emphasize the tuple.0
parse tree, and as a hint that this line isn't needed (name lookup doesn't occur during parse). So the parse tree below ends up a lot shorter, making it easier to see the syntax under test.
Actually, it looks like things have gotten slightly out of date due to a LLVM IR change (#4212 looks like the source of conflicts). I'm happy to have you merge/autoupdate, or I can take care of that (let me know how you'd prefer). |
When forming a specific (previously called a generic instance), evaluate the eval block of the generic to determine the values of any constants used in that specific. The majority of the work here is updating eval.cpp so that it can use the results of prior evaluations in the same block when computing later values. Include the computed results in the formatted SemIR output. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
When evaluating in a generic context, a constant with a symbolic type might evaluate to a constant with a concrete type (or a more specific symbolic type). This can't actually happen yet given the current state of the toolchain, as far as I can determine, so this is more just a refactoring for now, but will be relied upon by future generics work. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
…anguage#4136) The output is really basic, I'm just adding this to help track how memory is allocated. ``` --- filename: 'check/testdata/expr_category/in_place_tuple_init.carbon' source_: used_bytes: 8057 reserved_bytes: 8057 tokens_.allocator_: used_bytes: 0 reserved_bytes: 0 tokens_.token_infos_: used_bytes: 1040 reserved_bytes: 2032 (eliding) value_stores_.string_literals_.set_: used_bytes: 320 reserved_bytes: 320 Total: used_bytes: 20609 reserved_bytes: 29437 ... ``` --------- Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
…arbon-language#4137) Querying a local constant with an invalid instruction triggers a crash, this will prevent self_param_id to be used unless it is defined. Closes carbon-language#4071 and carbon-language#4080 This will only fix the crash. The scenario where a declaration-only interface is imported then defined still gives an error message, but it won't crash this time.
…re them to be fully defined. (carbon-language#4139) When referring to a constant within a specific, such as a field of a generic class, use that specific version of the constant's value.
…nguage#4142) Most of this is enabled by default, but there is some that needs an explicit flag. Avoiding `-Wnon-virtual-dtor` itself for now because that warning can require changes that carry overhead such as having an extra, unused destructor entry in the vtable. Hopefully we don't have too many folks who need our code to be `-Wnon-virtual-dtor` clean.
…-language#4133) This improve the toolchain's performance by about 10%. It will also allow us to leverage TCMalloc's extensions to do heap profiling and get other information about how efficiently we're using the heap. Note that currently this causes all of our builds to produce a warning due to an issue with `rules_python` and multiple modules registering python toolchains: bazelbuild/rules_python#1818 This is also only enabled on Linux as there is no support for other OSes at the moment.
Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
also fix the bug the wherein the diagnostic `TupleIndexOnANonTupleType` was not showing
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
…ail_non_tuple_access.carbon
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
593a2b0
to
91d3545
Compare
I think, I might have messed things up when trying to sync. |
this changes the tuple index from
tuple[0]
totuple.0
in accordance with the accepted propsal #3646