Skip to content

[Sema] Extend callee diagnosis to multiple generics #1319

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

Merged
merged 1 commit into from
Feb 16, 2016

Conversation

gregomni
Copy link
Contributor

Straightforward extension of the previous work here (last pull was #1229) to handle callees with multiple generic parameters. Same type requirements are already handled by the ArchetypeBuilder, and protocol conformance is handled explicitly. This is still bailing on nested archetypes.

Pre-existing tests updated that now give better diagnoses.

@gregomni
Copy link
Contributor Author

@slavapestov Thanks for the last merge! Here's the next update.

SmallVector<Type, 4> &substitutions)
: dc(dc), archetypes(archetypes), substitutions(substitutions) {}
GenericVisitor(DeclContext *dc, TypeSubstitutionMap &archetypesMap)
: dc(dc), archetypesMap(archetypesMap) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you fix the indentation so that : is moved over by 2 or 4 spaces?

@slavapestov
Copy link
Contributor

It looks like an improvement but I don't quite understand what you're doing with archetypesMap there. Perhaps just a matter of adding more comments?

@gregomni
Copy link
Contributor Author

Did your suggestions on indentation/empty() and tried adding a couple more comments, although I still feel like those could be improved.

Straightforward extension of the previous work here to handle callees
with multiple generic parameters. Same type requirements are already
handled by the ArchetypeBuilder, and protocol conformance is handled
explicitly. This is still bailing on nested archetypes.

Pre-existing tests updated that now give better diagnoses.
@gregomni
Copy link
Contributor Author

Okay, improved comment, squashed/pushed. It wasn't that the replacement archetype should've been matched to the original, it should've been matched to itself, and hopefully the new comment explains adequately why.

@slavapestov
Copy link
Contributor

Ok. As a future improvement, do you think there's any way to express this without destructuring SubstitutedType? I'm wondering if instead CSDiag should be passing some more information down from the ApplyExpr -- substitutions are already recorded there.

There are only a couple of places left that still look at SubstitutedType and they all feel a bit hacky -- I'd like to rip it out some day.

@gregomni
Copy link
Contributor Author

Yes, I think you could ask the constraint system for all its type variables, and then for each variable, add to the map its archetype (if any) -> its fixed type (if any). And then you wouldn't need the substitution type restructuring at all.

@slavapestov
Copy link
Contributor

archetypes already are "fixed types". You're thinking of type variables?

The constraint system introduces archetypes when a type variable is bound to a generic parameter in a signature. The signature is "opened" and archetypes are constructed to encapsulate the conformances of that generic parameter, as well as any nested associated types.

@gregomni
Copy link
Contributor Author

Sorry, right. Was looking through the TypeVariableType public API and misreading what that did. I guess in order to do away with destructuring the SubstitutionTypes, I'd need to walk through the CS constraints and get bindings - that's essentially the info that I want in the archetypeMap. In any case, the info has to be in the CS, the SubstitutionTypes in parameters passed in here are just a convenient side-effect that I'm talking advantage of, not something that is irreplaceable.

@slavapestov
Copy link
Contributor

@lattner What do you think?

@slavapestov
Copy link
Contributor

@gregomni I think if the current approach passes tests we can merge it anyway since it improves the diagnostics.

But it does seem like you've identified something here that could be generalized and cleaned up, and it would be great if you could investigate it further.

@slavapestov
Copy link
Contributor

@swift-ci Please test

slavapestov added a commit that referenced this pull request Feb 16, 2016
[Sema] Extend callee diagnosis to multiple generics
@slavapestov slavapestov merged commit e0c028d into swiftlang:master Feb 16, 2016
@gregomni gregomni deleted the generic-func-args branch August 18, 2020 23:12
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.

2 participants