forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Lastuse proofread #1
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
guillaumecarraux
wants to merge
2
commits into
main
Choose a base branch
from
lastuse
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,21 @@ import NameKinds.WildcardParamName | |
| import cc.* | ||
| import dotty.tools.dotc.transform.MacroAnnotations.hasMacroAnnotation | ||
| import dotty.tools.dotc.core.NameKinds.DefaultGetterName | ||
| import dotty.tools.dotc.util.Property.{Key, StickyKey} | ||
| import dotty.tools.dotc.transform.PostTyper.enclosingMethod | ||
| import dotty.tools.dotc.transform.PostTyper.methodLastUses | ||
|
|
||
| object PostTyper { | ||
| val name: String = "posttyper" | ||
| val description: String = "additional checks and cleanups after type checking" | ||
|
|
||
| val lastUseAttachment = StickyKey[Unit] | ||
|
|
||
| val enclosingMethod = Key[DefDef[?]] | ||
|
|
||
| /** Attachment on a Method that stores local variables annotated with @lastUse */ | ||
| val methodLastUses = StickyKey[Set[Symbol]] | ||
|
|
||
| } | ||
|
|
||
| /** A macro transform that runs immediately after typer and that performs the following functions: | ||
|
|
@@ -56,6 +67,8 @@ object PostTyper { | |
| * (11) Minimizes `call` fields of `Inlined` nodes to just point to the toplevel | ||
| * class from which code was inlined. | ||
| * | ||
| * (12) Replaces @lastUse annotation with an attachment, so it survives the erasure phase. | ||
| * | ||
| * The reason for making this a macro transform is that some functions (in particular | ||
| * super and protected accessors and instantiation checks) are naturally top-down and | ||
| * don't lend themselves to the bottom-up approach of a mini phase. The other two functions | ||
|
|
@@ -479,13 +492,14 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => | |
| val tree1 = cpy.ValDef(tree)(tpt = makeOverrideTypeDeclared(tree.symbol, tree.tpt)) | ||
| if tree1.removeAttachment(desugar.UntupledParam).isDefined then | ||
| checkStableSelection(tree.rhs) | ||
|
|
||
| processValOrDefDef(super.transform(tree1)) | ||
| case tree: DefDef => | ||
| registerIfHasMacroAnnotations(tree) | ||
| Checking.checkPolyFunctionType(tree.tpt) | ||
| annotateContextResults(tree) | ||
| val tree1 = cpy.DefDef(tree)(tpt = makeOverrideTypeDeclared(tree.symbol, tree.tpt)) | ||
| processValOrDefDef(superAcc.wrapDefDef(tree1)(super.transform(tree1).asInstanceOf[DefDef])) | ||
| processValOrDefDef(superAcc.wrapDefDef(tree1)(super.transform(tree1)(using ctx.withProperty(enclosingMethod, Some(tree1))).asInstanceOf[DefDef]))//I dont think I need a stickykey since i will never copy the defdef itself when managing its components right ? AND I dont need it in the next phases | ||
| case tree: TypeDef => | ||
| registerIfHasMacroAnnotations(tree) | ||
| val sym = tree.symbol | ||
|
|
@@ -569,6 +583,19 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase => | |
| case tree: TypeTree => | ||
| val tpe = if tree.isInferred then CleanupRetains()(tree.tpe) else tree.tpe | ||
| tree.withType(transformAnnotsIn(tpe)) | ||
| case Typed(t, tpt: TypeTree) if tpt.tpe.hasAnnotation(defn.LastUseAnnot) => | ||
| t match | ||
| case _: Ident => | ||
| t.putAttachment(PostTyper.lastUseAttachment, ()) | ||
| val enclosing = ctx.property(enclosingMethod).get | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: isn't there a way to get the enclosing method without adding a property to the context? There should be an |
||
| val others = enclosing.getAttachment(methodLastUses).getOrElse(Set.empty) | ||
| //attach the symbol to the method | ||
| enclosing.putAttachment(methodLastUses, others + t.symbol) | ||
| Typed(t, tpt) | ||
| case _ => | ||
| report.error("`@lastUse` annotation can only be applied on local variables", tree.srcPos) | ||
| Typed(t, tpt) | ||
|
|
||
| case Typed(Ident(nme.WILDCARD), _) => | ||
| withMode(Mode.Pattern)(super.transform(tree)) | ||
| // The added mode signals that bounds in a pattern need not | ||
|
|
||
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.
nit: You should usually add new phases at the end of the mega phase list