-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Optimization: Introduce CompactAnnotation #24679
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
Open
odersky
wants to merge
8
commits into
scala:main
Choose a base branch
from
dotty-staging:opt-annots
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.
+280
−204
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
434941a
Optimization: Introduce CompactAnnotation
odersky 910529a
Represent all retains annotations as CompactAnnotations
odersky 7b15169
Special class for RetainingAnnotations
odersky b9e6eb9
Don't detour over tree when going from RetainingAnnotation to capture…
odersky e648b42
Cache result of toCaptureSet in RetainingAnnotation
odersky effba5c
Use more RetainingAnnotation tests where it makes sense
odersky d223e79
Drop RetainingType
odersky 3e8c9cf
Comments and general polishing
odersky 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
49 changes: 49 additions & 0 deletions
49
compiler/src/dotty/tools/dotc/cc/RetainingAnnotation.scala
This file contains hidden or 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,49 @@ | ||
| package dotty.tools | ||
| package dotc | ||
| package cc | ||
|
|
||
| import core.* | ||
| import Types.*, Symbols.*, Contexts.* | ||
| import Annotations.{Annotation, CompactAnnotation, EmptyAnnotation} | ||
| import config.Feature | ||
|
|
||
| /** A class for annotations @retains, @retainsByName and @retainsCap */ | ||
| class RetainingAnnotation(tpe: Type) extends CompactAnnotation(tpe): | ||
|
|
||
| def this(cls: ClassSymbol, args: Type*)(using Context) = this(cls.typeRef.appliedTo(args.toList)) | ||
|
|
||
| /** Sanitize @retains arguments to approximate illegal types that could cause a compilation | ||
| * time blowup before they are dropped ot detected. This means mapping all all skolems | ||
| * (?n: T) to (?n: Any), and mapping all recursive captures that are not on CapSet to `^`. | ||
| * Skolems and capturing types on types other than CapSet are not allowed in a | ||
| * @retains annotation anyway, so the underlying type does not matter as long as it is also | ||
| * illegal. See i24556.scala and i24556a.scala. | ||
| */ | ||
| override protected def sanitize(tp: Type)(using Context): Type = tp match | ||
| case SkolemType(_) => | ||
| SkolemType(defn.AnyType) | ||
| case tp @ AnnotatedType(parent, ann: RetainingAnnotation) | ||
| if parent.typeSymbol != defn.Caps_CapSet && ann.symbol != defn.RetainsCapAnnot => | ||
| AnnotatedType(parent, RetainingAnnotation(defn.RetainsCapAnnot)) | ||
| case tp @ OrType(tp1, tp2) => | ||
| tp.derivedOrType(sanitize(tp1), sanitize(tp2)) | ||
| case _ => | ||
| tp | ||
|
|
||
| override def mapWith(tm: TypeMap)(using Context): Annotation = | ||
| if Feature.ccEnabledSomewhere then mapWithCtd(tm) else EmptyAnnotation | ||
|
|
||
| def isStrict(using Context): Boolean = symbol.isRetains | ||
|
|
||
| def retainedType(using Context): Type = | ||
| if symbol == defn.RetainsCapAnnot then defn.captureRoot.termRef | ||
| else argumentType(0) | ||
|
|
||
| private var myCaptureSet: CaptureSet | Null = null | ||
|
|
||
| def toCaptureSet(using Context): CaptureSet = | ||
| if myCaptureSet == null then | ||
| myCaptureSet = CaptureSet(retainedType.retainedElements*) | ||
| myCaptureSet.nn | ||
|
|
||
| end RetainingAnnotation |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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.
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.
Just wondering, why do we choose to use
mutable.LinkedHashMapnow?