Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
663e4cb
docs for method resolution
Akirathan Sep 8, 2025
00577f7
Testing/documenting the type chains for Atom, Type and Module
JaroslavTulach Sep 9, 2025
5f6fdaa
Simplify docs for method resolution
Akirathan Sep 12, 2025
948a1a9
Removing accidental changes
JaroslavTulach Sep 13, 2025
580587b
Apply suggestion from @JaroslavTulach
Akirathan Oct 1, 2025
d841f70
Added some observations to eigen types
Akirathan Oct 1, 2025
8f7d18e
Refer to polyglot readme.
Akirathan Oct 1, 2025
c6b9a3e
Add parent type and builtin type terminology
Akirathan Oct 1, 2025
9d4e613
Update docs/types/dynamic-dispatch.md
Akirathan Oct 1, 2025
7590715
Reword and simplify.
Akirathan Oct 1, 2025
497f2ab
Remove argument evaluation section
Akirathan Oct 1, 2025
41914f4
Update docs/types/dynamic-dispatch.md
Akirathan Oct 2, 2025
79ea0a5
Merge branch 'develop' into wip/akirathan/docs-methods
Akirathan Oct 2, 2025
550ef53
fmt
Akirathan Oct 2, 2025
76cdd12
typo
Akirathan Oct 2, 2025
6920f9e
Consistently ujse parameters and arguments
Akirathan Oct 2, 2025
86644aa
Update docs with the newest proposition
Akirathan Oct 2, 2025
2cd8f4d
Removing confusion by using different Text values
JaroslavTulach Oct 3, 2025
ea61947
Checking the hierarchy of Any and its eigentype
JaroslavTulach Oct 3, 2025
093156d
Type of Any.type is again Any.type
JaroslavTulach Oct 3, 2025
ed299f5
Correct terminology - use preapplied argument instead of default
Akirathan Oct 3, 2025
6a7059b
docs for singleton types
Akirathan Oct 6, 2025
f9172f5
Update test to reflect newest semantics
Akirathan Oct 6, 2025
cdd2f6e
Add tests for normal type and singleton type chains
Akirathan Oct 6, 2025
60c0c79
Update anyCHain test
Akirathan Oct 6, 2025
f7395a2
Implement correct semantics of Type.allTypes
Akirathan Oct 6, 2025
7a9e15e
Merge branch 'develop' into wip/akirathan/docs-methods
Akirathan Oct 7, 2025
14fa297
Revert Type to develop. Remove TypeChainTest.
Akirathan Oct 7, 2025
6e60a90
Revert "Revert Type to develop. Remove TypeChainTest."
Akirathan Oct 8, 2025
fbdd7ef
NO changes to Type
Akirathan Oct 8, 2025
feeb6ba
Ignore failing TypeChainTest
Akirathan Oct 8, 2025
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
134 changes: 134 additions & 0 deletions docs/types/dynamic-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,137 @@ main = Test.simplify
When invoking a method on _module object_ its _module static methods_ take
precedence over _instance methods_ defined on `Any`. Thus a module serves
primarily as a _container for module (static) methods_.

## Method Resolution

