Skip to content

Commit

Permalink
Register Fir checkers to compiler processor
Browse files Browse the repository at this point in the history
Summary:
$title

Fir compiler uses the FirExtensionRegistrar for all Fir extensions, which helps simplify the installation site in the compiler processor

Reviewed By: fbcbl

Differential Revision: D65447524

fbshipit-source-id: 4d777831f1f4b7a375b4e8b511140449b90ef019
  • Loading branch information
kingsleyadio authored and facebook-github-bot committed Nov 14, 2024
1 parent cb4d0bc commit 3c1e024
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package com.facebook.litho
import com.facebook.litho.common.LithoCompilerConfig
import com.facebook.litho.common.get
import com.facebook.litho.k1.LithoFeCheckersContributor
import com.facebook.litho.k2.LithoFirExtensionRegistrar
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter
import org.jetbrains.kotlin.resolve.extensions.AnalysisHandlerExtension

/**
Expand All @@ -50,6 +52,7 @@ class LithoComponentRegistrar : CompilerPluginRegistrar() {
})
}
// K2 extensions
FirExtensionRegistrarAdapter.registerExtension(LithoFirExtensionRegistrar())
// Backend extensions
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.facebook.litho.k2

import com.facebook.litho.common.LithoNames
import com.facebook.litho.k2.diagnostics.LithoFirHookUsageChecker
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.analysis.checkers.expression.ExpressionCheckers
import org.jetbrains.kotlin.fir.analysis.extensions.FirAdditionalCheckersExtension
import org.jetbrains.kotlin.fir.extensions.FirDeclarationPredicateRegistrar
import org.jetbrains.kotlin.fir.extensions.predicate.DeclarationPredicate

/**
* Responsible for supplying additional checkers that will be called when the compiler analyses
* code. It can also report additional errors or warnings that can be visualized by the IDE.
*
* There are different kinds of checkers available, and can be as fine-grained as possible.
*
* @see [FirAdditionalCheckersExtension]
* @see [LithoFirHookUsageChecker]
*/
class LithoFirCheckersExtension(session: FirSession) : FirAdditionalCheckersExtension(session) {

override val expressionCheckers: ExpressionCheckers =
object : ExpressionCheckers() {
override val functionCallCheckers = setOf(LithoFirHookUsageChecker())
}

override fun FirDeclarationPredicateRegistrar.registerPredicates() {
register(predicate)
}

/**
* Defined a set of predicates that will be used to filter the declarations that should trigger
* the checkers defined in this extension.
*/
private val predicate =
DeclarationPredicate.create {
metaAnnotated(LithoNames.Unconditional.asSingleFqName(), includeItself = false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.facebook.litho.k2

import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar

/**
* Responsible for registering all FIR specific extensions for Litho to the compiler.
*
* It exposes a shorthand API that makes it easy to register extensions correctly. The API
* implicitly passes an [FirSession] object to the extension constructor, and also provides
* mechanisms to pass explicit dependencies as necessary.
*
* @see [LithoFirCheckersExtension]
*/
class LithoFirExtensionRegistrar : FirExtensionRegistrar() {
override fun ExtensionRegistrarContext.configurePlugin() {
+::LithoFirCheckersExtension
}
}

0 comments on commit 3c1e024

Please sign in to comment.