All Downloads are FREE. Search and download functionalities are using the official Maven repository.

arrow.meta.plugins.proofs.phases.resolve.scopes.ProofsScopeTower.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha.6
Show newest version
package arrow.meta.plugins.proofs.phases.resolve.scopes

import arrow.meta.phases.CompilerContext
import arrow.meta.plugins.proofs.phases.Proof
import org.jetbrains.kotlin.backend.common.SimpleMemberScope
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitsExtensionsResolutionFilter
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
import org.jetbrains.kotlin.resolve.scopes.LocalRedeclarationChecker
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.resolve.scopes.ResolutionScope
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
import org.jetbrains.kotlin.types.TypeApproximator

class ProofsScopeTower(
  module: ModuleDescriptor,
  val proofs: List,
  compilerContext: CompilerContext
) : ImplicitScopeTower {
  val scopeOwner = module
  val importingScope =
    LexicalScopeImpl(
      ImportingScope.Empty,
      scopeOwner,
      false,
      null,
      LexicalScopeKind.SYNTHETIC,
      LocalRedeclarationChecker.DO_NOTHING
    ) {}
  override val dynamicScope: MemberScope = SimpleMemberScope(proofs.map { it.through })
  override val implicitsResolutionFilter: ImplicitsExtensionsResolutionFilter =
    ImplicitsExtensionsResolutionFilter.Default
  override val isDebuggerContext: Boolean = false
  override val isNewInferenceEnabled: Boolean = false
  override val lexicalScope: LexicalScope =
    LexicalChainedScope.create(
      parent = importingScope,
      ownerDescriptor = scopeOwner,
      isOwnerDescriptorAccessibleByLabel = false,
      implicitReceiver = null,
      kind = LexicalScopeKind.SYNTHETIC,
      memberScopes = arrayOf({ proofs }.memberScope())
    ) // .addImportingScope(memberScope.memberScopeAsImportingScope())
  override val location: LookupLocation = NoLookupLocation.FROM_BACKEND
  override val syntheticScopes: SyntheticScopes = SyntheticScopes.Empty
  override val typeApproximator: TypeApproximator =
    TypeApproximator(
      module.builtIns,
      compilerContext.configuration?.languageVersionSettings ?: LanguageVersionSettingsImpl.DEFAULT
    )
  override fun getImplicitReceiver(scope: LexicalScope): ReceiverValueWithSmartCastInfo? = null
  override fun interceptFunctionCandidates(
    resolutionScope: ResolutionScope,
    name: Name,
    initialResults: Collection,
    location: LookupLocation,
    dispatchReceiver: ReceiverValueWithSmartCastInfo?,
    extensionReceiver: ReceiverValueWithSmartCastInfo?
  ): Collection = emptyList()

  override fun interceptVariableCandidates(
    resolutionScope: ResolutionScope,
    name: Name,
    initialResults: Collection,
    location: LookupLocation,
    dispatchReceiver: ReceiverValueWithSmartCastInfo?,
    extensionReceiver: ReceiverValueWithSmartCastInfo?
  ): Collection = emptyList()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy