Skip to content

Commit

Permalink
Added AttemptedCandidate for regions compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Verdagon committed Sep 2, 2023
1 parent 8e6272b commit 02f39df
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
25 changes: 25 additions & 0 deletions Frontend/.idea/scala_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 18 additions & 13 deletions Frontend/TypingPass/src/dev/vale/typing/OverloadResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class OverloadResolver(
exact) match {
case Err(e) => return Err(e)
case Ok(potentialBanner) => {
Ok(StampFunctionSuccess(potentialBanner, Map()))
Ok(StampFunctionSuccess(potentialBanner.prototype, Map()))
// Ok(
// stampPotentialFunctionForPrototype(
// coutputs, callingEnv, callRange, callLocation, potentialBanner, contextRegion, args))
Expand Down Expand Up @@ -221,6 +221,11 @@ class OverloadResolver(
})
}

case class AttemptedCandidate(
// Pure and region will go here
prototype: PrototypeT[IFunctionNameT]
)

private def attemptCandidateBanner(
callingEnv: IInDenizenEnvironmentT,
coutputs: CompilerOutputs,
Expand All @@ -232,7 +237,7 @@ class OverloadResolver(
args: Vector[CoordT],
candidate: ICalleeCandidate,
exact: Boolean):
Result[PrototypeT[IFunctionNameT], IFindFunctionFailureReason] = {
Result[AttemptedCandidate, IFindFunctionFailureReason] = {
candidate match {
case FunctionCalleeCandidate(ft@FunctionTemplataT(declaringEnv, function)) => {
// See OFCBT.
Expand Down Expand Up @@ -350,7 +355,7 @@ class OverloadResolver(
case Err(rejectionReason) => Err(rejectionReason)
case Ok(()) => {
vassert(coutputs.getInstantiationBounds(prototype.prototype.id).nonEmpty)
Ok(prototype.prototype)
Ok(AttemptedCandidate(prototype.prototype))
}
}
}
Expand All @@ -365,7 +370,7 @@ class OverloadResolver(
case Err(rejectionReason) => Err(rejectionReason)
case Ok(()) => {
vassert(coutputs.getInstantiationBounds(prototype.prototype.id).nonEmpty)
Ok(prototype.prototype)
Ok(AttemptedCandidate(prototype.prototype))
}
}
}
Expand All @@ -380,7 +385,7 @@ class OverloadResolver(
case HeaderCalleeCandidate(header) => {
paramsMatch(coutputs, callingEnv, callRange, callLocation, args, header.paramTypes, exact) match {
case Ok(_) => {
Ok(header.toPrototype)
Ok(AttemptedCandidate(header.toPrototype))
}
case Err(fff) => Err(fff)
}
Expand Down Expand Up @@ -412,7 +417,7 @@ class OverloadResolver(
val bounds = Map[IRuneS, PrototypeTemplataT[IFunctionNameT]]()

vassert(coutputs.getInstantiationBounds(prototype.id).nonEmpty)
Ok(prototype)
Ok(AttemptedCandidate(prototype))
}
case Err(fff) => Err(fff)
}
Expand Down Expand Up @@ -452,7 +457,7 @@ class OverloadResolver(
args: Vector[CoordT],
extraEnvsToLookIn: Vector[IInDenizenEnvironmentT],
exact: Boolean):
Result[PrototypeT[IFunctionNameT], FindFunctionFailure] = {
Result[AttemptedCandidate, FindFunctionFailure] = {
// This is here for debugging, so when we dont find something we can see what envs we searched
val searchedEnvs = new Accumulator[SearchedEnvironment]()
val undedupedCandidates = new Accumulator[ICalleeCandidate]()
Expand Down Expand Up @@ -519,12 +524,12 @@ class OverloadResolver(
callingEnv: IInDenizenEnvironmentT,
callRange: List[RangeS],
callLocation: LocationInDenizen,
unfilteredBanners: Iterable[PrototypeT[IFunctionNameT]],
unfilteredBanners: Iterable[AttemptedCandidate],
argTypes: Vector[CoordT]):
(
PrototypeT[IFunctionNameT],
AttemptedCandidate,
// Rejection reason by banner
Map[PrototypeT[IFunctionNameT], IFindFunctionFailureReason]) = {
Map[AttemptedCandidate, IFindFunctionFailureReason]) = {

// Sometimes a banner might come from many different environments (remember,
// when we do a call, we look in the environments of all the arguments' types).
Expand All @@ -544,7 +549,7 @@ class OverloadResolver(
// If there are multiple overloads with the same exact parameter list,
// then get rid of the templated ones; ordinary ones get priority.
val banners =
dedupedBanners.groupBy(_.paramTypes).values.flatMap({ potentialBannersWithSameParamTypes =>
dedupedBanners.groupBy(_.prototype.paramTypes).values.flatMap({ potentialBannersWithSameParamTypes =>
val ordinaryBanners =
potentialBannersWithSameParamTypes
if (ordinaryBanners.isEmpty) {
Expand All @@ -558,7 +563,7 @@ class OverloadResolver(

val bannerIndexToScore =
banners.map(banner => {
vassertSome(getBannerParamScores(coutputs, callingEnv, callRange, callLocation, banner, argTypes))
vassertSome(getBannerParamScores(coutputs, callingEnv, callRange, callLocation, banner.prototype, argTypes))
})

// For any given parameter:
Expand Down Expand Up @@ -596,7 +601,7 @@ class OverloadResolver(
.map(i => i -> banners(i))
.foldLeft((List[(Int, PrototypeT[IFunctionNameT])](), List[(Int, PrototypeT[FunctionBoundNameT])]()))({
case ((normalCandidates, boundCandidates), (index, thisCandidate)) => {
thisCandidate match {
thisCandidate.prototype match {
case PrototypeT(IdT(packageCoord, initSteps, FunctionBoundNameT(tn, firstTemplateArgs, firstParameters)), firstReturnType) => {
val thisBoundCandidate = PrototypeT(IdT(packageCoord, initSteps, FunctionBoundNameT(tn, firstTemplateArgs, firstParameters)), firstReturnType)
(normalCandidates, (index -> thisBoundCandidate) :: boundCandidates)
Expand Down

0 comments on commit 02f39df

Please sign in to comment.