Skip to content

Commit

Permalink
Merge pull request ValeLang#620 from Verdagon/regionsmerge15
Browse files Browse the repository at this point in the history
Regions merge: Pulled coercing logic into higher typing phase
  • Loading branch information
Verdagon authored Jul 20, 2023
2 parents c95cd4b + b84a3ae commit ea2d118
Show file tree
Hide file tree
Showing 38 changed files with 1,455 additions and 1,306 deletions.
3 changes: 3 additions & 0 deletions Frontend/Builtins/src/dev/vale/Builtins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ object Builtins {
"runtime_sized_array_push" -> "runtime_sized_array_push.vale",
"runtime_sized_array_pop" -> "runtime_sized_array_pop.vale",
"runtime_sized_array_len" -> "runtime_sized_array_len.vale",
"runtime_sized_array_capacity" -> "runtime_sized_array_capacity.vale",
"runtime_sized_array_mut_drop" -> "runtime_sized_array_mut_drop.vale",
"static_sized_array_mut_drop" -> "static_sized_array_mut_drop.vale",
"mainargs" -> "mainargs.vale",
"as" -> "as.vale",
"print" -> "print.vale",
Expand Down
27 changes: 3 additions & 24 deletions Frontend/Builtins/src/dev/vale/resources/arrays.vale
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,19 @@ import v.builtins.arith.*;
import v.builtins.drop.*;
import v.builtins.panic.*;
import v.builtins.runtime_sized_array_mut_new.*;
import v.builtins.runtime_sized_array_mut_drop.*;
import v.builtins.runtime_sized_array_push.*;
import v.builtins.runtime_sized_array_pop.*;
import v.builtins.runtime_sized_array_len.*;
import v.builtins.runtime_sized_array_capacity.*;
import v.builtins.static_sized_array_mut_drop.*;

func drop_into<V Variability, S Int, E, F>(arr [#S]<imm, V>E, consumer &F) void
where func(&F, E)void
{}

extern("vale_static_sized_array_drop_into")
func drop_into<V Variability, S Int, E, F>(arr [#S]<mut, V>E, consumer &F) void
where func(&F, E)void;

func drop<V Variability, S Int, E>(arr [#S]<mut, V>E) void
where func drop(E)void {
drop_into(arr, {_;});
}
func drop<V Variability, S Int, E>(arr [#S]<imm, V>E) void {}

func drop_into<E, F>(arr []<mut>E, consumer &F) void
where func(&F, E)void
{
while (arr.len() > 0) {
consumer(arr.pop());
}
[] = arr;
}
func drop<E>(arr []<mut>E) void
where func drop(E)void {
drop_into(arr, {_;});
}

func drop_into<E, F>(arr []<imm>E, consumer &F) void
where func(&F, &E)void, func drop(E)void
{
Expand All @@ -51,9 +33,6 @@ where func drop(E)void {
extern("vale_static_sized_array_len")
func len<M Mutability, V Variability, S Int, E>(arr &[#S]<M Mutability, V>E) int;

extern("vale_runtime_sized_array_capacity")
func capacity<E>(arr &[]<mut>E) int;

func Array<M Mutability, E, G>(n int, generator G) []<M>E
where
M Mutability = mut,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extern("vale_runtime_sized_array_capacity")
func capacity<M Mutability, E>(arr &[]<M>E) int;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

func drop_into<E, F>(arr []<mut>E, consumer &F) void
where func(&F, E)void
{
while (arr.len() > 0) {
consumer(arr.pop());
}
[] = arr;
}
func drop<E>(arr []<mut>E) void
where func drop(E)void {
drop_into(arr, {_;});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

extern("vale_static_sized_array_drop_into")
func drop_into<V Variability, S Int, E, F>(arr [#S]<mut, V>E, consumer &F) void
where func(&F, E)void;

func drop<V Variability, S Int, E>(arr [#S]<mut, V>E) void
where func drop(E)void {
drop_into(arr, {_;});
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ object HigherTypingPass {
}
(actualType, expectedType) match {
case (x, y) if x == y => {
ruleBuilder += rule
ruleBuilder += CallSR(range, resultRune, templateRune, args)
}
case (KindTemplataType(), CoordTemplataType()) => {
val kindRune = RuneUsage(range, ImplicitCoercionKindRuneS(range, resultRune.rune))
runeAToType.put(kindRune.rune, KindTemplataType())
ruleBuilder += MaybeCoercingCallSR(range, kindRune, templateRune, args)
ruleBuilder += CallSR(range, kindRune, templateRune, args)
ruleBuilder += CoerceToCoordSR(range, resultRune, kindRune)
}
case _ => vimpl()
Expand All @@ -89,7 +89,7 @@ object HigherTypingPass {
runeAToType, ruleBuilder, range, resultRune, name)
}
case KindTemplataType() => {
ruleBuilder += rule
ruleBuilder += LookupSR(range, resultRune, name)
}
case TemplateTemplataType(paramTypes, returnType) => {
vassert(paramTypes.nonEmpty) // impl, if it's empty we might need to do some coercing.
Expand Down Expand Up @@ -118,7 +118,7 @@ object HigherTypingPass {
case TemplataLookupResult(actualType) => {
(actualType, desiredType) match {
case (x, y) if x == y => {
ruleBuilder += rule
ruleBuilder += LookupSR(range, resultRune, name)
}
case (KindTemplataType(), CoordTemplataType()) => {
coerceKindLookupToCoord(
Expand Down Expand Up @@ -157,7 +157,7 @@ object HigherTypingPass {
) = {
val kindRune = RuneUsage(range, ImplicitCoercionKindRuneS(range, resultRune.rune))
runeAToType.put(kindRune.rune, KindTemplataType())
ruleBuilder += MaybeCoercingLookupSR(range, kindRune, name)
ruleBuilder += LookupSR(range, kindRune, name)
ruleBuilder += CoerceToCoordSR(range, resultRune, kindRune)
}

Expand All @@ -171,8 +171,8 @@ object HigherTypingPass {
Unit = {
val templateRune = RuneUsage(range, ImplicitCoercionTemplateRuneS(range, resultRune.rune))
runeAToType.put(templateRune.rune, actualTemplateType)
ruleBuilder += MaybeCoercingLookupSR(range, templateRune, name)
ruleBuilder += MaybeCoercingCallSR(range, resultRune, templateRune, Vector())
ruleBuilder += LookupSR(range, templateRune, name)
ruleBuilder += CallSR(range, resultRune, templateRune, Vector())
}

private def coerceKindTemplateLookupToCoord(
Expand All @@ -187,8 +187,8 @@ object HigherTypingPass {
val kindRune = RuneUsage(range, ImplicitCoercionKindRuneS(range, resultRune.rune))
runeAToType.put(templateRune.rune, ttt)
runeAToType.put(kindRune.rune, KindTemplataType())
ruleBuilder += MaybeCoercingLookupSR(range, templateRune, name)
ruleBuilder += MaybeCoercingCallSR(range, kindRune, templateRune, Vector())
ruleBuilder += LookupSR(range, templateRune, name)
ruleBuilder += CallSR(range, kindRune, templateRune, Vector())
ruleBuilder += CoerceToCoordSR(range, resultRune, kindRune)
}
}
Expand Down Expand Up @@ -379,6 +379,13 @@ class HigherTypingPass(globalOptions: GlobalOptions, interner: Interner, keyword
// Shouldnt fail because we got a complete solve earlier
astrouts.codeLocationToMaybeType.put(rangeS.begin, Some(tyype))

headerRulesExplicitS.collect({
case MaybeCoercingCallSR(_, _, _, _) => vwat()
})
memberRulesExplicitS.collect({
case MaybeCoercingCallSR(_, _, _, _) => vwat()
})

val structA =
highertyping.StructA(
rangeS,
Expand Down
30 changes: 28 additions & 2 deletions Frontend/HigherTypingPass/src/dev/vale/highertyping/ast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package dev.vale.highertyping

import dev.vale.{RangeS, StrI, vassert, vcurious, vpass, vwat}
import dev.vale.parsing.ast.MutabilityP
import dev.vale.postparsing.rules.{IRulexSR, RuneUsage}
import dev.vale.postparsing.rules._
import dev.vale.postparsing._
import dev.vale.parsing._
import dev.vale.postparsing.rules.IRulexSR
import dev.vale.postparsing._

import scala.collection.immutable.List
Expand Down Expand Up @@ -88,6 +87,16 @@ case class StructA(

vpass()

// These should be removed by the higher typer
headerRules.collect({
case MaybeCoercingCallSR(_, _, _, _) => vwat()
case MaybeCoercingLookupSR(_, _, _) => vwat()
})
memberRules.collect({
case MaybeCoercingCallSR(_, _, _, _) => vwat()
case MaybeCoercingLookupSR(_, _, _) => vwat()
})

vassert(
!genericParameters.exists({ case x =>
x.rune.rune match {
Expand Down Expand Up @@ -131,6 +140,12 @@ case class ImplA(
interfaceKindRune: RuneUsage,
superInterfaceImpreciseName: IImpreciseNameS) {

// These should be removed by the higher typer
rules.collect({
case MaybeCoercingCallSR(_, _, _, _) => vwat()
case MaybeCoercingLookupSR(_, _, _) => vwat()
})

val hash = range.hashCode() + name.hashCode()
override def hashCode(): Int = hash;
override def equals(obj: Any): Boolean = {
Expand Down Expand Up @@ -182,6 +197,11 @@ case class InterfaceA(
// See IMRFDI
internalMethods: Vector[FunctionA]
) extends CitizenA {
// These should be removed by the higher typer
rules.collect({
case MaybeCoercingCallSR(_, _, _, _) => vwat()
case MaybeCoercingLookupSR(_, _, _) => vwat()
})

vassert(
!genericParameters.exists({ case x =>
Expand Down Expand Up @@ -269,6 +289,12 @@ case class FunctionA(
val hash = range.hashCode() + name.hashCode()
vpass()

// These should be removed by the higher typer
rules.collect({
case MaybeCoercingCallSR(_, _, _, _) => vwat()
case MaybeCoercingLookupSR(_, _, _) => vwat()
})

vassert(
!genericParameters.exists({ case x =>
x.rune.rune match { case DenizenDefaultRegionRuneS(_) => true case _ => false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3109,10 +3109,6 @@ class Instantiator(
// denizenName, denizenBoundToDenizenCallerSuppliedThing, substitutions, perspectiveRegionT, outerRegion)
// .expectRegionTemplata()

// strt here, somethings weird.
// // its possible the ownership from the substitution is messing with us.
// // the ownership should

kind match {
case KindPlaceholderT(placeholderId) => {
// Let's get the index'th placeholder from the top level denizen.
Expand Down
Loading

0 comments on commit ea2d118

Please sign in to comment.