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

Fully Qualified Names are not allowed in type signatures #8997

Open
radeusgd opened this issue Feb 7, 2024 · 5 comments · May be fixed by #12263
Open

Fully Qualified Names are not allowed in type signatures #8997

radeusgd opened this issue Feb 7, 2024 · 5 comments · May be fixed by #12263
Assignees
Labels
--bug Type: bug -compiler -type-system Category: type system and type inference

Comments

@radeusgd
Copy link
Member

radeusgd commented Feb 7, 2024

Repro:

from Standard.Base import all

foo : Standard.Base.Data.Numbers.Integer
foo = 1

bar (x : Standard.Base.Data.Numbers.Integer) = 10+x

main =
    bar foo

This seems like a completely valid program, but it fails to compile with:

X:\NBO\repr\test3.enso:3:7: error: The name `Standard.Base.Data.Numbers.Integer` could not be found.
    3 | foo : Standard.Base.Data.Numbers.Integer
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X:\NBO\repr\test3.enso:6:10: error: The name `Standard.Base.Data.Numbers.Integer` could not be found.
    6 | bar (x : Standard.Base.Data.Numbers.Integer) = 10+x
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Aborting due to 2 errors and 0 warnings.
Execution finished with an error: Compilation aborted due to errors.

If I replace the FQNs with just Integer it runs all fine.

I don't see any reason why FQNs should not be allowed in type signatures. In fact it is rather confusing.

Note that the exact same FQN used as value works all fine:

from Standard.Base import all

main =
    IO.println Standard.Base.Data.Numbers.Integer
    IO.println (42.is_a Standard.Base.Data.Numbers.Integer)

printing

Integer
True
@Akirathan
Copy link
Member

Akirathan commented Feb 12, 2025

Note that the exact same FQN used as value works all fine:

The reason it works in that case is that the fully-qualified name in the snippet

main =
    IO.println Standard.Base.Data.Numbers.Integer
    IO.println (42.is_a Standard.Base.Data.Numbers.Integer)

is resolved at runtime. Whereas the fully-qualified names in type signatures are resolved during compilation. More specifically, in the TypeNames compiler pass. I was able to pinpoint the exact failure in resolution in BindingsMap. See #12263 (comment)

@JaroslavTulach
Copy link
Member

Enso always wanted to support dependent types...

is resolved at runtime. Whereas the fully-qualified names in type signatures are resolved during compilation.

... to simplify: there is no difference between value and type treatment. Why not resolve the FQN at runtime as well?

@radeusgd
Copy link
Member Author

Enso always wanted to support dependent types...

is resolved at runtime. Whereas the fully-qualified names in type signatures are resolved during compilation.

... to simplify: there is no difference between value and type treatment. Why not resolve the FQN at runtime as well?

Because where possible we still want to do static analysis, no?

If I can resolve something at compile time, I can report an error to the user and find typos much faster. Deferring to runtime may even cause such errors to be completely unnoticed if a relevant test does not cover enough execution paths.

@Akirathan
Copy link
Member

Why not resolve the FQN at runtime as well?

In addition to what @radeusgd already mentioned, all the necessary information is already present in BindingsMap at compilation time, we are just not using it in this case.

@JaroslavTulach
Copy link
Member

Because where possible we still want to do static analysis, no?

I am not 100% sure and I don't think I ever claimed that or agreed to that.

If I can resolve something at compile time,

It may slow down the start...

Deferring to runtime

...may speed startup significantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
--bug Type: bug -compiler -type-system Category: type system and type inference
Projects
Status: ⚙️ Design
Development

Successfully merging a pull request may close this issue.

3 participants