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 def generated from givens not synthetic #12979

Merged
merged 10 commits into from
Aug 27, 2021

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 29, 2021

Fixes #12949

@odersky
Copy link
Contributor Author

odersky commented Jun 29, 2021

The problem is how to know whether some method is a structural given instance or
an implicit conversion associated with an implicit class. Previously we characterized
these methods by their Synthetic flag, but that meant that they were not automatically
exported. So we now drop Synthetic and use a flag GivenClass on the class half of
the pair.

The old scheme is still recognized in order to maintain Tasty backwards compatibility.
Tasty forwards compatibility is lost, that's why we need to wait for the next minor release.

A better fix would be to give the synthetic class of a structural given instance a special semantic name.
That would also get rid of the weirdness that the generated class of a given instance like

given foo: C with ...

is visible under the name foo. But that would break backwards Tasty compatibility, so we have to wait
until we can implement that.

@soronpo
Copy link
Contributor

soronpo commented Jun 29, 2021

The old scheme is still recognized in order to maintain Tasty backwards compatibility.
Tasty forwards compatibility is lost, that's why we need to wait for the next minor release.

So this means this PR will be merged only from 3.1?

@odersky
Copy link
Contributor Author

odersky commented Jun 29, 2021

@soronpo Yes, but I think we'll move to 3.1 soon anyway.

@soronpo
Copy link
Contributor

soronpo commented Jun 29, 2021

@soronpo Yes, but I think we'll move to 3.1 soon anyway.

Then I better get to finding more compatibility braking bugs soon 😉

@soronpo
Copy link
Contributor

soronpo commented Jun 29, 2021

@soronpo Yes, but I think we'll move to 3.1 soon anyway.

@odersky
Then I propose creating a warning message for 3.0.x notifying more refined "given with" types are not supported yet, if such structures are used.

@odersky
Copy link
Contributor Author

odersky commented Jun 29, 2021

@soronpo Not sure exactly what the warning should do and who would design and implement it.

@soronpo
Copy link
Contributor

soronpo commented Jun 29, 2021

Not sure exactly what the warning should do

Currently (until 3.1) given ... with ... type T structures are not valid. They exist in the language, but the compiler does not support them fully. This leads to an error that the user needs to figure out, possibly spend several hour minimizing, possibly find this issue, and possibly gets frustrated. Deprecating this feature until 3.1 is the way to go, IMO. I don't mind falling into the pit myself. I know Scala 3 is not yet completely charted territory and I tread lightly. I just want to prevent others from falling into the same pit without even putting a warning sign in front of it.

and who would design and implement it.

I don't mind helping out, but unfortunately currently my table is full. I'm trying my best minimizing and documenting the issues I find as I'm migrating my library to Scala 3.

@odersky
Copy link
Contributor Author

odersky commented Jun 29, 2021

Currently (until 3.1) given ... with ... type T structures are not valid.

That's a bit extremist. What does not work is wildcard exports for them. They are nevertheless widely used, so introducing a blanket warning would be extremely annoying. If someone can find a targeted warning that is clearly not annoying then I am happy to see a PR. But personally i think it will be very difficult to achieve and not worth the effort.

@bishabosha bishabosha added the needs-minor-release This PR cannot be merged until the next minor release label Jun 30, 2021
@@ -809,7 +809,10 @@ object desugar {
Nil
}
}
val classMods = if mods.is(Given) then mods &~ Given | Synthetic else mods
val classMods =
if mods.is(Given) then mods &~ Given | Synthetic | GivenClass
Copy link
Member

Choose a reason for hiding this comment

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

Instead of dropping Given and adding a new GivenClass, what prevents us from keeping Given?

Copy link
Member

@bishabosha bishabosha 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 this can be done without the need for new flags and TASTy changes, unless there is a good reason for the new flag

tests/semanticdb/expect/InventedNames.expect.scala Outdated Show resolved Hide resolved
tests/semanticdb/expect/InventedNames.expect.scala Outdated Show resolved Hide resolved
tests/semanticdb/expect/Classes.expect.scala Outdated Show resolved Hide resolved
@bishabosha
Copy link
Member

bishabosha commented Jul 26, 2021

I think this should not be merged without a minor TASTy bump, it breaks the assumption that a type can not have Given or Implicit flag. Unless we say that implementations should expect any possible flag

@odersky
Copy link
Contributor Author

odersky commented Jul 26, 2021

I think this should not be merged without a minor TASTy bump, it breaks the assumption that a type can not have Given or Implicit flag. Unless we say that implementations should expect any possible flag

I think flags are sufficiently underspecified that we don't need to worry about this. The TreeUnpickler works unchanged for old as well as new version. That should be our test for version bumps. If an old TreeUnpickler works with the new format, we are good.

@smarter
Copy link
Member

smarter commented Jul 26, 2021

If an old TreeUnpickler works with the new format, we are good.

That's good enough for the compiler but not necessarily for macro authors, who might have to adjust their macros if the semantics of tasty change, but anyway it seems that we'll bump to 3.1.0-RC1 (and therefore bump tasty) before the release.

@bishabosha
Copy link
Member

bishabosha commented Jul 26, 2021

At present the Scala 2 TASTy reader scans flags not compatible with Scala 2 to see if it needs to special case certain definitions, (such as Invisible) - so currently it explicitly checks for certain "redundant" flags it can safely ignore, such as Opaque on a class. So if a definition suddenly had a new flag that is not known to be safe to ignore, then the user will get a formatted error. Perhaps this approach was wrong.

TLDR: this will break Scala 2 TASTy reader for previously accepted code

@odersky
Copy link
Contributor Author

odersky commented Jul 27, 2021

OK, we have this under next minor release anyway.

@Kordyjan Kordyjan removed their request for review August 16, 2021 09:48
@bishabosha
Copy link
Member

this needs a rebase

@odersky
Copy link
Contributor Author

odersky commented Aug 23, 2021

@bishabosha Can you check that the semanticdb expect files are now correct? Thanks!

@bishabosha bishabosha assigned bishabosha and unassigned odersky Aug 23, 2021
don't add definition occurences for given instance parameters
@bishabosha bishabosha assigned odersky and unassigned bishabosha Aug 23, 2021
@bishabosha
Copy link
Member

bishabosha commented Aug 23, 2021

@odersky please may you check the addition I made, (I added a test for a symbol being a structural given instance method)

otherwise I think the semanticdb changes are good

@bishabosha bishabosha dismissed their stale review August 23, 2021 12:30

We will not explore the alternative proposed in this review

@odersky odersky assigned bishabosha and unassigned odersky Aug 23, 2021
@dwijnand dwijnand marked this pull request as draft August 23, 2021 13:45
@bishabosha bishabosha marked this pull request as ready for review August 25, 2021 12:25
@bishabosha
Copy link
Member

@odersky I have updated so that in semanticdb the type parameter in the structural given is recorded as belonging to the summoner method

@bishabosha
Copy link
Member

bishabosha commented Aug 27, 2021

So to summarise the point about the semanticdb changes:
We will go with showing a definition occurrence for the type parameter of the class in structural givens, as this gives the most consistent way to rename the type parameter with an IDE

@dwijnand
Copy link
Member

@dos65 are you able to finish reviewing this today?

Copy link
Contributor

@dos65 dos65 left a comment

Choose a reason for hiding this comment

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

@dwijnand @bishabosha

Now, It looks good from my side.
I haven't dived in code details, only checked how it affects semanticdb output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-minor-release This PR cannot be merged until the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export is missing more refined "given with" instances
8 participants