Skip to content

Add new entries to TypeName #371

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

Closed

Conversation

MarkMcCaskey
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey commented Apr 4, 2020

Current progress is:

  • Function code threaded through system but missing important pieces
  • Closure is only partially threaded through
  • Scalar and tuple code on this branch

Part of #368

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

Looks like a good start. But reading through this (and sort of from what I was thinking before), I'm wondering if we're better off keeping these in chalk-rust-ir, instead of chalk-ir. And ApplicationTy.name to be Interner::TypeName. I need to think about this a little bit more.

Comment on lines 194 to +159
pub struct StructId<I: Interner>(pub I::DefId);

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FnDefId<I: Interner>(pub I::DefId);

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ClosureId<I: Interner>(pub I::DefId);
Copy link
Member

Choose a reason for hiding this comment

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

We had previously talked about moving all of these as associated types on Interner. This is making me somewhat think this is a good idea. But maybe not in this PR.

pub struct ClosureDefn {
// What's a closure's name? Need to generate an `Identifier` or something
// TODO(markmccaskey): investigate what rustc does here
pub name: Identifier,
Copy link
Member

Choose a reason for hiding this comment

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

Technically, closures aren't nameable. But I'm not sure if rustc generates a name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, rustc has an internal name. I think giving them a dummy name is a fine thing to do for chalk tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

That said, we'll probably want to (a) consolidate some of this with functions and (b) we may want other things eventually to better match rustc. But we can evolve this part.

Comment on lines 93 to 130
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct FnDefDatumBound<I: Interner> {
pub params: Vec<Ty<I>>,
pub returns: Vec<Ty<I>>,
pub where_clauses: Vec<QuantifiedWhereClause<I>>,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct FnDefFlags {
pub upstream: bool,
pub fundamental: bool,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct FnDefDatum<I: Interner> {
pub binders: Binders<FnDefDatumBound<I>>,
pub id: FnDefId<I>,
pub flags: FnDefFlags,
}

impl<I: Interner> FnDefDatum<I> {
pub fn name(&self, interner: &I) -> TypeName<I> {
self.id.cast(interner)
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct ClosureDatum<I: Interner> {
//pub binders: Binders<StructDatumBound<I>>,
pub id: ClosureId<I>,
}

impl<I: Interner> ClosureDatum<I> {
pub fn name(&self, interner: &I) -> TypeName<I> {
self.id.cast(interner)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Why are these here, but the others are in chalk-ir? Plus there's duplicate structs like FnDefFlags/FnFlags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current implementation is pretty much just a duplication and slight modification of Struct as a starting point. For example, chalk_ast::StructFlags and chalk_rust_ir::StructFlags turned into FnDefFlags and FnFlags. And FnDefDatum is here because StructDatum is also here!

I'm oscillating between thinking I understand the goal and the pieces I'm working with and thinking I don't understand it 😄 . I'll go back to the basics and see if I can get a better understanding of the pieces involved here! The review helped me realize that my working understanding of Field was off base, for example, and perhaps I've missed other important details!

@@ -275,6 +275,172 @@ impl<I: Interner> ToProgramClauses<I> for StructDatum<I> {
}
}

impl<I: Interner> ToProgramClauses<I> for FnDefDatum<I> {
Copy link
Member

Choose a reason for hiding this comment

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

This seems mostly duplicated from StructDatum?

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting stuff! We'll have to think about just which rules we want here...

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

I think we should consider breaking out the scalar changes from the more complex types like fn-def and closure. Scalars are relatively simple, I think, and it'd be nice to review the fn-def and closures separately.

@MarkMcCaskey MarkMcCaskey force-pushed the feature/improve-type-name branch from 1e765c2 to 0430199 Compare April 7, 2020 04:42
@MarkMcCaskey MarkMcCaskey force-pushed the feature/improve-type-name branch from 0430199 to 0fe8a29 Compare April 7, 2020 05:10
@MarkMcCaskey
Copy link
Contributor Author

Thanks for the review! I'm realizing that I've probably gone a bit too far into unknown territory, so I'm going to read through the docs on chalk and think about this some more to try to get a more solid foundation before continuing tomorrow night.

@nikomatsakis
Copy link
Contributor

@MarkMcCaskey perhaps, but actually I thnk the code you wrote is all basically "on target" -- that is, the details of closures/functions might be a bit off, but you've got basically the right pieces in basically the right places :)

@MarkMcCaskey
Copy link
Contributor Author

I added basic parsing for (empty) function definitions so we can have tests for this.

I noticed in the tests there's code like,

            impl<T> Print for OnlySized<T> {
                // fn print() {
                //     println!("{}", std::mem::size_of::<T>());
                // }
            }

Is it in the scope of this PR to make this work?

@nikomatsakis
Copy link
Contributor

@MarkMcCaskey definitely not =)

@nikomatsakis
Copy link
Contributor

Closing in favor of #394 -- let's revisit this stuff once that one lands.

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.

4 participants