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

Make ty params non-positional #2364

Closed
catamorphism opened this issue May 7, 2012 · 10 comments
Closed

Make ty params non-positional #2364

catamorphism opened this issue May 7, 2012 · 10 comments
Labels
A-type-system Area: Type system C-cleanup Category: PRs that clean code up or issues documenting cleanup.

Comments

@catamorphism
Copy link
Contributor

@nikomatsakis and I agreed that it would be better to change the ty::substs type to have the tps field be a map from node IDs to types, rather than a vector of types as it is now. This allows ty params to be referred to based on their node IDs rather than positionally as they are now. Among other things, this addresses a bug in the code that I'm trying to isolate in which class ty params get concatenated with method ty params and sometimes a param gets duplicated. Niko said he would do this as a byproduct of rewriting the code for self types.

@ghost ghost assigned nikomatsakis May 7, 2012
catamorphism added a commit that referenced this issue May 7, 2012
Added a test case for #2288. It's xfailed for now, pending #2364
@nikomatsakis
Copy link
Contributor

I had thought to do this as part of #2372. I am debating a somewhat different approach, though, where we have two sets of type parameters (say type/method) and still index positionally? The only real reason to do is performance, though, so I think I will try both ways and do some measurements. Using a id-type mapping would be cleaner.

@pcwalton
Copy link
Contributor

pcwalton commented Jun 1, 2012

Positional type parameters are nice for performance. Possibly best to fix the concatenation issue directly and not move to a map.

@nikomatsakis
Copy link
Contributor

I've kind of stalled on implementing this. I was experimenting with various alternatives but none of them seem to be working out as cleaner overall, so I think I agree with you @pcwalton .

@catamorphism
Copy link
Contributor Author

@nikomatsakis Were you able to do a performance comparison for any of the alternatives?

@nikomatsakis
Copy link
Contributor

No, and I doubt that it's significant. It's more that the code wasn't turning out cleaner; actually the opposite in some cases.

@catamorphism
Copy link
Contributor Author

Well, I just meant that if performance was the same, that would be a case for continuing to think about it. If performance was a lot worse with your changes, then I would be inclined to agree with you and Patrick. But I still think positional ty params are really error-prone... I'd at least want to know what percentage of compile time type substitution takes before going along with "keep it this way for good performance".

@nikomatsakis
Copy link
Contributor

I don't know. @pcwalton could be right that perf is bad, I never got far enough that things built. I just felt like I was making a lot of changes but it wasn't that things were getting simpler---and sometimes they felt more complex. Feel free to pursue it on your own if you like, I'm just not interested in making this change anymore. :)

@graydon
Copy link
Contributor

graydon commented Jul 4, 2012

Surely a class' methods can't be parameterized independently of the class itself, can they? That was something we tried to avoid in the design, I thought..

In any case, deferring this to 0.4. Doesn't sound urgent.

@nikomatsakis
Copy link
Contributor

@graydon I am not sure what you mean. Currently, both classes and methods can have type parameters. I was initially opposed to this but it turns out to be extremely useful.... (you can't implement something like map() as a method without it, for example)

@catamorphism
Copy link
Contributor Author

I'm feeling pretty apathetic about this.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
… also include ZSTs (rust-lang#2794)

This change considers another case for the code generation of scalar data.
In particular, when the expected type is an ADT, we previously
considered two cases: either there is no field or there is one. But in
cases where the ADT includes a ZST, the ADT will contain multiple
fields: one associated to the scalar data, and other fields associated
to the ZSTs. In those cases, we ended up crashing as in rust-lang#2680:

```rust
error: internal compiler error: Kani unexpectedly panicked at panicked at cprover_bindings/src/goto_program/expr.rs:804:9:
                                assertion failed: `(left == right)`
                                  left: `2`,
                                 right: `1`: Error in struct_expr; mismatch in number of fields and values.
                                    StructTag("tag-_161424092592971241517604180463813633314")
                                    [Expr { value: IntConstant(0), typ: Unsignedbv { width: 8 }, location: None, size_of_annotation: None }].

thread 'rustc' panicked at cprover_bindings/src/goto_program/expr.rs:804:9:
assertion failed: `(left == right)`
  left: `2`,
 right: `1`: Error in struct_expr; mismatch in number of fields and values.
	StructTag("tag-_161424092592971241517604180463813633314")
	[Expr { value: IntConstant(0), typ: Unsignedbv { width: 8 }, location: None, size_of_annotation: None }]
```

With the changes in this PR, that's no longer the case.

Resolves rust-lang#2364 
Resolves rust-lang#2680
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

No branches or pull requests

4 participants