Skip to content

Change default params representation #8637

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 8 commits into from
Apr 3, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 30, 2020

Now: Have a flag HasDefault on each parameter symbol that has a default argument, instead of the flag DefaultParameterized on method symbols that we had before. To make this work, we need to retain a way for methods to refer to their parameter symbols.

The new scheme makes it easier to find default arguments, and corresponds to what Scala-2 does.

We should update Tasty reflect to match the new functionality.

odersky added 7 commits March 29, 2020 17:33
Store the parameter symbols of a method in a `paramss`
field of the method symbol.

Parameter symbols are kept up-to-date until erasure.
Add a method `paramSymss` that mirrors the type structure of a method.
Rename the old `paramss` to `rawParamss` to caution against naive uses.
Also, add a nestedZipWithConserve method
Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Add" instead of "Added")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

@odersky odersky changed the title Change default params Change default params representation Mar 30, 2020
final def setParamssFromDefs(tparams: List[TypeDef[?]], vparamss: List[List[ValDef[?]]])(using Context): Unit =
setParamss(tparams.map(_.symbol), vparamss.map(_.map(_.symbol)))

/** A pair consistsing of type paremeter symbols and value parameter symbol lists
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolasstucki The paramSymss method should be exported through Tasty reflect.

Copy link
Contributor

Choose a reason for hiding this comment

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

I added paramSymss to the TASTy reflect API

api.ParameterList.of(params.toArray, mt.isImplicitMethod) :: paramLists(restpe, params.length)
assert(paramss.nonEmpty && paramss.head.hasSameLengthAs(pnames),
i"mismatch for $sym, ${sym.info}, ${sym.paramSymss}")
val apiParams = paramss.head.lazyZip(ptypes).map((param, ptype) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smarter I am not sure whether we need the parameter type ptype
in the method type to produce an api type, or whether the type of the
parameter symbol is enough. In the latter case, paramLists can be
much simpler; a simple nestedMap instead of the recursion suffices.

Copy link
Member

Choose a reason for hiding this comment

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

We need the fully parameter type: if any of its part change, that's a possible API change and some code might need to be recompiled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But ptype and the parameter symbol's type are usually isomorphic, right? It's just that one refers to internal parameter symbols and the other to external paramRefs.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, I haven't checked this PR in detail yet so I can't say but I guess it's fine then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know about the fine print though. E.g. does internal vs external representation of varargs matter?

Copy link
Member

Choose a reason for hiding this comment

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

As long as the varargs gets represented by an api type which doesn't match some other non-varargs type it should be fine, both representations should have this propriety but I'll double-check. Are there other situations where the types differ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't think of anything else.

@odersky
Copy link
Contributor Author

odersky commented Apr 3, 2020

@nicolasstucki The Tasty reflect additions look good to me. Can you do a quick review of the rest?

@nicolasstucki nicolasstucki self-requested a review April 3, 2020 13:08
Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

Side question. Do we also need this for type definitions?

@odersky odersky merged commit a5c934a into scala:master Apr 3, 2020
@odersky odersky deleted the change-default-params branch April 3, 2020 22:28
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