Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Inference PoC - iteration 1 - most basic type inference #8652

Merged
merged 186 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
4d2c126
implement a stub for the type inference pass
radeusgd Dec 21, 2023
ba1befd
note
radeusgd Dec 21, 2023
01e8cfb
notes
radeusgd Dec 21, 2023
08a4691
ensure compiled in a cleaner way
radeusgd Dec 27, 2023
1bf418f
experiments, logging
radeusgd Dec 27, 2023
53d9d16
WIP adding more test cases, getting into the IR, deconstructing it an…
radeusgd Dec 27, 2023
1b2dc7c
adding more test cases for relatively simple but a bit more complex s…
radeusgd Dec 28, 2023
ed09456
fix doc
radeusgd Dec 28, 2023
3c451f9
ignore test for now
radeusgd Dec 28, 2023
4e183f9
document implementation detail leaking to API
radeusgd Dec 28, 2023
14571ce
very basic type propagation - literals, WIP lambdas
radeusgd Dec 28, 2023
762c338
checkpoint
radeusgd Dec 28, 2023
5167afd
ignore self in lambda type
radeusgd Dec 28, 2023
2396c31
registering ascribed types, resolving ascribed types
radeusgd Dec 28, 2023
29c3141
resolving function types and error types - in the limited way as curr…
radeusgd Dec 28, 2023
b2a6c59
refactor metadata, looking into how to resolve names
radeusgd Dec 28, 2023
a730bab
tmp
radeusgd Dec 29, 2023
6106c8d
WIP: refactoring test runner to be closer to the compiler
radeusgd Dec 29, 2023
ee20261
start actually testing stuff
radeusgd Dec 29, 2023
8e00b7a
more checks in tests
radeusgd Dec 29, 2023
ad5e8d0
all existing tests do test something, ignoring pending tests for now
radeusgd Dec 29, 2023
2f4f75b
trying to resolve ctors but it's harder than I thought
radeusgd Dec 29, 2023
86ff46d
WIP resolving type objects
radeusgd Dec 29, 2023
38ba970
first steps in resolving function application - resolving constructors
radeusgd Dec 29, 2023
a22a2d0
allow multi arg constructors as well :)
radeusgd Dec 29, 2023
db95a80
test for NotInvokable warning
radeusgd Dec 29, 2023
9816239
allow to easily turn on/off verbose logs
radeusgd Dec 29, 2023
0964c24
allow to enable type checking by CLI
radeusgd Dec 29, 2023
433765e
add test for defaulted args in ctor
radeusgd Dec 30, 2023
63427b6
do not infer ctors with defaults as currently that is not correctly h…
radeusgd Jan 2, 2024
dad9d09
WIP: persistance, not yet sure how to fix the issue of storing Expres…
radeusgd Jan 12, 2024
b3f049f
propagating local bindings
radeusgd Jan 12, 2024
c07063f
make it compile
radeusgd Jan 12, 2024
cc06f57
fix test
radeusgd Jan 12, 2024
bf3d02c
refactor
radeusgd Jan 12, 2024
16e5c3e
note
radeusgd Jan 12, 2024
05bcfdd
Vector Literal
radeusgd Jan 12, 2024
d89dda9
add test
radeusgd Jan 12, 2024
0764a70
register checked argument types
radeusgd Jan 12, 2024
4ba9cae
adding tests
radeusgd Jan 12, 2024
2cea501
inferring case pt. 1
radeusgd Jan 12, 2024
9f4e8fe
inferring case pt. 2
radeusgd Jan 12, 2024
433bb2f
case sum type
radeusgd Jan 12, 2024
4a0f88c
add a test
radeusgd Jan 12, 2024
7e1555d
adding more tests, stub for type errors, add inferred type to bindings
radeusgd Jan 13, 2024
5191ef3
very basic type errors
radeusgd Jan 13, 2024
3c3fc2c
disable logging
radeusgd Jan 13, 2024
9cbf216
add test for conversion
radeusgd Jan 18, 2024
6886328
add test for spurious Not_Invokable warnign
radeusgd Jan 18, 2024
cbccd55
adding tests, disable type errors due to conversions
radeusgd Jan 18, 2024
3953d28
add type error test that can be checked even without conversions
radeusgd Jan 18, 2024
702ccea
weird but possible
radeusgd Jan 18, 2024
db55e4a
fix
radeusgd Jan 18, 2024
8a24387
refactor local bindings map
radeusgd Jan 19, 2024
40d3a90
move out TypeCompatibility
radeusgd Jan 19, 2024
d984bc1
simplify logging
radeusgd Jan 19, 2024
960af5b
simplify logging - {}
radeusgd Jan 19, 2024
77c7a5b
javafmt
radeusgd Jan 19, 2024
e2607b7
reducing coupling: avoid storing Bindings Map in the Type representation
radeusgd Mar 2, 2024
2bfefb4
WIP: remove IR from TypeRepresentation, abstracting ResolvedType for …
radeusgd Mar 2, 2024
9a5f46e
debug
radeusgd Mar 4, 2024
3b8e16c
add test for resolving symbols thru local module name
radeusgd Mar 4, 2024
a8cc0dc
fix local resolution
radeusgd Mar 4, 2024
6641c39
updating tests, note
radeusgd Mar 4, 2024
fd9cbfd
comments
radeusgd Mar 4, 2024
330530c
switch to Reference for Expression
radeusgd Mar 7, 2024
c82dcfa
not prepare
radeusgd Mar 7, 2024
73b30d8
detect cycles
radeusgd Mar 8, 2024
d12a53e
revert cycle detector
radeusgd Mar 8, 2024
43150c1
break cycles by registering the object _before_ it is written
radeusgd Mar 8, 2024
ef66976
WIP: testing consistency
radeusgd Mar 15, 2024
6438caa
fix test
radeusgd Mar 15, 2024
9882d91
draft for common NameResolution logic
radeusgd Mar 15, 2024
0b70aae
use common NameResolution in IrToTruffle
radeusgd Mar 15, 2024
044ddef
use common NameResolution in TypeInference
radeusgd Mar 15, 2024
4133e7f
fixes after rebase
radeusgd Mar 15, 2024
482f016
fixes after AliasAnalysis -unnest rebase
radeusgd Mar 18, 2024
c28b734
'interop' helpers now no longer necessary
radeusgd Mar 18, 2024
9014552
fix: now the qualified type name is correctly discovering the relevan…
radeusgd Mar 21, 2024
18eb854
fix NPE
radeusgd Mar 22, 2024
dbb6aeb
WIP adding test but it doesn't work for a different reason
radeusgd Mar 22, 2024
00f9a2f
Revert "break cycles by registering the object _before_ it is written"
radeusgd Mar 26, 2024
0f7158f
Revert "revert cycle detector"
radeusgd Mar 26, 2024
31e7733
name in cycle detector
radeusgd Mar 26, 2024
39943a7
update test (weird?)
radeusgd Mar 26, 2024
9945303
remove old logs
radeusgd Mar 26, 2024
970f807
add missing branches, handle type application
radeusgd Mar 27, 2024
8bd1e78
revert back to keeping Type in TypeObject
radeusgd Mar 27, 2024
5d1bb20
remove now unused PackageRepo resolution logic
radeusgd Mar 27, 2024
e3629cf
WIP
radeusgd Mar 27, 2024
7723a50
update tests
radeusgd Mar 27, 2024
0534947
javafmt
radeusgd Mar 27, 2024
b96bcd8
update ()
radeusgd Mar 27, 2024
eefde02
note
radeusgd Mar 27, 2024
039c27a
make the logic less imperative
radeusgd Mar 27, 2024
723e5db
investigating weird behaviour of imports in tests
radeusgd Mar 27, 2024
d8626f3
move tests to right place
radeusgd Mar 27, 2024
978dc64
remove unnecessary debug print
radeusgd Mar 27, 2024
34ca2dd
unify Any instantiate, special case for Function type
radeusgd Mar 27, 2024
e61021a
case for polyglot symbol
radeusgd Mar 27, 2024
fbb8d2f
CR: rename NameResolution -> NameResolutionAlgorithm
radeusgd Mar 28, 2024
5e4de83
refactoring: modularize the inference logic
radeusgd Mar 28, 2024
d8e8296
update cache version number
radeusgd Mar 28, 2024
71d5f34
docs
radeusgd Mar 28, 2024
425f5ca
warn -> debug
radeusgd Mar 28, 2024
9339481
cleanup
radeusgd Mar 28, 2024
84585bd
cleanup, docs
radeusgd Mar 28, 2024
2f1fa5b
fix a test
radeusgd Mar 28, 2024
1dae00c
javafmt
radeusgd Mar 28, 2024
6644057
scalafmt
radeusgd Mar 28, 2024
90a5ab4
remove debug function
radeusgd Mar 28, 2024
50e76a1
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd Apr 12, 2024
cc10f40
CR: remove comment about warning
radeusgd Apr 12, 2024
9fccb7e
CR: rename `--enable-type-check` to `--enable-static-analysis`
radeusgd Apr 12, 2024
bfebf36
CR: remove obsolete empty file
radeusgd Apr 12, 2024
5324692
CR: make class final
radeusgd Apr 12, 2024
0a05d59
CR
radeusgd Apr 12, 2024
5293919
CR: follow up in renaming
radeusgd Apr 12, 2024
66bd462
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd Apr 12, 2024
96f01ae
CR: TODO
radeusgd Apr 12, 2024
474e186
CR: docs
radeusgd Apr 13, 2024
010dbfa
more doc
radeusgd Apr 13, 2024
732e671
more tests, fix a kind of false positive
radeusgd Apr 13, 2024
789d722
abstract away BindingsMap from TypeRepresentation in favor of AtomTyp…
radeusgd Apr 13, 2024
d804f58
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd Apr 19, 2024
b14f504
CR: final
radeusgd Apr 20, 2024
1040af8
CR: remove Optional
radeusgd Apr 20, 2024
70edb41
javafmt
radeusgd Apr 20, 2024
d00736a
remove unused
radeusgd Apr 20, 2024
d3bb4ea
CR: avoid storing metadata for intermediate nodes
radeusgd Apr 20, 2024
351dc86
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd Apr 26, 2024
0df7b8c
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd Apr 27, 2024
bd17b67
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd May 2, 2024
6c600ba
re-add removed static analysis CLI option after merge
radeusgd May 2, 2024
7f97cc5
fix moved ctor after merge
radeusgd May 2, 2024
3a71796
suppress warning
radeusgd May 2, 2024
94febc1
fix test after merge
radeusgd May 2, 2024
ac6fafd
fmt after merge
radeusgd May 2, 2024
a8282e3
fmt 2
radeusgd May 2, 2024
2ef91da
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd May 6, 2024
74ba7cd
fix after merge
radeusgd May 6, 2024
e7cd8b8
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd May 6, 2024
d550285
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd May 11, 2024
dff0b20
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd May 23, 2024
1a0462a
Persistance.Reference fails to serialize if stored in Option. Could b…
radeusgd May 23, 2024
d08f80a
add test for storing NULL reference
radeusgd May 23, 2024
caf213a
fix storing NULL references
radeusgd May 23, 2024
4a7e358
add test for serializing a deserialized loop (it used to be failing)
radeusgd May 24, 2024
b867051
try fixing by making the writer aware of the inner type of the Reference
radeusgd May 24, 2024
86a08a4
simplify supertype search
radeusgd May 24, 2024
db4ec13
Revert "try fixing by making the writer aware of the inner type of th…
radeusgd May 24, 2024
6600f60
store Persistance Ids next to references
radeusgd May 24, 2024
d073c3d
add debug info
radeusgd May 24, 2024
63f4e8a
enable asserts in persistance tests
radeusgd May 27, 2024
4c7e444
fix sizes after protocol update
radeusgd May 27, 2024
fb3f6ce
rename for clarity
radeusgd May 27, 2024
8376869
introduce InlineReference
radeusgd May 27, 2024
3d9bd75
better error message
radeusgd May 27, 2024
57d98bf
move java List persistance to IrPersistance
radeusgd May 27, 2024
ca1fd9d
count InlineReferences instead of Sequences
radeusgd May 27, 2024
6d68b8a
update test
radeusgd May 27, 2024
12e7cf3
ensure persistance of List and Seq is aligned
radeusgd May 27, 2024
65adea6
cleanup after cherry pick
radeusgd May 27, 2024
f50063b
update count at the right moment
radeusgd May 27, 2024
e74d7ea
cleanup
radeusgd May 27, 2024
1de43b1
null
radeusgd May 27, 2024
1a2b251
Avoid storing unnecessary integer for NULL references, make the code …
radeusgd May 27, 2024
f0e9ffa
Merge branch 'refs/heads/develop' into wip/radeusgd/cycles-in-persist…
radeusgd May 28, 2024
6e2ea8c
Exposing just a single Persistance.Reference abstraction
JaroslavTulach May 28, 2024
c1c0a26
Reference.of(obj, deferredWrite)
JaroslavTulach May 28, 2024
6a2409d
Encapsulating Reference serde in PerReferencePeristance
JaroslavTulach May 29, 2024
e22dd5c
Merge branch 'wip/jtulach/cycles-in-persistance-followup+' into wip/r…
radeusgd Jun 1, 2024
0b2012b
CHANGELOG.md
radeusgd May 25, 2024
49a702d
add missing persistance for TypeInference pass
radeusgd May 24, 2024
514c6a9
add test for persistance of type metadata
radeusgd May 27, 2024
ba1b504
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd Jun 10, 2024
414aeb8
integrate back changes from #9914 after merge commit
radeusgd Jun 10, 2024
8163e52
yet another update after merge
radeusgd Jun 10, 2024
33c357c
more fixes after merge
radeusgd Jun 10, 2024
10f71e0
fixes
radeusgd Jun 10, 2024
1cd8421
reintroduce defer write - was lost after merge...
radeusgd Jun 10, 2024
ae598de
formatting
radeusgd Jun 10, 2024
caf025b
Merge branch 'refs/heads/develop' into wip/radeusgd/8590-prototype-ty…
radeusgd Jun 13, 2024
142a58d
cleanup tests between each case - to avoid one failure causing 10 more
radeusgd Jun 13, 2024
b958ec6
increase timeout on a failing test
radeusgd Jun 13, 2024
f3d16a2
yet another bump
radeusgd Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class RuntimeOptions {
private static final OptionDescriptor DISABLE_PRIVATE_CHECK_DESCRIPTOR =
OptionDescriptor.newBuilder(DISABLE_PRIVATE_CHECK_KEY, DISABLE_PRIVATE_CHECK).build();

public static final String ENABLE_STATIC_ANALYSIS = optionName("enableStaticAnalysis");
public static final OptionKey<Boolean> ENABLE_STATIC_ANALYSIS_KEY = new OptionKey<>(false);
private static final OptionDescriptor ENABLE_STATIC_ANALYSIS_DESCRIPTOR =
OptionDescriptor.newBuilder(ENABLE_STATIC_ANALYSIS_KEY, ENABLE_STATIC_ANALYSIS).build();

public static final String ENABLE_AUTO_PARALLELISM = optionName("withAutoParallelism");
public static final OptionKey<Boolean> ENABLE_AUTO_PARALLELISM_KEY = new OptionKey<>(false);
private static final OptionDescriptor ENABLE_AUTO_PARALLELISM_DESCRIPTOR =
Expand Down Expand Up @@ -145,6 +150,7 @@ public class RuntimeOptions {
LOG_MASKING_DESCRIPTOR,
DISABLE_INLINE_CACHES_DESCRIPTOR,
DISABLE_PRIVATE_CHECK_DESCRIPTOR,
ENABLE_STATIC_ANALYSIS_DESCRIPTOR,
ENABLE_AUTO_PARALLELISM_DESCRIPTOR,
ENABLE_PROJECT_SUGGESTIONS_DESCRIPTOR,
ENABLE_GLOBAL_SUGGESTIONS_DESCRIPTOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @param logLevel the log level for this context
* @param enableIrCaches whether or not IR caching should be enabled
* @param disablePrivateCheck If `private` keyword should be disabled.
* @param enableStaticAnalysis whether or not to enable static type checking
* @param strictErrors whether or not to use strict errors
* @param useGlobalIrCacheLocation whether or not to use the global IR cache location
* @param options additional options for the Context
Expand All @@ -42,6 +43,7 @@ final class ContextFactory {
private boolean logMasking;
private boolean enableIrCaches;
private boolean disablePrivateCheck;
private boolean enableStaticAnalysis;
private boolean strictErrors;
private boolean useGlobalIrCacheLocation = true;
private boolean enableAutoParallelism;
Expand Down Expand Up @@ -95,6 +97,11 @@ public ContextFactory disablePrivateCheck(boolean disablePrivateCheck) {
return this;
}

public ContextFactory enableStaticAnalysis(boolean enableStaticAnalysis) {
this.enableStaticAnalysis = enableStaticAnalysis;
return this;
}

public ContextFactory strictErrors(boolean strictErrors) {
this.strictErrors = strictErrors;
return this;
Expand Down Expand Up @@ -144,6 +151,7 @@ PolyglotContext build() {
Boolean.toString(useGlobalIrCacheLocation))
.option(RuntimeOptions.DISABLE_IR_CACHES, Boolean.toString(!enableIrCaches))
.option(RuntimeOptions.DISABLE_PRIVATE_CHECK, Boolean.toString(disablePrivateCheck))
.option(RuntimeOptions.ENABLE_STATIC_ANALYSIS, Boolean.toString(enableStaticAnalysis))
.option(DebugServerInfo.ENABLE_OPTION, "true")
.option(RuntimeOptions.LOG_MASKING, Boolean.toString(logMasking))
.options(options)
Expand Down
38 changes: 34 additions & 4 deletions engine/runner/src/main/java/org/enso/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public final class Main {
private static final String NO_IR_CACHES_OPTION = "no-ir-caches";
private static final String NO_READ_IR_CACHES_OPTION = "no-read-ir-caches";
private static final String DISABLE_PRIVATE_CHECK_OPTION = "disable-private-check";
private static final String ENABLE_STATIC_ANALYSIS_OPTION = "enable-static-analysis";
private static final String COMPILE_OPTION = "compile";
private static final String NO_COMPILE_DEPENDENCIES_OPTION = "no-compile-dependencies";
private static final String NO_GLOBAL_CACHE_OPTION = "no-global-cache";
Expand Down Expand Up @@ -440,6 +441,11 @@ private static Options buildOptions() {
.longOpt(DISABLE_PRIVATE_CHECK_OPTION)
.desc("Disables private module checking at runtime. Useful for tests.")
.build();
var enableStaticAnalysisOption =
cliOptionBuilder()
.longOpt(ENABLE_STATIC_ANALYSIS_OPTION)
.desc("Enable static analysis (Experimental type inference).")
.build();

var options = new Options();
options
Expand Down Expand Up @@ -486,7 +492,8 @@ private static Options buildOptions() {
.addOption(skipGraalVMUpdater)
.addOption(executionEnvironmentOption)
.addOption(warningsLimitOption)
.addOption(disablePrivateCheckOption);
.addOption(disablePrivateCheckOption)
.addOption(enableStaticAnalysisOption);

return options;
}
Expand Down Expand Up @@ -587,13 +594,15 @@ private void createNew(
* compiled
* @param shouldUseGlobalCache whether or not the compilation result should be written to the
* global cache
* @param enableStaticAnalysis whether or not static type checking should be enabled
* @param logLevel the logging level
* @param logMasking whether or not log masking is enabled
*/
private void compile(
String packagePath,
boolean shouldCompileDependencies,
boolean shouldUseGlobalCache,
boolean enableStaticAnalysis,
Level logLevel,
boolean logMasking) {
var file = new File(packagePath);
Expand All @@ -611,6 +620,7 @@ private void compile(
.logLevel(logLevel)
.logMasking(logMasking)
.enableIrCaches(true)
.enableStaticAnalysis(enableStaticAnalysis)
.strictErrors(true)
.useGlobalIrCacheLocation(shouldUseGlobalCache)
.build();
Expand Down Expand Up @@ -640,6 +650,7 @@ private void compile(
* @param enableIrCaches are IR caches enabled
* @param disablePrivateCheck Is private modules check disabled. If yes, `private` keyword is
* ignored.
* @param enableStaticAnalysis whether or not static type checking should be enabled
* @param inspect shall inspect option be enabled
* @param dump shall graphs be sent to the IGV
* @param executionEnvironment name of the execution environment to use during execution or {@code
Expand All @@ -654,6 +665,7 @@ private void run(
boolean enableIrCaches,
boolean disablePrivateCheck,
boolean enableAutoParallelism,
boolean enableStaticAnalysis,
boolean inspect,
boolean dump,
String executionEnvironment,
Expand Down Expand Up @@ -686,6 +698,7 @@ private void run(
.disablePrivateCheck(disablePrivateCheck)
.strictErrors(true)
.enableAutoParallelism(enableAutoParallelism)
.enableStaticAnalysis(enableStaticAnalysis)
.executionEnvironment(executionEnvironment != null ? executionEnvironment : "live")
.warningsLimit(warningsLimit)
.options(options)
Expand Down Expand Up @@ -867,9 +880,14 @@ private void runMain(
* @param logLevel log level to set for the engine runtime
* @param logMasking is the log masking enabled
* @param enableIrCaches are IR caches enabled
* @param enableStaticAnalysis whether or not static type checking should be enabled
*/
private void runRepl(
String projectPath, Level logLevel, boolean logMasking, boolean enableIrCaches) {
String projectPath,
Level logLevel,
boolean logMasking,
boolean enableIrCaches,
boolean enableStaticAnalysis) {
var mainMethodName = "internal_repl_entry_point___";
var dummySourceToTriggerRepl =
"""
Expand All @@ -890,6 +908,7 @@ private void runRepl(
.logLevel(logLevel)
.logMasking(logMasking)
.enableIrCaches(enableIrCaches)
.enableStaticAnalysis(enableStaticAnalysis)
.build();
var mainModule = context.evalModule(dummySourceToTriggerRepl, replModuleName);
runMain(mainModule, null, Collections.emptyList(), mainMethodName);
Expand Down Expand Up @@ -1032,7 +1051,13 @@ private void runMain(Options options, CommandLine line, Level logLevel, boolean
var shouldCompileDependencies = !line.hasOption(NO_COMPILE_DEPENDENCIES_OPTION);
var shouldUseGlobalCache = !line.hasOption(NO_GLOBAL_CACHE_OPTION);

compile(packagePaths, shouldCompileDependencies, shouldUseGlobalCache, logLevel, logMasking);
compile(
packagePaths,
shouldCompileDependencies,
shouldUseGlobalCache,
line.hasOption(ENABLE_STATIC_ANALYSIS_OPTION),
logLevel,
logMasking);
}

if (line.hasOption(RUN_OPTION)) {
Expand All @@ -1045,6 +1070,7 @@ private void runMain(Options options, CommandLine line, Level logLevel, boolean
shouldEnableIrCaches(line),
line.hasOption(DISABLE_PRIVATE_CHECK_OPTION),
line.hasOption(AUTO_PARALLELISM_OPTION),
line.hasOption(ENABLE_STATIC_ANALYSIS_OPTION),
line.hasOption(INSPECT_OPTION),
line.hasOption(DUMP_GRAPHS_OPTION),
line.getOptionValue(EXECUTION_ENVIRONMENT_OPTION),
Expand All @@ -1054,7 +1080,11 @@ private void runMain(Options options, CommandLine line, Level logLevel, boolean
}
if (line.hasOption(REPL_OPTION)) {
runRepl(
line.getOptionValue(IN_PROJECT_OPTION), logLevel, logMasking, shouldEnableIrCaches(line));
line.getOptionValue(IN_PROJECT_OPTION),
logLevel,
logMasking,
shouldEnableIrCaches(line),
line.hasOption(ENABLE_STATIC_ANALYSIS_OPTION));
}
if (line.hasOption(DOCS_OPTION)) {
genDocs(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.enso.compiler;

import org.enso.compiler.core.IR;
import org.enso.compiler.core.ir.ProcessingPass;
import org.enso.compiler.pass.IRPass;
import scala.Option;

/**
* A set of helper methods for handling of IR metadata.
*
* <p>This encapsulates the friction of interop between Scala and Java types.
*/
public final class MetadataInteropHelpers {
public static <T> T getMetadataOrNull(IR ir, IRPass pass, Class<T> expectedType) {
Option<ProcessingPass.Metadata> option = ir.passData().get(pass);
if (option.isDefined()) {
try {
return expectedType.cast(option.get());
} catch (ClassCastException exception) {
throw new IllegalStateException(
"Unexpected metadata type "
+ option.get().getClass().getCanonicalName()
+ " "
+ "for "
+ pass,
exception);
}
} else {
return null;
}
}

public static <T> T getMetadata(IR ir, IRPass pass, Class<T> expectedType) {
T metadataOrNull = getMetadataOrNull(ir, pass, expectedType);
if (metadataOrNull == null) {
throw new IllegalStateException("Missing expected " + pass + " metadata for " + ir + ".");
}

return metadataOrNull;
}

private MetadataInteropHelpers() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.enso.compiler.context;

import org.enso.compiler.MetadataInteropHelpers;
import org.enso.compiler.core.ConstantsNames;
import org.enso.compiler.core.ir.Name;
import org.enso.compiler.data.BindingsMap;
import org.enso.compiler.pass.analyse.AliasAnalysis$;
import org.enso.compiler.pass.analyse.alias.Info;
import org.enso.compiler.pass.resolve.GlobalNames$;
import scala.Option;

/**
* Encapsulates the logic for resolving a variable name.
*
* <p>The same logic is needed in two places:
*
* <ol>
* <li>in the runtime ({@link org.enso.interpreter.runtime.IrToTruffle.processName}),
* <li>in the type checker ({@link
* org.enso.compiler.pass.analyse.types.TypeInference.processName}).
* </ol>
*
* <p>To ensure that all usages stay consistent, they should all rely on the logic implemented in
* this class, customizing it to the specific needs of the context in which it is used.
*
* @param <ResultType> The result type of the resolution process.
* @param <LocalNameLinkType> The type describing a link to a local name in a current scope.
* Depending on the context this may be a Graph.Link (in the compiler) or a FramePointer (in the
* runtime).
*/
public abstract class NameResolutionAlgorithm<ResultType, LocalNameLinkType> {
public final ResultType resolveName(Name.Literal name) {
Info.Occurrence occurrenceMetadata =
MetadataInteropHelpers.getMetadata(name, AliasAnalysis$.MODULE$, Info.Occurrence.class);
var maybeLocalLink = findLocalLink(occurrenceMetadata);
if (maybeLocalLink.isDefined()) {
return resolveLocalName(maybeLocalLink.get());
}

BindingsMap.Resolution global =
MetadataInteropHelpers.getMetadataOrNull(
name, GlobalNames$.MODULE$, BindingsMap.Resolution.class);
if (global != null) {
BindingsMap.ResolvedName resolution = global.target();
return resolveGlobalName(resolution);
}

if (name.name().equals(ConstantsNames.FROM_MEMBER)) {
return resolveFromConversion();
}

return resolveUnresolvedSymbol(name.name());
}

protected abstract Option<LocalNameLinkType> findLocalLink(Info.Occurrence occurrenceMetadata);
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved

protected abstract ResultType resolveLocalName(LocalNameLinkType localLink);

protected abstract ResultType resolveGlobalName(BindingsMap.ResolvedName resolvedName);

protected abstract ResultType resolveFromConversion();

protected abstract ResultType resolveUnresolvedSymbol(String symbolName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import org.enso.compiler.pass.analyse.alias.Graph;
import org.enso.compiler.pass.analyse.alias.Info;
import org.enso.compiler.pass.analyse.types.TypeInference;
import org.enso.compiler.pass.resolve.DocumentationComments;
import org.enso.compiler.pass.resolve.DocumentationComments$;
import org.enso.compiler.pass.resolve.ExpressionAnnotations$;
Expand Down Expand Up @@ -74,6 +75,7 @@
id = 1265,
allowInlining = false)
@Persistable(clazz = Graph.Link.class, id = 1266, allowInlining = false)
@Persistable(clazz = TypeInference.class, id = 1280)
public final class PassPersistance {
private PassPersistance() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.enso.compiler.pass.analyse.types;

import java.util.List;

/**
* Describes the visible interface of an Atom Type.
*
* <p>This interface declares what methods can be called on instances of that type (or statically)
* and what constructors may be called on it to create new instances.
*/
interface AtomTypeInterface {
List<? extends Constructor> constructors();

interface Constructor {
String name();

List<? extends Argument> arguments();
}

interface Argument {
String name();

boolean hasDefaultValue();

/**
* The ascribed type of the argument.
*
* <p>It may be {@code null} if the type is not known.
*/
TypeRepresentation getType(TypeResolver resolver);
}

// TODO in next iteration: static and member methods
}
Loading
Loading