-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Union types: deduplication + Nothing type members absorption #16312
Draft
mucciolo
wants to merge
13
commits into
scala:main
Choose a base branch
from
mucciolo:deduplicate-union-types-#10693
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+145
−3
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2b6cb1f
Union types: deduplication + Nothing type members absorption
mucciolo b5ce897
Applied review comments
mucciolo 2fa6ddc
Inlined Type.isOrType
mucciolo 28f855d
Added EqLinkedHashSet, an identity-based linked hash set
mucciolo a555606
Optimized Types.gatherTreeUniqueMembersAbsorbingNothingTypes
mucciolo 655dc31
Reverted i11694 and i14823a
mucciolo 588ee18
Cleanup
mucciolo 896e92e
updated EqLinkedHashSet.clear signature
mucciolo 5974ca2
deduplicatedAbsorbingNothingTypes checkpoint
mucciolo dbeb5b7
boiled down test to issue code only
mucciolo 3335e61
deduplicating inferred val def types
mucciolo f540c3d
updated i10693.check
mucciolo 437150c
commenting prints
mucciolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dotty.tools.dotc.util | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
class EqLinkedHashSet[T]( | ||
initialCapacity: Int = 8, capacityMultiple: Int = 2 | ||
) extends MutableSet[T] { | ||
|
||
private val map: MutableMap[T, Unit] = new EqHashMap(initialCapacity, capacityMultiple) | ||
private val linkingArray: ArrayBuffer[T] = new ArrayBuffer(initialCapacity) | ||
|
||
override def +=(x: T): Unit = | ||
map.update(x, ()) | ||
if map.size != linkingArray.size then linkingArray += x | ||
|
||
override def put(x: T): T = | ||
this += x | ||
x | ||
|
||
override def -=(x: T): Unit = | ||
map -= x | ||
if map.size != linkingArray.size then linkingArray -= x | ||
|
||
override def clear(resetToInitial: Boolean = true): Unit = | ||
map.clear(resetToInitial) | ||
linkingArray.clear() | ||
|
||
override def lookup(x: T): T | Null = if map.contains(x) then x else null | ||
|
||
override def size: Int = map.size | ||
|
||
override def iterator: Iterator[T] = linkingArray.iterator | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[[syntax trees at end of typer]] // local/i10693.scala | ||
package <empty> { | ||
final lazy module val i10693$package: i10693$package = new i10693$package() | ||
final module class i10693$package() extends Object() { | ||
this: i10693$package.type => | ||
def test[A >: Nothing <: Any, B >: Nothing <: Any](a: A, b: B): A | B = a | ||
val v0: String | Int = test[String, Int]("string", 1) | ||
val v1: Int | String = test[Int, String](1, "string") | ||
val v2: String | Int = test[String | Int, Int | String](v0, v1) | ||
val v3: Int | String = test[Int | String, String | Int](v1, v0) | ||
val v4: String | Int = | ||
test[String | Int | (Int | String), Int | String | (String | Int)](v2, v3) | ||
val v5: Int | String = | ||
test[Int | String | (String | Int), String | Int | (Int | String)](v3, v2) | ||
val v6: String | Int = | ||
test[String | Int | (Int | String) | (Int | String | (String | Int)), | ||
Int | String | (String | Int) | (String | Int | (Int | String))](v4, v5) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def test[A, B](a: A, b: B): A | B = a | ||
val v0 = test("string", 1) | ||
val v1 = test(1, "string") | ||
val v2 = test(v0, v1) | ||
val v3 = test(v1, v0) | ||
val v4 = test(v2, v3) | ||
val v5 = test(v3, v2) | ||
val v6 = test(v4, v5) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two problems with this approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️