Skip to content

Commit

Permalink
Sped up 4.2%, by removing the parseds JSON round-trip when not in san…
Browse files Browse the repository at this point in the history
…ity check mode
  • Loading branch information
Verdagon committed Apr 5, 2022
1 parent 29eef43 commit 5f04754
Show file tree
Hide file tree
Showing 83 changed files with 2,446 additions and 2,113 deletions.
32 changes: 32 additions & 0 deletions Coordinator/src/build.vale
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
"Whether to reuse existing VAST",
"false",
"Whether to reuse the VAST created by (presumably) the last run."),
Flag(
"--run_backend",
FLAG_BOOL(),
"Whether to run the backend.",
"true",
"Whether to run the backend. True to run it, false to stop after frontend."),
Flag(
"--run_clang",
FLAG_BOOL(),
"Whether to run the clang step.",
"true",
"Whether to run the clang step. True to run it, false to stop after backend."),
Flag(
"--sanity_check",
FLAG_BOOL(),
"Whether to run self-diagnostics while compiling.",
"true",
"Whether to run self-diagnostics while compiling."),
Flag(
"--override_known_live_true",
FLAG_BOOL(),
Expand Down Expand Up @@ -204,6 +222,9 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
include_builtins = parsed_flags.get_bool_flag("--include_builtins", true);
output_vast = parsed_flags.get_bool_flag("--output_vast", true);
reuse_vast = parsed_flags.get_bool_flag("--reuse_vast", false);
run_backend = parsed_flags.get_bool_flag("--run_backend", true);
run_clang = parsed_flags.get_bool_flag("--run_clang", true);
sanity_check = parsed_flags.get_bool_flag("--sanity_check", true);
output_vpst = parsed_flags.get_bool_flag("--output_vpst", true);
no_std = parsed_flags.get_bool_flag("--no_std", false);

Expand Down Expand Up @@ -299,6 +320,7 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
&project_vale_input_declarations,
&project_non_vale_input_declarations,
benchmark,
sanity_check,
verbose,
debug_output,
include_builtins,
Expand Down Expand Up @@ -337,6 +359,11 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
// print(f"Both a .vast and non-vast files were specified! If a .vast is specified, it must be the only input.")
// sys.exit(1)

if not run_backend {
println("Not running backend, stopping here.");
return void();
}

if verbose {
println("Invoking Backend...")
}
Expand Down Expand Up @@ -365,6 +392,11 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
panic("Backend returned error code {backend_return_code}, aborting.");
}

if not run_clang {
println("Not running clang, stopping here.");
return void();
}

