Skip to content

Commit

Permalink
Merge pull request #634 from Verdagon/master
Browse files Browse the repository at this point in the history
Fixes for ARM, VmdSiteGen, and linear types.
  • Loading branch information
Verdagon authored May 14, 2024
2 parents 4009c50 + a20de9a commit 6fb9832
Show file tree
Hide file tree
Showing 69 changed files with 691 additions and 228 deletions.
1 change: 1 addition & 0 deletions Backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS
Support
IRReader
Passes
aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info
x86asmparser x86codegen x86desc x86disassembler x86info
webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo
)
Expand Down
4 changes: 4 additions & 0 deletions Backend/setupclion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
open preferences -> Build,Execution,Deployment -> CMake

add this to the profile's CMake Options field:
-G "Unix Makefiles" -DLLVM_DIR=/Users/verdagon/clang+llvm-16.0.4-arm64-apple-darwin22.0/lib/cmake/llvm
6 changes: 6 additions & 0 deletions Backend/src/vale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,12 @@ LLVMTargetMachineRef createMachine(ValeOptions *opt) {
LLVMInitializeX86AsmPrinter();
LLVMInitializeX86AsmParser();

LLVMInitializeAArch64TargetInfo();
LLVMInitializeAArch64TargetMC();
LLVMInitializeAArch64Target();
LLVMInitializeAArch64AsmPrinter();
LLVMInitializeAArch64AsmParser();

LLVMInitializeWebAssemblyTargetInfo();
LLVMInitializeWebAssemblyTargetMC();
LLVMInitializeWebAssemblyTarget();
Expand Down
13 changes: 12 additions & 1 deletion Coordinator/src/build.vale
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
Flag(
"--clang_override",
FLAG_STR(),
"Path to the clang binary to ue for linking.",
"Path to the clang binary to use for linking.",
"clang",
"Alternate path for the clang binary to use."),
Flag(
"--libc_override",
FLAG_STR(),
"Path to libc folder.",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr",
"Path to libc folder which contains lib and include."),
Flag(
"--benchmark",
FLAG_BOOL(),
Expand Down Expand Up @@ -317,6 +323,7 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
}

maybe_clang_path_override = parsed_flags.get_string_flag("--clang_override");
maybe_libc_path_override = parsed_flags.get_string_flag("--libc_override");

output_dir = Path(parsed_flags.get_string_flag("--output_dir", "build"));

Expand Down Expand Up @@ -606,6 +613,7 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
invoke_clang(
windows,
&maybe_clang_path_override,
&maybe_libc_path_override,
&clang_inputs,
&executable_name,
asan,
Expand All @@ -618,4 +626,7 @@ func build_stuff(compiler_dir &Path, all_args &Array<imm, str>) {
if clang_return_code != 0 {
panic("clang returned error code {clang_return_code}, aborting.");
}
if verbose {
println("Done!");
}
}
23 changes: 20 additions & 3 deletions Coordinator/src/clang.vale
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import stdlib.os.*;
func invoke_clang(
windows bool,
maybe_clang_path_override &Opt<str>,
maybe_libc_path_override &Opt<str>,
clang_inputs &List<Path>,
exe_name str,
asan bool,
Expand All @@ -13,9 +14,9 @@ func invoke_clang(
Subprocess {
program =
if maybe_clang_path_override.isEmpty() {
if (windows) {
"cl.exe"
} else {
if (windows) {
"cl.exe"
} else {
"clang"
}
} else {
Expand All @@ -28,6 +29,16 @@ Subprocess {

args.add("-I" + output_dir./("include").str());

if not maybe_libc_path_override.isEmpty() {
libc_path_str = maybe_libc_path_override.get();
libc_path = Path(libc_path_str);
if not libc_path.exists() {
panic("libc override dir doesn't exist: " + libc_path.str());
}
args.add("-I" + libc_path./("include").str());
args.add("-L" + libc_path./("lib").str());
}

if (windows) {
args.add("/ENTRY:\"main\"");
args.add("/SUBSYSTEM:CONSOLE");
Expand Down Expand Up @@ -58,6 +69,12 @@ Subprocess {
args.add("-g");
}

// DO NOT SUBMIT take these out, this is a workaround for
// how our subprocess code doesn't handle stderr output well or something.
args.add("-Wno-nullability-completeness");
args.add("-Wno-availability");
args.add("-Wno-format");

if (pic) {
args.add("-fPIC");
}
Expand Down

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

9 changes: 9 additions & 0 deletions Frontend/.idea/libraries/scala_reflect_2_12_8.xml

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

2 changes: 1 addition & 1 deletion Frontend/.idea/misc.xml

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

4 changes: 2 additions & 2 deletions Frontend/Builtins/Builtins.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/dev/vale/resources" type="java-resource" />
</content>
<orderEntry type="jdk" jdkName="temurin-20" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Utils" />
<orderEntry type="module" module-name="Von" />
<orderEntry type="library" name="scala-sdk-2.12.17" level="application" />
<orderEntry type="library" name="scala-sdk-2.12.19" level="application" />
</component>
</module>
4 changes: 2 additions & 2 deletions Frontend/CompileOptions/CompileOptions.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="temurin-20" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="scala-sdk-2.12.17" level="application" />
<orderEntry type="library" name="scala-sdk-2.12.19" level="application" />
</component>
</module>
4 changes: 2 additions & 2 deletions Frontend/FinalAST/FinalAST.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="temurin-20" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Utils" />
<orderEntry type="module" module-name="Von" />
<orderEntry type="module" module-name="TypingPass" />
<orderEntry type="library" name="scala-sdk-2.12.17" level="application" />
<orderEntry type="library" name="scala-sdk-2.12.19" level="application" />
</component>
</module>
4 changes: 2 additions & 2 deletions Frontend/HigherTypingPass/HigherTypingPass.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="temurin-20" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Highlighter" />
<orderEntry type="module" module-name="ParsingPass" />
Expand All @@ -17,6 +17,6 @@
<orderEntry type="module" module-name="Solver" />
<orderEntry type="module" module-name="CompileOptions" />
<orderEntry type="module" module-name="LexingPass" />
<orderEntry type="library" name="scala-sdk-2.12.17" level="application" />
<orderEntry type="library" name="scala-sdk-2.12.19" level="application" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.vale.highertyping

import scala.sys.process.Process
import dev.vale
import dev.vale.highertyping.HigherTypingPass.explicifyLookups
import dev.vale.lexing.{FailedParse, RangeL}
Expand Down Expand Up @@ -732,6 +733,20 @@ class HigherTypingPass(globalOptions: GlobalOptions, interner: Interner, keyword
programsS.flatMap(_.exports).toVector,
programsS.flatMap(_.imports).toVector))
})
val imports = mergedProgramS.packageCoordToContents.values.flatMap(_.imports)
// val rustImports = imports.filter(_.moduleName == keywords.rust)
// rustImports.foreach({
// case ImportS(_, moduleName, packageNames, importeeName) => {
// val rustPackageString = packageNames.map(_.str).mkString(".")
//
// // ask a rust process to generate the json
// // DO NOT SUBMIT
// val processBuilder = Process("glass", List("/Users/verdagon/.cargo/bin/rustc", rustPackageString, importeeName.str))
// val process = processBuilder.run
// // Blocks
// process.exitValue()
// }
// })

// val orderedModules = orderModules(mergedProgramS)

Expand Down
4 changes: 2 additions & 2 deletions Frontend/Highlighter/Highlighter.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="temurin-20" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="ParsingPass" />
<orderEntry type="module" module-name="Utils" />
<orderEntry type="library" name="org.scalatest:scalatest_2.12:3.0.8" level="project" />
<orderEntry type="module" module-name="CompileOptions" />
<orderEntry type="module" module-name="LexingPass" />
<orderEntry type="library" name="scala-sdk-2.12.17" level="application" />
<orderEntry type="library" name="scala-sdk-2.12.19" level="application" />
</component>
</module>
4 changes: 2 additions & 2 deletions Frontend/InstantiatingPass/InstantiatingPass.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="temurin-20" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Utils" />
<orderEntry type="module" module-name="TypingPass" />
Expand All @@ -18,6 +18,6 @@
<orderEntry type="library" name="org.scalatest:scalatest_2.12:3.0.8" level="project" />
<orderEntry type="module" module-name="Builtins" />
<orderEntry type="module" module-name="Tests" />
<orderEntry type="library" name="scala-sdk-2.12.17" level="application" />
<orderEntry type="library" name="scala-sdk-2.12.19" level="application" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,12 @@ class Instantiator(
// - ri$J -> dis$J
implPlaceholderToDispatcherPlaceholder
.find(_._2 == dispatcherPlaceholderTemplata))._1
val IdT(_, _, KindPlaceholderNameT(KindPlaceholderTemplateNameT(index, rune))) = implPlaceholder
val index =
implPlaceholder match {
case IdT(_, _, KindPlaceholderNameT(KindPlaceholderTemplateNameT(index, rune))) => index
case IdT(_, _, NonKindNonRegionPlaceholderNameT(index, rune)) => index
case other => vwat(other)
}
// Here we're grabbing it from the instantiated impl that we're overriding, here ri<bool, str>.
val templataC = implIdC.localName.templateArgs(index)
// This is a collapsed, but it needs to be subjective from this dispatcher's perspective.
Expand Down Expand Up @@ -1373,29 +1378,39 @@ class Instantiator(
case IdT(_, _, last) => {
last match {
case LambdaCallFunctionNameT(_, _, _) => {
(denizenName.steps.last, desiredPrototypeS.id.steps.init.init.last) match {
case (
FunctionNameT(FunctionTemplateNameT(nameA,codeLocA),templateArgsA,parametersA),
FunctionNameIX(FunctionTemplateNameI(nameB,codeLocB),templateArgsB,parametersB)) => {
// Make sure we're talking about roughly the same function
vassert(nameA == nameB)
vassert(codeLocA == codeLocB)
vassert(templateArgsA.length == templateArgsB.length)
vassert(parametersA.length == parametersB.length)
// Could we have a false positive here if we're doing things on different templates?
// I don't think so.
}
case (
LambdaCallFunctionNameT(LambdaCallFunctionTemplateNameT(codeLocA,paramsTTA),templateArgsA,parametersA),
LambdaCallFunctionNameI(LambdaCallFunctionTemplateNameI(codeLocB,paramsTTB),templateArgsB,parametersB)) => {
// Make sure we're talking about roughly the same function
vassert(codeLocA == codeLocB)
vassert(paramsTTA == paramsTTB)
vassert(templateArgsA.length == templateArgsB.length)
vassert(parametersA.length == parametersB.length)
}
case other => vwat(other)
}
// Lambdas Can Call Sibling Lambdas (LCCSL)
// If we want to call a lambda, there are three possibilities I've seen:
// - We're in the root denizen and we want to call our own lambda.
// - We're in a lambda and we want to call an even deeper lambda.
// - (This is the weird one) we want to call a *sibling* lambda.
// In all cases, make sure the denizen roots of everyone agree.
val denizenRootSuperTemplate = TemplataCompiler.getRootSuperTemplate(interner, denizenName)
val desiredPrototypeRootSuperTemplate = TemplataCompiler.getRootSuperTemplate(interner, desiredPrototypeT.id)
vassert(denizenRootSuperTemplate == desiredPrototypeRootSuperTemplate)

// (denizenName.steps.last, desiredPrototypeS.id.steps.init.init.last) match {
// case (
// FunctionNameT(FunctionTemplateNameT(nameA,codeLocA),templateArgsA,parametersA),
// FunctionNameIX(FunctionTemplateNameI(nameB,codeLocB),templateArgsB,parametersB)) => {
// // Make sure we're talking about roughly the same function
// vassert(nameA == nameB)
// vassert(codeLocA == codeLocB)
// vassert(templateArgsA.length == templateArgsB.length)
// vassert(parametersA.length == parametersB.length)
// // Could we have a false positive here if we're doing things on different templates?
// // I don't think so.
// }
// case (
// LambdaCallFunctionNameT(LambdaCallFunctionTemplateNameT(codeLocA,paramsTTA),templateArgsA,parametersA),
// LambdaCallFunctionNameI(LambdaCallFunctionTemplateNameI(codeLocB,paramsTTB),templateArgsB,parametersB)) => {
// // Make sure we're talking about roughly the same function
// vassert(codeLocA == codeLocB)
// vassert(paramsTTA == paramsTTB)
// vassert(templateArgsA.length == templateArgsB.length)
// vassert(parametersA.length == parametersB.length)
// }
// case other => vwat(other)
// }
}
case _ =>
}
Expand Down
4 changes: 2 additions & 2 deletions Frontend/IntegrationTests/IntegrationTests.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<sourceFolder url="file://$MODULE_DIR$/test/main/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="temurin-20" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="HigherTypingPass" />
<orderEntry type="module" module-name="PassManager" />
Expand All @@ -25,7 +25,7 @@
<orderEntry type="module" module-name="Builtins" />
<orderEntry type="module" module-name="CompileOptions" />
<orderEntry type="module" module-name="LexingPass" />
<orderEntry type="library" name="scala-sdk-2.12.17" level="application" />
<orderEntry type="module" module-name="InstantiatingPass" />
<orderEntry type="library" name="scala-sdk-2.12.19" level="application" />
</component>
</module>
1 change: 0 additions & 1 deletion Frontend/IntegrationTests/test/dev/vale/ArrayTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.vale

import com.sun.tools.javac.util.ArrayUtils
import dev.vale.parsing.ast.ImmutableP
import dev.vale.typing.NewImmRSANeedsCallable
import dev.vale.typing.ast.{LetNormalTE, NewImmRuntimeSizedArrayTE, RuntimeSizedArrayLookupTE, StaticSizedArrayLookupTE}
Expand Down
15 changes: 15 additions & 0 deletions Frontend/IntegrationTests/test/dev/vale/IntegrationTestsA.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,21 @@ class IntegrationTestsA extends FunSuite with Matchers {
compile.evalForKind(Vector()) match { case VonBool(false) => }
}

// See LCCSL
test("Lambda can call sibling lambda") {
val compile = RunCompilation.test(
"""
|exported func main() int {
| continueF = (x) => { x };
| barkF = (x) => { continueF(x) };
| return barkF(42);
|}
""".stripMargin)
compile.evalForKind(Vector()) match {
case VonInt(42) =>
}
}

test("set swapping locals") {
val compile = RunCompilation.test(Tests.loadExpected("programs/mutswaplocals.vale"))
compile.evalForKind(Vector()) match { case VonInt(42) => }
Expand Down
Loading

0 comments on commit 6fb9832

Please sign in to comment.