-
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
Implement phantom types part 1 #2136
Merged
odersky
merged 32 commits into
scala:master
from
dotty-staging:implement-phantom-types-part-1
May 8, 2017
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f067b8e
Rename old PhantomClasses to avoid name clashes with phantom types.
nicolasstucki ac57124
Implement phantom types.
nicolasstucki 84931e3
Extra tests for Phantoms 1.
nicolasstucki a23ef92
Extra tests for Phantoms 2.
nicolasstucki 7ccdbf3
Quick cleanup
nicolasstucki 01063d3
Optimizations
nicolasstucki 5fb733c
Remove unecessary code
nicolasstucki e8590f6
Add restriction on phantom latice definition.
nicolasstucki 621a67b
Fixes after rebase.
nicolasstucki ee44731
Replace phantomTop by general top type.
nicolasstucki 0f4f863
Fix error on if/match with phantoms of different lattices.
nicolasstucki efae3a3
Inline error messages.
nicolasstucki 510c0cb
Fix phantom Nothing.
nicolasstucki f782288
Fix cyclic computation of topType.
nicolasstucki 341cdf1
Move phantom universe checks from Typer to TypeAssigner.
nicolasstucki a50328f
Remove PhantomTypeErasure and integrate into Erasure.
nicolasstucki 9502cb2
Slighly faster phantom erasure checks.
nicolasstucki 6f03972
Simplify the definition of Phantom.assume.
nicolasstucki 621610f
Cache PhantomNothing, PhantomAny and PhantomAssume symbols.
nicolasstucki ef62884
Shortcircuit slow path typing Nothing <:< XYZ for non phantoms.
nicolasstucki 49e88fe
Faster bottomType and phantomness checks.
nicolasstucki e062df3
Improve names of phantom classes in defn.
nicolasstucki 3ff903e
Remove unnecessary changes.
nicolasstucki f0383fe
Remove ErasedPhantom class and use Unit.
nicolasstucki 91558c3
Set flags of scala.Phantom to be NoInitsTrait.
nicolasstucki ec13270
Rename Phantoms in defn and add Type.isPhantom.
nicolasstucki 62b7732
Add documentation.
nicolasstucki 4202b98
Fix neg/cycles.scala infinite loop on phantomLatticeType.
nicolasstucki c6fe778
Code cleanup.
nicolasstucki 07c02c8
Fix after rebase, if/match missmatch on phantoms.
nicolasstucki 40ab53a
Polishings of Typer and TypeAssigner
odersky a21404a
Remove unused error messages.
nicolasstucki 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,28 @@ | ||
package dotty.tools.dotc.core | ||
|
||
import dotty.tools.dotc.ast.tpd._ | ||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.core.Symbols.defn | ||
import dotty.tools.dotc.core.Types.Type | ||
|
||
/** Phantom erasure erases (minimal erasure): | ||
* | ||
* - Parameters/arguments are erased to BoxedUnit. The next step will remove the parameters | ||
* from the method definitions and calls (implemented in branch implement-phantom-types-part-2). | ||
* - Definitions of `def`, `val`, `lazy val` and `var` returning a phantom type to return a BoxedUnit. The next step | ||
* is to erase the fields for phantom types (implemented in branch implement-phantom-types-part-3) | ||
* - Calls to Phantom.assume become calls to BoxedUnit. Intended to be optimized away by local optimizations. | ||
* | ||
* BoxedUnit is used as it fits perfectly and homogeneously in all locations where phantoms can be found. | ||
* Additionally some of the optimizations that can be performed on phantom types can also be directly implemented | ||
* on all boxed units. | ||
*/ | ||
object PhantomErasure { | ||
|
||
/** Returns the default erased type of a phantom type */ | ||
def erasedPhantomType(implicit ctx: Context): Type = defn.BoxedUnitType | ||
|
||
/** Returns the default erased tree for a call to Phantom.assume */ | ||
def erasedAssume(implicit ctx: Context): Tree = ref(defn.BoxedUnit_UNIT) | ||
|
||
} |
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
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
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
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
Oops, something went wrong.
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.
Could be:
topType.prefix.select(tpnme.Nothing)
or something close.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.
It could. The advantage of this version is that computing a bottom type that would result in
scala.Nothing
is more efficient.