-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[Header Mode] Elide property initializers #5572
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
aviroop-123
wants to merge
5
commits into
JetBrains:master
Choose a base branch
from
aviroop-123:header-compilation-property-initializer
base: master
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.
+104
−17
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4890cd4
[Header mode] Elide property initializer with explicit return types.
aviroop-123 4f0fb2e
[Header mode] Elide property initializer after implicit types are res…
aviroop-123 a3ba76d
[Header mode] Skip eliding const property initializers.
aviroop-123 72fa3c0
[Header mode] Skip eliding properties with anonymous object initializ…
aviroop-123 f66186c
[Header mode] Elide expression functions in Lt2Fir.
aviroop-123 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
40 changes: 38 additions & 2 deletions
40
compiler/fir/analysis-tests/testData/resolve/headerMode/propertyDeclaration.fir.txt
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 |
|---|---|---|
| @@ -1,8 +1,44 @@ | ||
| FILE: propertyDeclaration.kt | ||
| public final val a: R|kotlin/String| = String(A) | ||
| public final val a: R|kotlin/String| | ||
| public get(): R|kotlin/String| | ||
| public final val b: R|kotlin/String| = String(B) | ||
| public final val b: R|kotlin/String| | ||
| public get(): R|kotlin/String| | ||
| public final fun foo(): R|kotlin/String| | ||
| public final val c: R|kotlin/String| | ||
| public get(): R|kotlin/String| | ||
| public final val d: R|kotlin/Boolean| | ||
| public get(): R|kotlin/Boolean| | ||
| public final val e: R|kotlin/String| | ||
| public get(): R|kotlin/String| | ||
| public final var f: R|kotlin/Int| | ||
| public get(): R|kotlin/Int| | ||
| public set(value: R|kotlin/Int|): R|kotlin/Unit| | ||
| public final val g: R|kotlin/Int| | ||
| public get(): R|kotlin/Int| | ||
| public final val h: R|kotlin/String|by R|kotlin/lazy|<R|kotlin/String|>(<L> = lazy@fun <anonymous>(): R|kotlin/String| <inline=NoInline> { | ||
| ^ String(H) | ||
| } | ||
| ) | ||
| public get(): R|kotlin/String| | ||
| public final const val i: R|kotlin/Int| = Int(123) | ||
| public get(): R|kotlin/Int| | ||
| public final val j: R|kotlin/Any| = object : R|kotlin/Any| { | ||
| private constructor(): R|<anonymous>| { | ||
| super<R|kotlin/Any|>() | ||
| } | ||
|
|
||
| public final fun foo(): R|kotlin/String| { | ||
| ^foo String(foo) | ||
| } | ||
|
|
||
| public final fun bar(): R|kotlin/String| { | ||
| ^bar String(bar) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public get(): R|kotlin/Any| | ||
| public final val k: R|(kotlin/String) -> kotlin/String| | ||
| public get(): R|(kotlin/String) -> kotlin/String| | ||
| public final val l: R|(kotlin/String) -> kotlin/String| | ||
| public get(): R|(kotlin/String) -> kotlin/String| |
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 |
|---|---|---|
|
|
@@ -178,6 +178,11 @@ open class FirDeclarationsResolveTransformer( | |
|
|
||
| val cannotHaveDeepImplicitTypeRefs = property.backingField?.returnTypeRef !is FirImplicitTypeRef | ||
| if (!property.isConst && implicitTypeOnly && property.returnTypeRef !is FirImplicitTypeRef && cannotHaveDeepImplicitTypeRefs) { | ||
| if (session.languageVersionSettings.getFlag(AnalysisFlags.headerMode) && | ||
| property.initializer !is FirAnonymousObjectExpression | ||
| ) { | ||
| property.replaceInitializer(null) | ||
| } | ||
| return property | ||
| } | ||
|
|
||
|
|
@@ -188,6 +193,14 @@ open class FirDeclarationsResolveTransformer( | |
| if (!initializerIsAlreadyResolved) { | ||
| dataFlowAnalyzer.enterProperty(property) | ||
| } | ||
| else if ( | ||
|
Contributor
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. This branch is actually useless, as you anyway remove the initializer in the end of the |
||
| session.languageVersionSettings.getFlag(AnalysisFlags.headerMode) && | ||
| !property.isConst && | ||
| property.returnTypeRef !is FirImplicitTypeRef && | ||
| property.initializer !is FirAnonymousObjectExpression | ||
| ) { | ||
| property.replaceInitializer(null) | ||
| } | ||
|
|
||
| var backingFieldIsAlreadyResolved = false | ||
| context.withProperty(property) { | ||
|
|
@@ -295,6 +308,13 @@ open class FirDeclarationsResolveTransformer( | |
| property.replaceControlFlowGraphReference(FirControlFlowGraphReferenceImpl(it)) | ||
| } | ||
| } | ||
| if (session.languageVersionSettings.getFlag(AnalysisFlags.headerMode) && | ||
| !property.isConst && | ||
| property.returnTypeRef !is FirImplicitTypeRef && | ||
| property.initializer !is FirAnonymousObjectExpression | ||
| ) { | ||
| property.replaceInitializer(null) | ||
| } | ||
|
|
||
| property | ||
| } | ||
|
|
||
2 changes: 0 additions & 2 deletions
2
compiler/testData/codegen/box/inference/pcla/issues/kt67993.kt
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
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.
Setting
forceKeepingTheBodyInHeaderModehere actually doesn't do anything, as this property affects onlytransformFunctionBody, and here we call justgetAsFirExpression, which unconditionally creates an expression.Here you should just don't call
getAsFirExpressionifisReturnType && modifiers?.isConst() != true.