This section describes the _method resolution_ process, which resolves a
concrete method definition for a concrete call site. For a method call
expression `Receiver.symbol`, this section focuses only on a single dispatch
based on `Receiver` argument. For multiple dispatch, see the
[Multiple Dispatch](#multiple-dispatch) section.

Method resolution algorithm for `Receiver.symbol`:

1. **Determine the kind of `Receiver`:**

- 1.1. If `Receiver` is a type (type object), go to step 2.
- 1.2. If `Receiver` is a value (instance / atom), go to step 3.
- 1.3. If `Receiver` is a module, go to step 4.
- 1.4. If `Receiver` is a polyglot object, go to step 5.
- 1.5. If there is no `Receiver`, go to step 6.

2. **`Receiver` is a type. This call site is a _static method call_:**

- 2.1. We are looking for either a _static method_ or an _instance method_
defined on `Receiver` type.
- 2.2. If `symbol` is defined on `Receiver`, with or without `self` argument,
select it and stop.
- 2.3. If `symbol` is defined on `Any`, with or without `self` argument,
select it and stop.
- 2.4. Otherwise, raise `No_Such_Method` panic and stop.

3. **`Receiver` is a value (instance / atom):**

- 3.1. We are looking for an _instance method_.
- 3.2. If `symbol` is defined on `Receiver` with `self` argument, select it
and stop.
- 3.3. If `symbol` is defined on `Any` with `self` argument, select it and
stop.
- 3.4. Otherwise, raise `No_Such_Method` panic and stop.

4. **`Receiver` is a module. We are looking for a _module method_:**

- 4.1. Module methods are not allowed to be defined with `self` argument.
- 4.2. If `symbol` is defined in `Receiver` module, select it and stop.
- 4.3. Otherwise, raise `No_Such_Method` panic and stop.

5. **`Receiver` is a polyglot object. A polyglot object can be:**

- 5.1. A Java class, imported by `polyglot java import ...` statement.
- 5.2. Java object instance, created by `Java_Class.new ...` expression.
- 5.3. Javascript, Python, or any other allowed foreign language object
returned by a foreign method call.
- 5.4. Searching for `symbol` on such a `Receiver` is subject to the rules of
the [polyglot Interoperability](../polyglot/README.md) chapter.

6. **There is no `Receiver`:**
- 6.1. We are looking either for a _module method_ or for a variable in the
current scope or any parent scopes.
- 6.2. Note that in this case, `symbol` does not have to resolve to a method
definition. This is a general _symbol lookup_ rather than a _method
resolution_. See [Symbol lookup](#symbol-lookup).

### Symbol lookup

- If `symbol` is defined in the current lexical scope, select it and stop.
Copy link
Member

@JaroslavTulach JaroslavTulach Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This is not really a "dynamic dispatch"
  • but it is an interesting topic
  • and complicated - e.g. term like all transitively imported modules sounds scary
  • I'd move it to its own "lexical dispatch" document

- Iterate parent scopes: from the current lexical scope, up until this module
scope. If `symbol` is defined in the scope, select it and stop.
- Look for the `symbol` in all transitively imported modules (in DFS?). If
`symbol` is defined in any of the modules, select it and stop.
- Raise `Name_Not_Found` panic and stop.

## Method evaluation

This section describes the _method evaluation_ process. We assume that a
particular method definition was already selected by the
[method resolution](#method-resolution) process.

Let's have `method` be a method definition resolved from
[Method Resolution](#method-resolution) process, that is defined as
`method [self] [parName=[defaultValue]]* = <body expression>`.

If `self` parameter is specified, we call it an _instance method_, otherwise, we
call it a _static method_.

### Instance method call evaluation

The method call expression in the format of `obj.method [[argName=]argValue]*`,
where `obj` is an instance (value / atom) of type `T`, and `method` is an
_instance method_ with `self` argument defined either on `T` or outside `T` as
an _extension method_, the method evaluation process is as follows:

- `self` argument cannot be specified explicitly
- Go to [Arguments evaluation](#argument-evaluation) to evaluate `argValue`s and
bind them to `argName`s.

### Static method call evaluation

The method call expression in the format of
`TypeOrModule.method [[argName=]argValue]*`, where `TypeOrModule` is either a
type or a module, and `method` is a _static method_ defined on `TypeOrModule`.
Note that `TypeOrModule` does not have to be specified, if `method` is directly
imported.

The method evaluation process is as follows:

1. **Determine whether `TypeOrModule` is a type or a module:**

- 1.1. If `TypeOrModule` is not `Any`, go to 2
- 1.2. If `TypeOrModule` is `Any`, go to 4

2. **`TypeOrModule` is not `Any`:**

- 2.1. If `self` argument is specified explicitly, go to 3. `self` argument
value is either:
- Passed via `self` named argument.
- First positional argument.
- 2.2. If `self` argument is not specified explicitly, go to 4.

3. **`self` is specified explicitly:**

- 3.1. `self` argument is specified explicitly.
- 3.2. Bind `self` argument to the provided value.
- 3.3. Go to [Arguments evaluation](#argument-evaluation) to evaluate rest of
the arguments.

4. **`self` is not specified explicitly:**

- 4.1. `self` argument is not specified explicitly. This can happen only if
there are no arguments. Which results in a method reference.

5. **`TypeOrModule` is `Any`:**
- 5.1. TODO ...

### Argument evaluation

TODO