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

Rename struct types to ADT types and introduce new interned ADT ID #454

Merged
merged 2 commits into from
May 18, 2020
Merged

Rename struct types to ADT types and introduce new interned ADT ID #454

merged 2 commits into from
May 18, 2020

Conversation

AzureMarker
Copy link
Member

Closes #453

The only functional changes are due to the introduction of the ADT ID, and they are minimal.

Comment on lines +147 to +148
/// TODO: Currently only handles structs, may need more work for enums & unions
pub fn verify_adt_decl(&self, adt_id: AdtId<I>) -> Result<(), WfError<I>> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this function generalizes to all ADTs in its current form, so I flagged it with this TODO.

type DefId: Debug + Copy + Eq + Ord + Hash;

/// The ID type for ADTs
type InternedAdtId: Debug + Copy + Eq + Ord + Hash;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I'm not actually sure why we need this. @nikomatsakis on your issue, you said that for rustc this would be &'tcx AtdDef. But we can access that with tcx.adt_def(DefId). So...I'm not really sure why Adts need their own special id.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that, eventually, we want rustc's types to be equal to chalk's types. We could potentially convert rustc to use a DefId and not a &'tcx AdtDef, and I considered that, but it would mean doing a query every time we want to access field information, so it might imply extra overhead.

To be honest, I suspect that we may want to take this same approach for all ids, to give Interner implementations more flexibility in how they manage their ids, but it seems ok to start here.

We could always remove it later if converting rustc to use DefId is better, or we could go further, or leave it as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I can understand the sentiment towards wanting to not have to query every time we want to access field information. But I don't think we should do that here, for a couple reasons:

  1. It's different than what we do for everything else (right now). I would rather things be consistent than trying to optimize for less overhead. (This is, in part, because we don't exactly know how much overhead there would be. And everything else isn't optimized at all.)
  2. I think this is possibly just wrong. If we want to store the AdtDef (or any other info for other types), then I think it should be stored in InternedType, not in the equivalent of DefId.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the argument for uniformity, but I don't understand the argument for it being wrong. From the perspective of chalk, it is an id -- an id is just something opaque that we give to the RustIrDatabase in exchange for information.

The only difference here is that we've given the Interner (and RustIrDatabase) more license to decide how to represent ids (as I noted above, I suspect we ought to do this for all ids).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for performance, it's true that we haven't (in rustc) measured the impact of replacing AdtDef with a DefId. It's also true that when we added AdtDef (instead of def_id), it was a noticeable win. But the compiler was a very different beast back then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll concede.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, to be clear, I do think you have a point about performance and uniformity. And I resisted suggesting we introduce this indirection for some time because I wanted to try converting rustc to use a DefId instead for precisely this reason. And I still sort of do. But I also think we can do that work independently by adding the indirection, which is why I wound up suggesting it.

@nikomatsakis nikomatsakis merged commit 03c7f3d into rust-lang:master May 18, 2020
@AzureMarker AzureMarker deleted the tweak/generalize-struct-type branch May 18, 2020 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

generalize the builtin struct type to adt to match rustc
3 participants