-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Constant and replace transparent parameters #4942
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
Conversation
Constant is s subtype of Singleton types that only allow constants for which the value is known at compile time.
0fbda2e
to
ca6b5e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Singleton
is already fishy and should ideally be replaced by something else (keyword, annotation, ...), I don' think we should introduce more magic types like it unless we have a very good reason and we can prove that they respect the subtyping laws. (Singleton
cannot: if A <: X
and B <: X
then we expected A | B <: X
but 1 | 2
is not a singleton).
Maybe @Blaisorblade can tell us how bad this would be :) |
Why this change? Using a type for
And if you manage to make it work, you'll have recreated a way to check programs which is syntax-directed, not type-directed.
val x: 1 & Constant = 1
x: Constant // should work but your examples suggest otherwise. EDIT: LOL, ninjaed by @smarter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned about the design, see objections in comment and by @smarter.
We talked about this also with Martin today, and we agreed to think harder about it. He agreed Singleton is problematic, but actually Constant is muddier. Singleton clearly breaks because it describes types; but Constant describes "compile-time values", and it seems to me that |
I agree. The main idea was to express constantness of a parameter of an inlined method (for macros). As singleton already covered constants I explored this design that clearly has issues. |
To be more precise |
We should first solve the issue with Singleton |
Introduce the type
Constant
which is a subtype ofSingleton
but only allows constants (e.i. known values).Use
Constant
to mark parameters oftransparent
methods that must be passed as constants or inlined constants.