if verbose {
println("Collecting cc inputs...")
}
Expand Down
16 changes: 12 additions & 4 deletions Coordinator/src/valestrom.vale
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ func invoke_frontend(
project_vale_inputs &List<ProjectValeInputDeclaration>,
project_non_vale_inputs &List<ProjectNonValeInputDeclaration>,
benchmark bool,
sanity_check bool,
verbose bool,
debug_output bool,
include_builtins bool,
Expand All @@ -24,26 +25,33 @@ Subprocess {
command_line_args.add(frontend_path.str());
command_line_args.add("dev.vale.passmanager.PassManager");
command_line_args.add("build");
command_line_args.add("--output-dir");
command_line_args.add("--output_dir");
command_line_args.add(output_dir.str());

if benchmark {
command_line_args.add("--benchmark");
}
if sanity_check {
command_line_args.add("--sanity_check");
command_line_args.add("true");
}
if verbose {
command_line_args.add("--verbose");
}
if debug_output {
command_line_args.add("--debug_output");
}
if not include_builtins {
command_line_args.add("--include-builtins false");
command_line_args.add("--include_builtins");
command_line_args.add("false");
}
if not output_vast {
command_line_args.add("--output-vast false");
command_line_args.add("--output_vast");
command_line_args.add("false");
}
if not output_vpst {
command_line_args.add("--output-vpst false");
command_line_args.add("--output_vpst");
command_line_args.add("false");
}

project_directories.each((declaration) => {
Expand Down
39 changes: 26 additions & 13 deletions Frontend/Builtins/src/dev/vale/Builtins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package dev.vale
import scala.io.Source

object Builtins {
val NAMESPACE_COORD = PackageCoordinate("", Vector.empty)
def NAMESPACE_COORD(interner: Interner) = {
interner.intern(PackageCoordinate("", Vector.empty))
}

val moduleToFilename =
Map(
Expand Down Expand Up @@ -38,23 +40,34 @@ object Builtins {
// bare minimum. For example, the most basic test is `func main() int { return 42; }`, and we don't want it
// to fail just because the builtin-yet-unused `func as<T, X>(x X) Opt<T> { ... }` doesn't want to
// work right now.
def getModulizedCodeMap(): FileCoordinateMap[String] = {
moduleToFilename.foldLeft(FileCoordinateMap[String](Map()))({
case (prev, (moduleName, filename)) => {
prev.add("v", Vector("builtins", moduleName), filename, load(filename))
}
def getModulizedCodeMap(interner: Interner): FileCoordinateMap[String] = {
val result = new FileCoordinateMap[String]()
moduleToFilename.foreach({ case (moduleName, filename) =>
result.put(
interner.intern(FileCoordinate(
interner.intern(PackageCoordinate("v", Vector("builtins", moduleName))),
filename)),
load(filename))
})
result
}

// Add an empty v.builtins.whatever so that the aforementioned imports still work.
// But load the actual files all inside the root paackage.
def getCodeMap(): FileCoordinateMap[String] = {
moduleToFilename.foldLeft(FileCoordinateMap[String](Map()))({
case (prev, (moduleName, filename)) => {
prev
.add("v", Vector("builtins", moduleName), filename, "")
.add(NAMESPACE_COORD.module, NAMESPACE_COORD.packages, filename, load(filename))
}
def getCodeMap(interner: Interner): FileCoordinateMap[String] = {
val result = new FileCoordinateMap[String]()
moduleToFilename.foreach({ case (moduleName, filename) =>
result.put(
interner.intern(FileCoordinate(
interner.intern(PackageCoordinate("v", Vector("builtins", moduleName))),
filename)),
"")
result.put(
interner.intern(FileCoordinate(
interner.intern(PackageCoordinate(NAMESPACE_COORD(interner).module, NAMESPACE_COORD(interner).packages)),
filename)),
load(filename))
})
result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package dev.vale.compileserver

import com.google.cloud.functions.{HttpFunction, HttpRequest, HttpResponse}
import dev.vale.passmanager.PassManager
import dev.vale.Err
import dev.vale.{Err, Interner, Ok, vimpl}
import PassManager.{Options, SourceInput, build, jsonifyProgram}
import dev.vale.{Err, Ok, vimpl}

class BuildAction extends HttpFunction {
override def service(request: HttpRequest, response: HttpResponse): Unit = {
Expand All @@ -15,13 +14,14 @@ class BuildAction extends HttpFunction {
return
}

val interner = new Interner()
val options =
Options(
Vector(SourceInput(PassManager.DEFAULT_PACKAGE_COORD, "in.vale", code)),
Vector(SourceInput(PassManager.DEFAULT_PACKAGE_COORD(interner), "in.vale", code)),
Some(""),
false, false, true, false, true, None, false, true, true, true)
val json =
PassManager.build(options) match {
PassManager.build(interner, options) match {
case Ok(Some(programH)) => jsonifyProgram(vimpl(), programH)
case Err(error) => {
response.setStatusCode(400)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import com.google.cloud.functions.{HttpFunction, HttpRequest, HttpResponse}
import dev.vale.passmanager.PassManager
import dev.vale.testvm.Vivem
import PassManager.{Options, SourceInput}
import dev.vale.{Err, Ok}
import dev.vale.Err
import dev.vale.{Err, Interner, Ok}

class RunAction extends HttpFunction {
override def service(request: HttpRequest, response: HttpResponse): Unit = {
Expand All @@ -17,13 +16,14 @@ class RunAction extends HttpFunction {
return
}

val interner = new Interner()
val options =
Options(
Vector(SourceInput(PassManager.DEFAULT_PACKAGE_COORD, "in.vale", code)),
Vector(SourceInput(PassManager.DEFAULT_PACKAGE_COORD(interner), "in.vale", code)),
Some(""),
false, false, true, false, true, None, false, true, true, true)
val program =
PassManager.build(options) match {
PassManager.build(interner, options) match {
case Ok(Some(programH)) => programH
case Err(error) => {
response.setStatusCode(400)
Expand Down
25 changes: 12 additions & 13 deletions Frontend/FinalAST/src/dev/vale/finalast/types.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.vale.finalast

import dev.vale.{FileCoordinate, PackageCoordinate, vassert, vfail}
import dev.vale.vimpl
import dev.vale.{FileCoordinate, Interner, PackageCoordinate, vassert, vfail, vimpl}

// Represents a reference type.
// A reference contains these things:
Expand Down Expand Up @@ -93,30 +92,30 @@ case class ReferenceH[+T <: KindH](

// A value, a thing that can be pointed at. See ReferenceH for more information.
sealed trait KindH {
def packageCoord: PackageCoordinate
def packageCoord(interner: Interner): PackageCoordinate
}
object IntH {
val i32 = IntH(32)
}
case class IntH(bits: Int) extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = PackageCoordinate.BUILTIN
override def packageCoord(interner: Interner): PackageCoordinate = PackageCoordinate.BUILTIN(interner)
}
case class VoidH() extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = PackageCoordinate.BUILTIN
override def packageCoord(interner: Interner): PackageCoordinate = PackageCoordinate.BUILTIN(interner)
}
case class BoolH() extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = PackageCoordinate.BUILTIN
override def packageCoord(interner: Interner): PackageCoordinate = PackageCoordinate.BUILTIN(interner)
}
case class StrH() extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = PackageCoordinate.BUILTIN
override def packageCoord(interner: Interner): PackageCoordinate = PackageCoordinate.BUILTIN(interner)
}
case class FloatH() extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = PackageCoordinate.BUILTIN
override def packageCoord(interner: Interner): PackageCoordinate = PackageCoordinate.BUILTIN(interner)
}
// A primitive which can never be instantiated. If something returns this, it
// means that it will never actually return. For example, the return type of
Expand All @@ -126,23 +125,23 @@ case class FloatH() extends KindH {
// where None is never, Some(None) is Void, and Some(Some(_)) is a normal thing.
case class NeverH(fromBreak: Boolean) extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = PackageCoordinate.BUILTIN
override def packageCoord(interner: Interner): PackageCoordinate = PackageCoordinate.BUILTIN(interner)
}

case class InterfaceRefH(
// Unique identifier for the interface.
fullName: FullNameH
) extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = fullName.packageCoordinate
override def packageCoord(interner: Interner): PackageCoordinate = fullName.packageCoordinate
}

case class StructRefH(
// Unique identifier for the interface.
fullName: FullNameH
) extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = fullName.packageCoordinate
override def packageCoord(interner: Interner): PackageCoordinate = fullName.packageCoordinate
}

// An array whose size is known at compile time, and therefore doesn't need to
Expand All @@ -152,7 +151,7 @@ case class StaticSizedArrayHT(
name: FullNameH,
) extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = name.packageCoordinate
override def packageCoord(interner: Interner): PackageCoordinate = name.packageCoordinate
}

// An array whose size is known at compile time, and therefore doesn't need to
Expand All @@ -175,7 +174,7 @@ case class RuntimeSizedArrayHT(
name: FullNameH,
) extends KindH {
val hash = runtime.ScalaRunTime._hashCode(this); override def hashCode(): Int = hash;
override def packageCoord: PackageCoordinate = name.packageCoordinate
override def packageCoord(interner: Interner): PackageCoordinate = name.packageCoordinate
}

case class RuntimeSizedArrayDefinitionHT(
Expand Down
Loading

0 comments on commit 5f04754

Please sign in to comment.