Skip to content

Commit 545db47

Browse files
Remove duplicated IR ASTs for static methods (#13962)
Implements the newly specified behavior of method invocations from #13961. Co-authored-by: Jaroslav Tulach <[email protected]>
1 parent 75bd540 commit 545db47

File tree

44 files changed

+1932
-1045
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1932
-1045
lines changed

distribution/lib/Standard/Base/0.0.0-dev/docs/api/Data/Numbers.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@
8686
- sqrt self -> Standard.Base.Any.Any
8787
- tan self -> Standard.Base.Any.Any
8888
- tanh self -> Standard.Base.Any.Any
89+
- Standard.Base.Data.Numbers.Positive_Integer.new integer:Standard.Base.Data.Numbers.Integer -> Standard.Base.Any.Any
8990
- Standard.Base.Data.Numbers.Float.from that:Standard.Base.Data.Numbers.Integer -> Standard.Base.Data.Numbers.Float
9091
- type Number_Parse_Error
9192
- Error text:Standard.Base.Any.Any
9293
- to_display_text self -> Standard.Base.Any.Any
94+
- Standard.Base.Data.Numbers.Integer.from that:Standard.Base.Data.Numbers.Positive_Integer -> Standard.Base.Data.Numbers.Integer
9395
- type Positive_Integer
9496
- Value integer:Standard.Base.Data.Numbers.Integer
9597
- new integer:Standard.Base.Data.Numbers.Integer -> Standard.Base.Any.Any
9698
- Standard.Base.Data.Numbers.Positive_Integer.from that:Standard.Base.Data.Numbers.Integer -> Standard.Base.Data.Numbers.Positive_Integer
97-
- Standard.Base.Data.Numbers.Integer.from that:Standard.Base.Data.Numbers.Positive_Integer -> Standard.Base.Data.Numbers.Integer
9899
- Standard.Base.Data.Ordering.Comparable.from that:Standard.Base.Data.Numbers.Positive_Integer -> Standard.Base.Data.Ordering.Comparable

distribution/lib/Standard/Base/0.0.0-dev/docs/api/Data/Ordering.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
- >= self that:Standard.Base.Data.Ordering.Comparable -> Standard.Base.Data.Boolean.Boolean!Standard.Base.Errors.Common.Incomparable_Values
88
- new value:Standard.Base.Any.Any comparator:Standard.Base.Any.Any -> Standard.Base.Data.Ordering.Comparable
99
- Standard.Base.Data.Ordering.Ordering.and_then self ~other:Standard.Base.Any.Any -> Standard.Base.Any.Any
10+
- Standard.Base.Data.Ordering.Ordering.compare x:Standard.Base.Any.Any y:Standard.Base.Any.Any -> Standard.Base.Data.Ordering.Ordering!Standard.Base.Errors.Common.Incomparable_Values
1011
- Standard.Base.Data.Ordering.Ordering.from_sign sign:Standard.Base.Any.Any -> Standard.Base.Any.Any
1112
- Standard.Base.Data.Ordering.Ordering.hash x:Standard.Base.Any.Any -> Standard.Base.Any.Any
1213
- Standard.Base.Data.Ordering.Ordering.to_sign self -> Standard.Base.Any.Any
1314
- Standard.Base.Data.Ordering.Comparable.from that:Standard.Base.Any.Any -> Standard.Base.Data.Ordering.Comparable
15+
- Standard.Base.Data.Ordering.Comparable.from that:Standard.Base.Data.Ordering.Ordering -> Standard.Base.Data.Ordering.Comparable
1416
- type Ordering
1517
- Equal
1618
- Greater
1719
- Less
1820
- and_then self ~other:Standard.Base.Any.Any -> Standard.Base.Any.Any
21+
- compare x:Standard.Base.Any.Any y:Standard.Base.Any.Any -> Standard.Base.Data.Ordering.Ordering!Standard.Base.Errors.Common.Incomparable_Values
1922
- from_sign sign:Standard.Base.Any.Any -> Standard.Base.Any.Any
2023
- hash x:Standard.Base.Any.Any -> Standard.Base.Any.Any
2124
- to_sign self -> Standard.Base.Any.Any
22-
- compare x:Standard.Base.Any.Any y:Standard.Base.Any.Any -> Standard.Base.Data.Ordering.Ordering!Standard.Base.Errors.Common.Incomparable_Values
23-
- Standard.Base.Data.Ordering.Comparable.from that:Standard.Base.Data.Ordering.Ordering -> Standard.Base.Data.Ordering.Comparable

distribution/lib/Standard/Base/0.0.0-dev/docs/api/Data/Read/Return_As.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- make_return self input:Standard.Base.Data.Read.Many_Files_List.Many_Files_List objects:(Standard.Base.Data.Vector.Vector Standard.Base.Any.Any) on_problems:Standard.Base.Errors.Problem_Behavior.Problem_Behavior -> Standard.Base.Any.Any
66
- to_display_text self -> Standard.Base.Data.Text.Text
77
- to_text self -> Standard.Base.Data.Text.Text
8+
- Standard.Base.Data.Read.Return_As.Return_As.from that:Standard.Base.Data.Read.Return_As.Return_As_Base -> Standard.Base.Data.Read.Return_As.Return_As
89
- type Return_As_Base
910
- As_Vector
1011
- get_dropdown_options -> Standard.Base.Any.Any
@@ -15,4 +16,3 @@
1516
- _get_known_return_classes -> Standard.Base.Data.Vector.Vector
1617
- new typ:Standard.Base.Any.Any -> Standard.Base.Data.Read.Return_As.SPI
1718
- replace_with_nothing_and_propagate vector:(Standard.Base.Data.Vector.Vector Standard.Base.Any.Any) on_problems:Standard.Base.Errors.Problem_Behavior.Problem_Behavior -> Standard.Base.Any.Any
18-
- Standard.Base.Data.Read.Return_As.Return_As.from that:Standard.Base.Data.Read.Return_As.Return_As_Base -> Standard.Base.Data.Read.Return_As.Return_As

distribution/lib/Standard/Base/0.0.0-dev/docs/api/Enso_Cloud/Enso_Secret.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
- to_js_object self -> Standard.Base.Any.Any
2828
- to_text self -> Standard.Base.Any.Any
2929
- update_value self new_value:Standard.Base.Data.Text.Text -> Standard.Base.Any.Any
30-
- as_credential_reference secret:Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret -> Standard.Base.Enso_Cloud.Enso_Secret.CredentialReference
31-
- as_hideable_value value:(Standard.Base.Data.Text.Text|Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret|Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value) factory:Standard.Base.Any.Any= -> Standard.Base.Any.Any
3230
- secret_asset_uri secret:Standard.Base.Any.Any -> Standard.Base.Any.Any
33-
- secret_resource_uri secret:Standard.Base.Any.Any -> Standard.Base.Any.Any
3431
- Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value.from that:Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret -> Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value
3532
- type Enso_Secret_Error
3633
- Access_Denied
3734
- Not_Found resolved_path:Standard.Base.Any.Any
3835
- to_display_text self -> Standard.Base.Any.Any
36+
- as_credential_reference secret:Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret -> Standard.Base.Enso_Cloud.Enso_Secret.CredentialReference
37+
- as_hideable_value value:(Standard.Base.Data.Text.Text|Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret|Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value) factory:Standard.Base.Any.Any= -> Standard.Base.Any.Any
38+
- secret_resource_uri secret:Standard.Base.Any.Any -> Standard.Base.Any.Any
3939
- Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value.from that:Standard.Base.Data.Text.Text -> Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value

distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Ordering_Helpers.enso

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Default_Comparator
2525
---
2626
compare : Any -> Any -> (Ordering|Nothing)
2727
compare x y =
28-
case Any.== x y of
28+
case x == y of
2929
True -> Ordering.Equal
3030
False ->
3131
case Default_Comparator.less_than_builtin x y of

distribution/lib/Standard/Table/0.0.0-dev/docs/api/Fixed_Width/Fixed_Width_Format.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
- from_descriptions descs:(Standard.Base.Data.Vector.Vector Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Column_Description) -> Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout
1818
- missing_layout_argument -> Standard.Base.Any.Any
1919
- to_js_object self -> Standard.Base.Any.Any
20+
- _make_fixed_width_layout_widget display:Standard.Base.Metadata.Display= -> Standard.Base.Metadata.Widget
21+
- Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout.from that:Standard.Table.Table.Table -> Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout
22+
- Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout.from that:Standard.Table.Column.Column -> Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout
2023
- Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout.from that:Standard.Base.Data.Vector.Vector -> Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout
2124
- Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout.from that:Standard.Base.Function.Function -> Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout
2225
- type Fixed_Width_Layout_Entry
@@ -25,6 +28,3 @@
2528
- Left
2629
- Right
2730
- to_java self -> Standard.Table.Fixed_Width.Fixed_Width_Format.Justification
28-
- _make_fixed_width_layout_widget display:Standard.Base.Metadata.Display= -> Standard.Base.Metadata.Widget
29-
- Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout.from that:Standard.Table.Table.Table -> Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout
30-
- Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout.from that:Standard.Table.Column.Column -> Standard.Table.Fixed_Width.Fixed_Width_Format.Fixed_Width_Layout

docs/runtime/compiler-ir.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ enso --no-compile-dependencies --no-ir-caches --vm.D enso.compiler.RemoveUnusedI
2929

3030
## Dumping IR
3131

32+
Note that to properly dump module from standard library, **it is recommended to
33+
run with --no-ir-caches**.
34+
3235
The IR can be visualized using the `enso.compiler.dumpIr` system property. The
3336
property value has format `<module-name>[:<dump-level>]`, where `module-name` is
3437
a substring of a module to dump and `dump-level` is an optional integer which

engine/runtime-compiler-dump-igv/src/main/java/org/enso/compiler/dump/igv/EnsoModuleAST.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,11 @@ private ASTNode buildTree(Pattern pattern) {
429429
private ASTNode buildTree(CallArgument argument) {
430430
return switch (argument) {
431431
case CallArgument.Specified specifiedArg -> {
432-
Map<String, Object> props = Map.of("argName", specifiedArg.name());
433-
var node = newNode(specifiedArg, props);
432+
var node = newNode(specifiedArg);
433+
if (specifiedArg.name().isDefined()) {
434+
var nameNode = buildTree(specifiedArg.name().get());
435+
createEdge(node, nameNode, "name");
436+
}
434437
var valueNode = buildTree(specifiedArg.value());
435438
createEdge(node, valueNode, "value");
436439
yield node;

engine/runtime-compiler/src/main/java/org/enso/compiler/pass/analyse/types/TypePropagation.java

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.enso.compiler.MetadataInteropHelpers;
77
import org.enso.compiler.common.NameResolutionAlgorithm;
88
import org.enso.compiler.core.CompilerError;
9+
import org.enso.compiler.core.ConstantsNames;
910
import org.enso.compiler.core.IR;
1011
import org.enso.compiler.core.ir.CallArgument;
1112
import org.enso.compiler.core.ir.Expression;
@@ -355,8 +356,13 @@ private TypeRepresentation processSingleApplication(
355356
Application.Prefix relatedIR,
356357
LocalBindingsTyping localBindingsTyping) {
357358
if (argument.name().isDefined()) {
358-
// TODO named arguments are not yet supported
359-
return null;
359+
var isSelf = ConstantsNames.SELF_ARGUMENT.equals(argument.name().get().name());
360+
if (!isSelf) {
361+
// TODO named arguments are not yet supported
362+
return null;
363+
} else {
364+
// static invocation syntax is supported
365+
}
360366
}
361367

362368
switch (functionType) {
@@ -370,7 +376,11 @@ private TypeRepresentation processSingleApplication(
370376

371377
case TypeRepresentation.UnresolvedSymbol unresolvedSymbol -> {
372378
return processUnresolvedSymbolApplication(
373-
unresolvedSymbol, argument.value(), localBindingsTyping, relatedIR);
379+
unresolvedSymbol,
380+
argument.value(),
381+
isStaticMethodInvocation(relatedIR),
382+
localBindingsTyping,
383+
relatedIR);
374384
}
375385

376386
default -> {
@@ -399,6 +409,7 @@ private AtomTypeDefinition findTypeDefinition(QualifiedName name) {
399409
private TypeRepresentation processUnresolvedSymbolApplication(
400410
TypeRepresentation.UnresolvedSymbol function,
401411
Expression argument,
412+
boolean isStaticMethodInvocation,
402413
LocalBindingsTyping localBindingsTyping,
403414
IR relatedWholeApplicationIR) {
404415
var argumentType = tryInferringType(argument, localBindingsTyping);
@@ -421,16 +432,23 @@ private TypeRepresentation processUnresolvedSymbolApplication(
421432
}
422433
}
423434

424-
// Then we resolve the _static_ `method` on the `Type` - by looking at the eigen type.
425-
// We resolve static calls on the eigen type. It should also contain registrations of the
426-
// static variants of member methods, so we don't need to inspect member scope.
427-
var staticScope = TypeScopeReference.atomEigenType(typeObject.name());
435+
TypeScopeReference staticScope;
436+
if (isStaticMethodInvocation) {
437+
staticScope = TypeScopeReference.atomType(typeObject.name());
438+
} else {
439+
staticScope = TypeScopeReference.atomEigenType(typeObject.name());
440+
}
428441
var resolvedStaticMethod = methodTypeResolver.resolveMethod(staticScope, function.name());
429442
if (resolvedStaticMethod == null) {
430443
encounteredNoSuchMethod(
431444
relatedWholeApplicationIR, argumentType, function.name(), MethodCallKind.STATIC);
432445
}
433-
return resolvedStaticMethod;
446+
if (isStaticMethodInvocation) {
447+
var withSelf = TypeRepresentation.buildStaticMethod(typeObject, resolvedStaticMethod);
448+
return withSelf;
449+
} else {
450+
return resolvedStaticMethod;
451+
}
434452
}
435453
}
436454

@@ -493,6 +511,23 @@ private boolean isConstructorOrType(String name) {
493511
return Character.isUpperCase(firstCharacter);
494512
}
495513

514+
/**
515+
* @see <a
516+
* href="https://github.com/enso-org/enso/tree/8c14901627d4d716a67da95d210c7b60f89d30b2/docs/types/dynamic-dispatch.md#static-method-invocation">static
517+
* method invocation specification</a>
518+
*/
519+
private static boolean isStaticMethodInvocation(Application.Prefix applicationIR) {
520+
if (applicationIR.arguments().length() >= 2) {
521+
var secondArg = applicationIR.arguments().apply(1);
522+
return isNamedSelfArgument(secondArg);
523+
}
524+
return false;
525+
}
526+
527+
private static boolean isNamedSelfArgument(CallArgument arg) {
528+
return arg.name().isDefined() && arg.name().get().name().equals(ConstantsNames.SELF_ARGUMENT);
529+
}
530+
496531
private TypeRepresentation resolveConstructorOnType(
497532
TypeRepresentation.TypeObject typeObject,
498533
String constructorName,

engine/runtime-compiler/src/main/java/org/enso/compiler/pass/analyse/types/TypeRepresentation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ static TypeRepresentation buildFunction(
3939
return reversed.stream().reduce(result, (acc, arg) -> new ArrowType(arg, acc));
4040
}
4141

42+
static TypeRepresentation buildStaticMethod(
43+
TypeRepresentation.TypeObject selfType, TypeRepresentation instanceMethod) {
44+
return new ArrowType(selfType.instanceType(), instanceMethod);
45+
}
46+
4247
record TopType() implements TypeRepresentation {
4348
@Override
4449
public String toString() {

0 commit comments

Comments
 (0)