Skip to content

Commit

Permalink
Merge pull request ValeLang#617 from Verdagon/regionsmerge12
Browse files Browse the repository at this point in the history
Regions merges: callLocation, renames, imports
  • Loading branch information
Verdagon authored Jul 13, 2023
2 parents fbb92e9 + 0440574 commit 922b53b
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Frontend/FinalAST/src/dev/vale/finalast/ast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ case class ProgramH(
}
def lookupFunction(prototype: PrototypeH): FunctionH = {
val paackage = lookupPackage(prototype.id.packageCoordinate)
val result = vassertSome(paackage.functions.find(_.fullName == prototype.id))
val result = vassertSome(paackage.functions.find(_.id == prototype.id))
vassert(prototype == result.prototype)
result
}
Expand Down Expand Up @@ -228,7 +228,7 @@ case class FunctionH(
vpass()

val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash; override def equals(obj: Any): Boolean = vcurious();
def fullName = prototype.id
def id = prototype.id
def isUserFunction = attributes.contains(UserFunctionH)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.vale.highertyping
import dev.vale
import dev.vale.highertyping.HigherTypingPass.explicifyLookups
import dev.vale.lexing.{FailedParse, RangeL}
import dev.vale.{CodeLocationS, Err, FileCoordinateMap, IPackageResolver, Interner, Keywords, Ok, PackageCoordinate, PackageCoordinateMap, Profiler, RangeS, Result, SourceCodeUtils, StrI, highertyping, vassert, vassertSome, vcurious, vfail, vimpl, vregionmut, vwat}
import dev.vale._
import dev.vale.options.GlobalOptions
import dev.vale.parsing.ast.{FileP, OwnP}
import dev.vale.postparsing.rules.{IRulexSR, RuleScout}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.vale.highertyping

import dev.vale.postparsing.{CodeNameS, PostParser, RuneTypeSolveError, RuneTypingCouldntFindType}
import dev.vale.postparsing._
import dev.vale.{Err, Ok, SourceCodeUtils, StrI, vassert, vfail}
import org.scalatest._
import dev.vale.solver._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
"""exported func main() {
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
}

test("Type simple generic function") {
Expand All @@ -30,7 +30,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
"""exported func moo<T>() where T Ref {
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
}

test("Infer coord type from parameters") {
Expand All @@ -39,7 +39,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
"""exported func moo<T>(x T) {
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
val program = vassertSome(astrouts.get(PackageCoordinate.TEST_TLD(compilation.interner, compilation.keywords)))
val main = program.lookupFunction("moo")
main.runeToType(CodeRuneS(compilation.keywords.T)) shouldEqual CoordTemplataType()
Expand All @@ -51,7 +51,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
"""struct Moo {
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
}

test("Type simple generic struct") {
Expand All @@ -61,7 +61,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
| bork T;
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
}

test("Template call, recursively evaluate") {
Expand All @@ -86,7 +86,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
"""interface Moo {
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
}

test("Type simple generic interface") {
Expand All @@ -95,7 +95,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
"""interface Moo<T> where T Ref {
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
}

test("Type simple generic interface method") {
Expand Down Expand Up @@ -145,7 +145,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
|{
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
val program = vassertSome(astrouts.get(PackageCoordinate.TEST_TLD(compilation.interner, compilation.keywords)))
val main = program.lookupFunction("moo")
main.runeToType(CodeRuneS(compilation.keywords.T)) shouldEqual CoordTemplataType()
Expand All @@ -159,7 +159,7 @@ class HigherTypingPassTests extends FunSuite with Matchers {
|{
|}
|""".stripMargin)
val astrouts = compilation.getAstrouts().getOrDie()
val astrouts = compilation.expectAstrouts()
val program = vassertSome(astrouts.get(PackageCoordinate.TEST_TLD(compilation.interner, compilation.keywords)))
val main = program.lookupFunction("moo")
main.runeToType(CodeRuneS(compilation.interner.intern(StrI("P")))) shouldEqual PackTemplataType(CoordTemplataType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ class Instantiator(
val functionExportsC =
functionExportsT.map({ case FunctionExportT(range, prototypeT, exportPlaceholderedIdT, exportedName) =>
val perspectiveRegionT = RegionT()
// exportPlaceholderedIdT.localName.templateArgs.last match {
// case PlaceholderTemplataT(IdT(packageCoord, initSteps, r @ RegionPlaceholderNameT(_, _, _, _)), RegionTemplataType()) => {
// IdT(packageCoord, initSteps, r)
// }
// case _ => vwat()
// }

val exportIdS =
translateId[ExportNameT, ExportNameI[sI]](
Expand Down Expand Up @@ -187,12 +181,6 @@ class Instantiator(
val funcExternsC =
functionExternsT.map({ case FunctionExternT(range, externPlaceholderedIdT, prototypeT, externedName) =>
val perspectiveRegionT = RegionT()
// externPlaceholderedIdT.localName.templateArgs.last match {
// case PlaceholderTemplataT(IdT(packageCoord, initSteps, r @ RegionPlaceholderNameT(_, _, _, _)), RegionTemplataType()) => {
// IdT(packageCoord, initSteps, r)
// }
// case _ => vwat()
// }

val externIdS =
translateId[ExternNameT, ExternNameI[sI]](
Expand Down Expand Up @@ -1080,7 +1068,7 @@ class Instantiator(
(idT.initNonPackageId() match {
case None => Map()
case Some(initNonPackageIdT) => {
assemblePlaceholderMap(initNonPackageIdT, vassertSome(idS.initNonPackageFullName()))
assemblePlaceholderMap(initNonPackageIdT, vassertSome(idS.initNonPackageId()))
}
}) ++
(idT match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,33 @@ object RegionCounter {
countId[IStructNameI[sI]](
counter,
structId,
{
case StructNameI(template, templateArgs) => {
templateArgs.foreach(countTemplata(counter, _))
}
case LambdaCitizenNameI(template) => {
}
case AnonymousSubstructNameI(template, templateArgs) => {
templateArgs.foreach(countTemplata(counter, _))
}
})
countStructName(counter, _))
}

def countStructTemplateName(
counter: Counter,
structName: IStructTemplateNameI[sI]):
Unit = {
structName match {
case StructTemplateNameI(humanName) => StructTemplateNameI(humanName)
}
}

def countStructName(
counter: Counter,
structName: IStructNameI[sI]):
Unit = {
structName match {
case StructNameI(template, templateArgs) => {
countStructTemplateName(counter, template)
templateArgs.foreach(countTemplata(counter, _))
}
case LambdaCitizenNameI(template) => {
}
case AnonymousSubstructNameI(template, templateArgs) => {
templateArgs.foreach(countTemplata(counter, _))
}
}
}

def countImplId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,6 @@ import scala.collection.immutable._
// type to avoid a cyclical definition.
// - If not in declared banners, then tell FunctionCompiler to start evaluating it.

// case class ImplI(
// // These are ICitizenTI and InterfaceIT which likely have placeholder templatas in them.
// // We do this because a struct might implement an interface in multiple ways, see SCIIMT.
// // We have the template names as well as the placeholders for better searching, see MLUIBTN.
//
// templata: ImplDefinitionTemplataI[cI],
//
// instantiatedId: IdI[cI, IImplNameI[cI]],
// templateId: IdI[cI, IImplTemplateNameI[cI]],
//
// subCitizenTemplateId: IdI[cI, ICitizenTemplateNameI[cI]],
// subCitizen: ICitizenIT[cI],
//
// superInterface: InterfaceIT[cI],
// superInterfaceTemplateId: IdI[cI, IInterfaceTemplateNameI[cI]],
//
// // This is similar to FunctionT.runeToFuncBound
// runeToFuncBound: Map[IRuneS, IdI[cI, FunctionBoundNameI[cI]]],
// runeToImplBound: Map[IRuneS, IdI[cI, ImplBoundNameI[cI]]],
//
// runeIndexToIndependence: Vector[Boolean],
//
// // A function will inherit bounds from its parameters' kinds. Same with an impl from its sub
// // citizen, and a case block from its receiving kind.
// // We'll need to remember those, so the instantiator can do its thing.
// // See TIBANFC for more.
// reachableBoundsFromSubCitizen: Vector[PrototypeI[cI]]
//
// // // Starting from a placeholdered super interface, this is the interface that would result.
// // // We get this by solving the impl, given a placeholdered sub citizen.
// // subCitizenFromPlaceholderedParentInterface: ICitizenIT,
// )

case class KindExportI(
range: RangeS,
tyype: KindIT[cI],
Expand Down Expand Up @@ -113,10 +80,10 @@ case class EdgeI(

override def equals(obj: Any): Boolean = {
obj match {
case EdgeI(thatEdgeFullName, thatStruct, thatInterface, _, _, _) => {
case EdgeI(thatEdgeId, thatStruct, thatInterface, _, _, _) => {
val isSame = subCitizen == thatStruct && superInterface == thatInterface
if (isSame) {
vassert(edgeId == thatEdgeFullName)
vassert(edgeId == thatEdgeId)
}
isSame
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ case class InterfaceToInterfaceUpcastIE(
// So, the target kind can be anything, not just an interface.
case class UpcastIE(
innerExpr: ReferenceExpressionIE,
targetSuperKind: InterfaceIT[cI],
targetInterface: InterfaceIT[cI],
// This is the impl we use to allow/permit the upcast. It'll be useful for monomorphization
// and later on for locating the itable ptr to put in fat pointers.
implName: IdI[cI, IImplNameI[cI]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ case class IdI[+R <: IRegionsModeI, +I <: INameI[R]](
}
}

def packageFullName: IdI[R, PackageTopLevelNameI[R]] = {
def packageId: IdI[R, PackageTopLevelNameI[R]] = {
IdI(packageCoord, Vector(), PackageTopLevelNameI())
}

def initFullName: IdI[R, INameI[R]] = {
def initId: IdI[R, INameI[R]] = {
if (initSteps.isEmpty) {
IdI(packageCoord, Vector(), PackageTopLevelNameI())
} else {
IdI(packageCoord, initSteps.init, initSteps.last)
}
}

def initNonPackageFullName(): Option[IdI[R, INameI[R]]] = {
def initNonPackageId(): Option[IdI[R, INameI[R]]] = {
if (initSteps.isEmpty) {
None
} else {
Expand Down Expand Up @@ -270,9 +270,7 @@ case class OverrideDispatcherCaseNameI[+R <: IRegionsModeI](
sealed trait IVarNameI[+R <: IRegionsModeI] extends INameI[R]
case class TypingPassBlockResultVarNameI[+R <: IRegionsModeI](life: LocationInFunctionEnvironmentI) extends IVarNameI[R]
case class TypingPassFunctionResultVarNameI[+R <: IRegionsModeI]() extends IVarNameI[R]
case class TypingPassTemporaryVarNameI[+R <: IRegionsModeI](life: LocationInFunctionEnvironmentI) extends IVarNameI[R] {
vpass()
}
case class TypingPassTemporaryVarNameI[+R <: IRegionsModeI](life: LocationInFunctionEnvironmentI) extends IVarNameI[R]
case class TypingPassPatternMemberNameI[+R <: IRegionsModeI](life: LocationInFunctionEnvironmentI) extends IVarNameI[R]
case class TypingIgnoredParamNameI[+R <: IRegionsModeI](num: Int) extends IVarNameI[R]
case class TypingPassPatternDestructureeNameI[+R <: IRegionsModeI](life: LocationInFunctionEnvironmentI) extends IVarNameI[R]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.vale.parsing
import dev.vale.{Err, Interner, Keywords, Ok, Result, StrI, U, vassert, vassertSome, vimpl, vwat}
import dev.vale.parsing.ast.{AbstractP, ConstructingMemberNameDeclarationP, DestructureP, INameDeclarationP, IgnoredLocalNameDeclarationP, LocalNameDeclarationP, NameP, PatternPP}
import dev.vale.parsing.templex.TemplexParser
import dev.vale.lexing.{CantUseThatLocalName, BadLocalName, BadNameBeforeDestructure, BadThingAfterTypeInPattern, EmptyParameter, EmptyPattern, FoundBothAbstractAndOverride, INodeLE, IParseError, LightFunctionMustHaveParamTypes, RangeL, RangedInternalErrorP, ScrambleLE, SquaredLE, SymbolLE, WordLE}
import dev.vale.lexing._
import dev.vale.parsing.ast._

import scala.collection.mutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.vale.lexing.{Lexer, LexingIterator}
import dev.vale.parsing.ast._
import dev.vale.{Collector, Interner, Keywords, StrI, vimpl}
import dev.vale.parsing.ast.{ConstantIntPE, ConstantStrPE, FunctionCallPE, LookupNameP, LookupPE, NameP, StrInterpolatePE}
import org.scalatest.FunSuite
import org.scalatest.Matchers.convertToAnyShouldWrapper
import org.scalatest._
import org.scalatest._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.vale.parsing.ast

import dev.vale.lexing.RangeL
import dev.vale.{vassert, vcurious, vwat}
import dev.vale._

//sealed trait IVirtualityP
case class AbstractP(range: RangeL)// extends IVirtualityP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import PassManager.SourceInput
import dev.vale.highertyping.{ICompileErrorA, ProgramA}
import dev.vale.instantiating.ast.HinputsI
import dev.vale.lexing.{FailedParse, RangeL}
import dev.vale.simplifying._
import dev.vale.typing.{HinputsT, ICompileErrorT}
import dev.vale.instantiating.ast.HinputsI
import dev.vale.postparsing.PostParser
import dev.vale.simplifying._
import dev.vale.typing.ICompileErrorT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.vale.postparsing.patterns

import dev.vale.{Interner, RangeS, vimpl}
import dev.vale._
import dev.vale.parsing.ast._
import dev.vale.postparsing._
import dev.vale.postparsing.rules.{IRulexSR, TemplexScout}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dev.vale.postparsing.patterns

import dev.vale.postparsing.IVarNameS
import dev.vale.postparsing.rules.RuneUsage
import dev.vale.{RangeS, StrI, vcurious, vpass, vwat}
import dev.vale._
import dev.vale.postparsing._

import scala.collection.immutable.List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ case class Hamuts(
packageCoordToExternNameToKind: Map[PackageCoordinate, Map[StrI, KindHT]]) {
override def equals(obj: Any): Boolean = vcurious(); override def hashCode(): Int = vfail() // Would need a really good reason to hash something this big

vassert(functionDefs.values.map(_.fullName).toVector.distinct.size == functionDefs.values.size)
vassert(functionDefs.values.map(_.id).toVector.distinct.size == functionDefs.values.size)
vassert(structDefs.map(_.id).distinct.size == structDefs.size)
vassert(runtimeSizedArrays.values.map(_.name).toVector.distinct.size == runtimeSizedArrays.size)

Expand Down Expand Up @@ -238,10 +238,10 @@ case class Hamuts(

def addFunction(functionRef2: PrototypeI[cI], functionDefH: FunctionH): Hamuts = {
vassert(functionRefs.contains(functionRef2))
functionDefs.find(_._2.fullName == functionDefH.fullName) match {
functionDefs.find(_._2.id == functionDefH.id) match {
case None =>
case Some(existing) => {
vfail("Internal error: Can't add function:\n" + functionRef2 + "\nbecause there's already a function with same hammer name:\b" + existing._1 + "\nHammer name:\n" + functionDefH.fullName)
vfail("Internal error: Can't add function:\n" + functionRef2 + "\nbecause there's already a function with same hammer name:\b" + existing._1 + "\nHammer name:\n" + functionDefH.id)
}
}

Expand Down

0 comments on commit 922b53b

Please sign in to comment.